]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Allow autoassembly to choose it's own name for the array.
authorNeil Brown <neilb@suse.de>
Tue, 23 May 2006 06:46:40 +0000 (06:46 +0000)
committerNeil Brown <neilb@suse.de>
Tue, 23 May 2006 06:46:40 +0000 (06:46 +0000)
This cannot be used yet, but it is working towards auto-assembly.

When auto-assembling an array, we make a name in /dev/md/
giving a number (from the peferred minor) or name (from set-name).

Signed-off-by: Neil Brown <neilb@suse.de>
Assemble.c
super0.c

index 4516b62cc4d7f10a51f6cecea8f5ae3c48aa2384..46ec9bc0bb96e6d24e4d3811d16c3f8db34d95a9 100644 (file)
@@ -139,27 +139,29 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
        struct mdinfo info;
        char *avail;
        int nextspare = 0;
-       
-       vers = md_get_version(mdfd);
-       if (vers <= 0) {
-               fprintf(stderr, Name ": %s appears not to be an md device.\n", mddev);
-               return 1;
-       }
-       if (vers < 9000) {
-               fprintf(stderr, Name ": Assemble requires driver version 0.90.0 or later.\n"
-                       "    Upgrade your kernel or try --build\n");
-               return 1;
-       }
+
        if (get_linux_version() < 2004000)
                old_linux = 1;
 
-       if (ioctl(mdfd, GET_ARRAY_INFO, &info.array)>=0) {
-               fprintf(stderr, Name ": device %s already active - cannot assemble it\n",
-                       mddev);
-               return 1;
-       }
-       ioctl(mdfd, STOP_ARRAY, NULL); /* just incase it was started but has no content */
+       if (mdfd >= 0) {
+               vers = md_get_version(mdfd);
+               if (vers <= 0) {
+                       fprintf(stderr, Name ": %s appears not to be an md device.\n", mddev);
+                       return 1;
+               }
+               if (vers < 9000) {
+                       fprintf(stderr, Name ": Assemble requires driver version 0.90.0 or later.\n"
+                               "    Upgrade your kernel or try --build\n");
+                       return 1;
+               }
 
+               if (ioctl(mdfd, GET_ARRAY_INFO, &info.array)>=0) {
+                       fprintf(stderr, Name ": device %s already active - cannot assemble it\n",
+                               mddev);
+                       return 1;
+               }
+               ioctl(mdfd, STOP_ARRAY, NULL); /* just incase it was started but has no content */
+       }
        /*
         * If any subdevs are listed, then any that don't
         * match ident are discarded.  Remainder must all match and
@@ -173,7 +175,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
            ident->super_minor < 0 &&
            ident->devices == NULL) {
                fprintf(stderr, Name ": No identity information available for %s - cannot assemble.\n",
-                       mddev);
+                       mddev ? mddev : "further assembly");
                return 1;
        }
        if (devlist == NULL)
@@ -191,7 +193,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
 
        if (verbose>0)
            fprintf(stderr, Name ": looking for devices for %s\n",
-                   mddev);
+                   mddev ? mddev : "further assembly");
 
        /* first walk the list of devices to find a consistent set
         * that match the criterea, if that is possible.
@@ -332,6 +334,17 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                tmpdev->used = 1;
        }
 
+       if (mdfd < 0) {
+               /* So... it is up to me to open the device.
+                * We create a name '/dev/md/XXX' based on the info in the
+                * superblock, and call open_mddev on that
+                */
+               asprintf(&mddev, "/dev/md/%s", info.name);
+               mdfd = open_mddev(mddev, 0);
+               if (mdfd < 0)
+                       return mdfd;
+       }
+
        /* Ok, no bad inconsistancy, we can try updating etc */
        for (tmpdev = devlist; tmpdev; tmpdev=tmpdev->next) if (tmpdev->used) {
                char *devname = tmpdev->devname;
index cc2f7a95a000c37bf1c0ab9646fcf0ca499835fe..7025445583e7b313409ade9fee8c6b2e1929ac7c 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -334,7 +334,7 @@ static void getinfo_super0(struct mdinfo *info, void *sbv)
        } else
                info->reshape_active = 0;
 
-       info->name[0] = 0;
+       sprintf(info->name, "%d", sb->md_minor);
        /* 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)) &&