From: Neil Brown Date: Tue, 9 Aug 2005 05:23:20 +0000 (+0000) Subject: Support nameing of version-1 arrays. X-Git-Tag: mdadm-2.0~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=947fd4ddb554fd2c3d81c190dfe63407f8771eb8;p=thirdparty%2Fmdadm.git Support nameing of version-1 arrays. --name is recognised in --create and --assemble name= is recognised in config file. Signed-off-by: Neil Brown --- diff --git a/Assemble.c b/Assemble.c index 739db512..449073f1 100644 --- a/Assemble.c +++ b/Assemble.c @@ -116,6 +116,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd, unsigned int num_devs; mddev_dev_t tmpdev; struct mdinfo info; + struct mddev_ident_s ident2; vers = md_get_version(mdfd); if (vers <= 0) { @@ -214,7 +215,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd, devname); close(dfd); } else { - tst->ss->getinfo_super(&info, super); + tst->ss->getinfo_super(&info, &ident2, super); close(dfd); } @@ -225,6 +226,13 @@ int Assemble(struct supertype *st, char *mddev, int mdfd, devname); continue; } + if (ident->name[0] && + (!super || strncmp(ident2.name, ident->name, 32)!=0)) { + if (inargv || verbose) + fprintf(stderr, Name ": %s has wrong name.\n", + devname); + continue; + } if (ident->super_minor != UnSet && (!super || ident->super_minor != info.array.md_minor)) { if (inargv || verbose) @@ -344,7 +352,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd, return 1; } - st->ss->getinfo_super(&info, first_super); + st->ss->getinfo_super(&info, &ident2, first_super); /* now we have some devices that might be suitable. * I wonder how many @@ -461,7 +469,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd, fprintf(stderr, Name ": No suitable drives found for %s\n", mddev); return 1; } - st->ss->getinfo_super(&info, super); + st->ss->getinfo_super(&info, &ident2, super); for (i=0; i 32) + fprintf(stderr, Name ": name too long, ignoring %s\n", w); + else + strcpy(mis.name, w+5); + } else if (strncasecmp(w, "devices=", 8 ) == 0 ) { if (mis.devices) fprintf(stderr, Name ": only specify devices once (use a comma separated list). %s ignored\n", @@ -375,7 +385,7 @@ void arrayline(char *line) } if (mis.devname == NULL) fprintf(stderr, Name ": ARRAY line with no device\n"); - else if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet) + else if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0) fprintf(stderr, Name ": ARRAY line %s has no identity information.\n", mis.devname); else { mi = malloc(sizeof(*mi)); diff --git a/mdadm.8 b/mdadm.8 index 48d6c53a..75fcbeb9 100644 --- a/mdadm.8 +++ b/mdadm.8 @@ -431,6 +431,14 @@ that the array pre-existed and is known to be clean. This is only really useful for Building RAID1 array. Only use this if you really know what you are doing. This is currently only supported for --build. +.TP +.BR -N ", " --name= +Set a +.B name +for the array. This is currently only effective when creating an +array with a version-1 superblock. The name is a simple textual +string that can be used to identify array components when assembling. + .TP .BR -R ", " --run Insist that @@ -517,6 +525,11 @@ e.g. when assembling .M --super-minor=dev will look for super blocks with a minor number of 0. +.TP +.BR -N ", " --name= +Specify the name of the array to assemble. This must be the name +that was specified when creating the array. + .TP .BR -f ", " --force Assemble the array even if some superblocks appear out-of-date diff --git a/mdadm.c b/mdadm.c index 4dd65245..de1f95a9 100644 --- a/mdadm.c +++ b/mdadm.c @@ -107,6 +107,7 @@ int main(int argc, char *argv[]) ident.autof = 0; ident.st = NULL; ident.bitmap_fd = -1; + ident.name[0] = 0; while ((option_index = -1) , (opt=getopt_long(argc, argv, @@ -526,6 +527,21 @@ int main(int argc, char *argv[]) } continue; + case O(CREATE,'N'): + case O(ASSEMBLE,'N'): + if (ident.name[0]) { + fprintf(stderr, Name ": name cannot be set twice. " + "Second value %s.\n", optarg); + exit(2); + } + if (strlen(optarg) > 32) { + fprintf(stderr, Name ": name '%s' is too long, 32 chars max.\n", + optarg); + exit(2); + } + strcpy(ident.name, optarg); + continue; + case O(ASSEMBLE,'m'): /* super-minor for array */ if (ident.super_minor != UnSet) { fprintf(stderr, Name ": super-minor cannot be set twice. " @@ -852,7 +868,7 @@ int main(int argc, char *argv[]) break; case ASSEMBLE: if (devs_found == 1 && ident.uuid_set == 0 && - ident.super_minor == UnSet && !scan ) { + ident.super_minor == UnSet && ident.name[0] == 0 && !scan ) { /* Only a device has been given, so get details from config file */ mddev_ident_t array_ident = conf_get_ident(configfile, devlist->devname); if (array_ident == NULL) { @@ -972,7 +988,7 @@ int main(int argc, char *argv[]) } rv = Create(ss, devlist->devname, mdfd, chunk, level, layout, size<0 ? 0 : size, - raiddisks, sparedisks, + raiddisks, sparedisks, ident.name, devs_found-1, devlist->next, runstop, verbose, force, bitmap_file, bitmap_chunk, write_behind, delay); break; diff --git a/mdadm.conf.5 b/mdadm.conf.5 index 97390102..e5b3ebfe 100644 --- a/mdadm.conf.5 +++ b/mdadm.conf.5 @@ -90,6 +90,13 @@ The value should be a 128 bit uuid in hexadecimal, with punctuation interspersed if desired. This must match the uuid stored in the superblock. .TP +.B name= +The value should be a simple textual name as was given to +.I mdadm +when the array was created. This must match the name stored in the +superblock on a device for that device to be included in the array. +Not all superblock-formats support names. +.TP .B super-minor= The value is an integer which indicates the minor number that was stored in the superblock when the array was created. When an array is diff --git a/mdadm.h b/mdadm.h index 8b58afc0..0457d9dd 100644 --- a/mdadm.h +++ b/mdadm.h @@ -112,6 +112,7 @@ typedef struct mddev_ident_s { int uuid_set; int uuid[4]; + char name[33]; unsigned int super_minor; @@ -177,10 +178,10 @@ extern struct superswitch { void (*detail_super)(void *sbv); void (*brief_detail_super)(void *sbv); void (*uuid_from_super)(int uuid[4], void *sbv); - void (*getinfo_super)(struct mdinfo *info, void *sbv); + void (*getinfo_super)(struct mdinfo *info, mddev_ident_t ident, void *sbv); int (*update_super)(struct mdinfo *info, void *sbv, char *update, char *devname, int verbose); __u64 (*event_super)(void *sbv); - int (*init_super)(struct supertype *st, void **sbp, mdu_array_info_t *info); + int (*init_super)(struct supertype *st, void **sbp, mdu_array_info_t *info, char *name); void (*add_to_super)(void *sbv, mdu_disk_info_t *dinfo); int (*store_super)(struct supertype *st, int fd, void *sbv); int (*write_init_super)(struct supertype *st, void *sbv, mdu_disk_info_t *dinfo, char *devname); @@ -244,6 +245,7 @@ extern int Build(char *mddev, int mdfd, int chunk, int level, int layout, extern int Create(struct supertype *st, char *mddev, int mdfd, int chunk, int level, int layout, unsigned long size, int raiddisks, int sparedisks, + char *name, int subdevs, mddev_dev_t devlist, int runstop, int verbose, int force, char *bitmap_file, int bitmap_chunk, int write_behind, int delay); diff --git a/super0.c b/super0.c index e3364390..f355fa73 100644 --- a/super0.c +++ b/super0.c @@ -223,7 +223,7 @@ static void uuid_from_super0(int uuid[4], void * sbv) } } -static void getinfo_super0(struct mdinfo *info, void *sbv) +static void getinfo_super0(struct mdinfo *info, mddev_ident_t ident, void *sbv) { mdp_super_t *sb = sbv; int working = 0; @@ -246,7 +246,8 @@ static void getinfo_super0(struct mdinfo *info, void *sbv) info->events = md_event(sb); uuid_from_super0(info->uuid, sbv); - + + ident->name[0] = 0; /* work_disks is calculated rather than read directly */ for (i=0; i < MD_SB_DISKS; i++) if ((sb->disks[i].state & (1<set_uuid[i]); if ((i&3)==0 && i != 0) printf(":"); } + if (sb->set_name[0]) + printf(" name=%.32s", sb->set_name); printf("\n"); } @@ -238,6 +240,7 @@ static void detail_super1(void *sbv) struct mdp_superblock_1 *sb = sbv; int i; + printf(" Name : %.32s\n", sb->set_name); printf(" UUID : "); for (i=0; i<16; i++) { printf("%02x", sb->set_uuid[i]); @@ -251,6 +254,8 @@ static void brief_detail_super1(void *sbv) struct mdp_superblock_1 *sb = sbv; int i; + if (sb->set_name[0]) + printf(" name=%.32s", sb->set_name); printf(" UUID="); for (i=0; i<16; i++) { printf("%02x", sb->set_uuid[i]); @@ -269,7 +274,7 @@ static void uuid_from_super1(int uuid[4], void * sbv) cuuid[i] = super->set_uuid[i]; } -static void getinfo_super1(struct mdinfo *info, void *sbv) +static void getinfo_super1(struct mdinfo *info, mddev_ident_t ident, void *sbv) { struct mdp_superblock_1 *sb = sbv; int working = 0; @@ -309,6 +314,9 @@ static void getinfo_super1(struct mdinfo *info, void *sbv) memcpy(info->uuid, sb->set_uuid, 16); + strncpy(ident->name, sb->set_name, 32); + ident->name[32] = 0; + for (i=0; i< __le32_to_cpu(sb->max_dev); i++) { role = __le16_to_cpu(sb->dev_roles[i]); if (/*role == 0xFFFF || */role < info->array.raid_disks) @@ -375,7 +383,7 @@ static __u64 event_super1(void *sbv) return __le64_to_cpu(sb->events); } -static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info) +static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info, char *name) { struct mdp_superblock_1 *sb = malloc(1024); int spares; @@ -402,7 +410,8 @@ static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info) *(__u32*)(sb->set_uuid+8) = random(); *(__u32*)(sb->set_uuid+12) = random(); - /* FIXME name */ + memset(sb->set_name, 0, 32); + strcpy(sb->set_name, name); sb->ctime = __cpu_to_le64((unsigned long long)time(0)); sb->level = __cpu_to_le32(info->level); diff --git a/tests/06name b/tests/06name new file mode 100644 index 00000000..80842abf --- /dev/null +++ b/tests/06name @@ -0,0 +1,13 @@ +set -x + +# create an array with a name + +$mdadm -CR $md0 -l0 -n2 --metadata=1 --name="Fred" $dev0 $dev1 +$mdadm -E $dev0 | grep 'Name : Fred$' > /dev/null || exit 1 +$mdadm -D $md0 | grep 'Name : Fred$' > /dev/null || exit 1 +$mdadm -S $md0 + +$mdadm -A $md0 --name="Fred" $devlist +$mdadm -Db $md0 +$mdadm -S $md0 + diff --git a/util.c b/util.c index 7621340b..b4c1d5ee 100644 --- a/util.c +++ b/util.c @@ -227,6 +227,7 @@ int check_raid(int fd, char *name) { void *super; struct mdinfo info; + struct mddev_ident_s ident; time_t crtime; struct supertype *st = guess_super(fd); @@ -235,7 +236,7 @@ int check_raid(int fd, char *name) /* Looks like a raid array .. */ fprintf(stderr, Name ": %s appears to be part of a raid array:\n", name); - st->ss->getinfo_super(&info, super); + st->ss->getinfo_super(&info, &ident, super); free(super); crtime = info.array.ctime; fprintf(stderr, " level=%d devices=%d ctime=%s", @@ -607,7 +608,8 @@ struct supertype *guess_super(int fd) rv = ss->load_super(st, fd, &sbp, NULL); if (rv == 0) { struct mdinfo info; - ss->getinfo_super(&info, sbp); + struct mddev_ident_s ident; + ss->getinfo_super(&info, &ident, sbp); if (bestsuper == -1 || besttime < info.array.ctime) { bestsuper = i;