From aa534678baad80689a642ba1bd602a00a267ac03 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 22 Jun 2010 16:30:59 -0700 Subject: Rename subarray v2 Allow the name of the array stored in the metadata to be updated. In some cases the metadata format may not be able to support this rename without modifying the UUID. In these cases the request will be blocked. Otherwise we allow the rename to take place, even for active arrays. This assumes that the user understands the difference between the kernel node name, the device node symlink name, and the metadata specific name. Anticipating further need to modify subarrays in-place, introduce the ->update_subarray() superswitch method. A future potential use case is setting storage pool (spare-group) identifiers. Signed-off-by: Dan Williams --- mdadm.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'mdadm.c') diff --git a/mdadm.c b/mdadm.c index 446fab82..e7435fd9 100644 --- a/mdadm.c +++ b/mdadm.c @@ -218,8 +218,14 @@ int main(int argc, char *argv[]) case Waitclean: case DetailPlatform: case KillSubarray: - if (opt == KillSubarray) + case UpdateSubarray: + if (opt == KillSubarray || opt == UpdateSubarray) { + if (subarray) { + fprintf(stderr, Name ": subarray can only be specified once\n"); + exit(2); + } subarray = optarg; + } case 'K': if (!mode) newmode = MISC; break; } if (mode && newmode == mode) { @@ -593,11 +599,16 @@ int main(int argc, char *argv[]) case O(CREATE,'N'): case O(ASSEMBLE,'N'): + case O(MISC,'N'): if (ident.name[0]) { fprintf(stderr, Name ": name cannot be set twice. " "Second value %s.\n", optarg); exit(2); } + if (mode == MISC && !subarray) { + fprintf(stderr, Name ": -N/--name only valid with --update-subarray in misc mode\n"); + exit(2); + } if (strlen(optarg) > 32) { fprintf(stderr, Name ": name '%s' is too long, 32 chars max.\n", optarg); @@ -624,11 +635,16 @@ int main(int argc, char *argv[]) continue; case O(ASSEMBLE,'U'): /* update the superblock */ + case O(MISC,'U'): if (update) { fprintf(stderr, Name ": Can only update one aspect of superblock, both %s and %s given.\n", update, optarg); exit(2); } + if (mode == MISC && !subarray) { + fprintf(stderr, Name ": Only subarrays can be updated in misc mode\n"); + exit(2); + } update = optarg; if (strcmp(update, "sparc2.2")==0) continue; @@ -812,10 +828,20 @@ int main(int argc, char *argv[]) case O(MISC, Waitclean): case O(MISC, DetailPlatform): case O(MISC, KillSubarray): + case O(MISC, UpdateSubarray): if (devmode && devmode != opt && (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) { - fprintf(stderr, Name ": --examine/-E cannot be given with -%c\n", - devmode =='E'?opt:devmode); + fprintf(stderr, Name ": --examine/-E cannot be given with "); + if (devmode == 'E') { + if (option_index >= 0) + fprintf(stderr, "--%s\n", + long_options[option_index].name); + else + fprintf(stderr, "-%c\n", opt); + } else if (isalpha(devmode)) + fprintf(stderr, "-%c\n", devmode); + else + fprintf(stderr, "previous option\n"); exit(2); } devmode = opt; @@ -1411,6 +1437,15 @@ int main(int argc, char *argv[]) case KillSubarray: rv |= Kill_subarray(dv->devname, subarray, quiet); continue; + case UpdateSubarray: + if (update == NULL) { + fprintf(stderr, + Name ": -U/--update must be specified with --update-subarray\n"); + rv |= 1; + continue; + } + rv |= Update_subarray(dv->devname, subarray, update, &ident, quiet); + continue; } mdfd = open_mddev(dv->devname, 1); if (mdfd>=0) { -- cgit v1.2.3