]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Support nameing of version-1 arrays.
authorNeil Brown <neilb@suse.de>
Tue, 9 Aug 2005 05:23:20 +0000 (05:23 +0000)
committerNeil Brown <neilb@suse.de>
Tue, 9 Aug 2005 05:23:20 +0000 (05:23 +0000)
--name is recognised in --create and --assemble
name= is recognised in config file.

Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
17 files changed:
Assemble.c
ChangeLog
Create.c
Detail.c
Examine.c
Kill.c
Query.c
ReadMe.c
config.c
mdadm.8
mdadm.c
mdadm.conf.5
mdadm.h
super0.c
super1.c
tests/06name [new file with mode: 0644]
util.c

index 739db51203f316f5164e85d83b4ff819a1f3b033..449073f1cbbf4cb120df7976bd0a7d028f85accf 100644 (file)
@@ -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<bestcnt; i++) {
                int j = best[i];
                unsigned int desired_state;
index 56bf07d7712b4ed71cb1689a1a5e2ecfe6446a7b..7d985c9eb1127ef04b71787a57b22576e20cb988 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@ Changes Prior to this release
     -   Support assembling from byte-swapped superblocks
        metadata type "0.swap" and --update=byteorder
     -   write-mostly and write-behind support for raid1.
+    -   Support --name= and 'name=' config entry for identifying
+       arrays be name.
 
 Changes Prior to 2.0-devel-3 release
     -   Assorted fixes for multiple bugs...
index 87a9a2e71c3c2ffd27eb02936bcc152d4b099b2b..0d7be8f0831cb6de0b9d2595503db011d6b08515 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -33,6 +33,7 @@
 
 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)
@@ -343,7 +344,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
        array.chunk_size = chunk*1024;
 
 
-       if (!st->ss->init_super(st, &super, &array))
+       if (!st->ss->init_super(st, &super, &array, name))
                return 1;
 
        if (bitmap_file && strcmp(bitmap_file, "internal")==0) {
index 4c93eff95f51b3d7bddbdfda716172aa493d0812..41b28a56d9593ad89a73375f6e3984ca9666546e 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -112,7 +112,8 @@ int Detail(char *dev, int brief, int test)
                                if (fd2 >=0 && st &&
                                    st->ss->load_super(st, fd2, &super, NULL) == 0) {
                                        struct mdinfo info;
-                                       st->ss->getinfo_super(&info, super);
+                                       struct mddev_ident_s ident;
+                                       st->ss->getinfo_super(&info, &ident, super);
                                        if (info.array.ctime != array.ctime ||
                                            info.array.level != array.level) {
                                                free(super);
index 8f15a759875dab1e8f504617840098b7d303f231..a5151ec0a6d73eb8855f1d2d6f00f818974e4368 100644 (file)
--- a/Examine.c
+++ b/Examine.c
@@ -62,6 +62,7 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct su
                void *super;
                struct supertype *st;
                struct mdinfo info;
+               struct mddev_ident_s ident;
                void *devs;
                struct array *next;
                int spares;
@@ -108,9 +109,9 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct su
                                ap->spares = 0;
                                ap->st = st;
                                arrays = ap;
-                               st->ss->getinfo_super(&ap->info, super);
+                               st->ss->getinfo_super(&ap->info, &ap->ident, super);
                        } else {
-                               st->ss->getinfo_super(&ap->info, super);
+                               st->ss->getinfo_super(&ap->info, &ap->ident, super);
                                free(super);
                        }
                        if (!(ap->info.disk.state & MD_DISK_SYNC))
diff --git a/Kill.c b/Kill.c
index 709306abacbac01394caf1931e869a48b4225cec..9f05e8bcfcbfa6851e038c052fb187714a64e2d1 100644 (file)
--- a/Kill.c
+++ b/Kill.c
@@ -63,7 +63,7 @@ int Kill(char *dev, int force)
                mdu_array_info_t info;
                info.major_version = -1; /* zero superblock */
                free(super);
-               st->ss->init_super(st, &super, &info);
+               st->ss->init_super(st, &super, &info, "");
                if (st->ss->store_super(st, fd, super)) {
                        fprintf(stderr, Name ": Could not zero superblock on %s\n",
                                dev);
diff --git a/Query.c b/Query.c
index d2bfb0524672cacab8ed31add6ca5480afbb376a..a76c69204e98f3c65274486dfc06d4622112599a 100644 (file)
--- a/Query.c
+++ b/Query.c
@@ -42,6 +42,7 @@ int Query(char *dev)
        int ioctlerr;
        int superror, superrno;
        struct mdinfo info;
+       struct mddev_ident_s ident;
        mdu_array_info_t array;
        void *super;
        struct supertype *st = NULL;
@@ -104,7 +105,7 @@ int Query(char *dev)
        close(fd);
        if (superror == 0) {
                /* array might be active... */
-               st->ss->getinfo_super(&info, super);
+               st->ss->getinfo_super(&info, &ident, super);
                if (st->ss->major == 0) {
                        mddev = get_md_name(info.array.md_minor);
                        disc.number = info.disk.number;
index 1ba7301b956fb3e1bf762869f4e47131e7fe38f6..91fe279116b00f72a996b96df1d50c673f270156 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -137,6 +137,7 @@ struct option long_options[] = {
     /* For assemble */
     {"uuid",      1, 0, 'u'},
     {"super-minor",1,0, 'm'},
+    {"name",     1, 0, 'N'},
     {"config",    1, 0, 'c'},
     {"scan",      0, 0, 's'},
     {"force",    0, 0, 'f'},
@@ -236,6 +237,7 @@ char OptionHelp[] =
 "  --bitmap-chunk=    : chunksize of bitmap in bitmap file (Kilobytes)\n"
 "  --delay=      -d   : seconds between bitmap updates\n"
 "  --write-behind=    : number of simultaneous write-behind requests to allow (requires bitmap)\n"
+"  --name=       -N   : Textual name for array - max 32 characters\n"
 "\n"
 " For assemble:\n"
 "  --bitmap=     -b   : File to find bitmap information in\n"
@@ -243,6 +245,7 @@ char OptionHelp[] =
 "                       have this uuid are excluded\n"
 "  --super-minor= -m  : minor number to look for in super-block when\n"
 "                       choosing devices to use.\n"
+"  --name=       -N   : Array name to look for in super-block.\n"
 "  --config=     -c   : config file\n"
 "  --scan        -s   : scan config file for missing information\n"
 "  --force       -f   : Assemble the array even if some superblocks appear out-of-date\n"
@@ -307,6 +310,7 @@ char Help_create[] =
 "  --run         -R   : insist of running the array even if not all\n"
 "                     : devices are present or some look odd.\n"
 "  --readonly    -o   : start the array readonly - not supported yet.\n"
+"  --name=       -N   : Textual name for array - max 32 characters\n"
 "  --bitmap-chunk=    : bitmap chunksize in Kilobytes.\n"
 "  --delay=      -d   : bitmap update delay in seconds.\n"
 "\n"
@@ -371,6 +375,7 @@ char Help_assemble[] =
 "                       have this uuid are excluded\n"
 "  --super-minor= -m  : minor number to look for in super-block when\n"
 "                       choosing devices to use.\n"
+"  --name=       -N   : Array name to look for in super-block.\n"
 "  --config=     -c   : config file\n"
 "  --scan        -s   : scan config file for missing information\n"
 "  --run         -R   : Try to start the array even if not enough devices\n"
index 40f33ac59afd90d79e9abbf15ab1e2dbdeab1dca..a5d5edd2a61691d1f7a2bfa1d593cb8fbb649710 100644 (file)
--- a/config.c
+++ b/config.c
@@ -277,6 +277,7 @@ void arrayline(char *line)
        mis.next = NULL;
        mis.st = NULL;
        mis.bitmap_fd = -1;
+       mis.name[0] = 0;
 
        for (w=dl_next(line); w!=line; w=dl_next(w)) {
                if (w[0] == '/') {
@@ -307,6 +308,15 @@ void arrayline(char *line)
                                        mis.super_minor = UnSet;
                                }
                        }
+               } else if (strncasecmp(w, "name=", 5)==0) {
+                       if (mis.name[0])
+                               fprintf(stderr, Name ": only specify name once, %s ignored.\n",
+                                       w);
+                       else if (strlen(w+5) > 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 48d6c53a01dc22ad341c4ebfe6f49ee0de3daa2e..75fcbeb9653c2759ed8aed5c2a7b3e96cb0c3c5c 100644 (file)
--- 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 4dd6524515a816d3dccfa3bc9c8d9bd7af7cc458..de1f95a93f1c403b77b0902ba43b995d8feafb8e 100644 (file)
--- 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;
index 97390102ec28b1b4c6a9c7ee85f1cc5fe65033bf..e5b3ebfe2c86ff9b10511727d9fa315db7975a64 100644 (file)
@@ -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 8b58afc067dfc4ee30541582edef224ac3e0301f..0457d9ddde7cf175b6237095ba4ca8635ea1c664 100644 (file)
--- 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);
index e33643905624033cbd93d1d7ca753ae1f1974414..f355fa731ab02a09a59f7e9e3c2467ccf560c609 100644 (file)
--- 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<<MD_DISK_SYNC)) &&
@@ -365,7 +366,7 @@ static __u64 event_super0(void *sbv)
 
 
 
-static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info)
+static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info, char *ignored_name)
 {
        mdp_super_t *sb = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
        int spares;
index f59eff06d6566473426e4e7b55805023d89c394f..e25d005759db79b0a63f5cec1bea68158ca95cd4 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -230,6 +230,8 @@ static void brief_examine_super1(void *sbv)
                printf("%02x", sb->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 (file)
index 0000000..80842ab
--- /dev/null
@@ -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 7621340bc2b24d6f34abfc1758e930b4a1361f4f..b4c1d5ee1372501f5d7967249587e5079218d15c 100644 (file)
--- 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;