]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
allow --incremental to reuse devices that already exist
authorNeil Brown <neilb@suse.de>
Mon, 26 May 2008 23:18:43 +0000 (09:18 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 26 May 2008 23:18:43 +0000 (09:18 +1000)
.. and other fixes.

Incremental.c
super-ddf.c

index 2c03a1464773f17e5ede0b09a012ec8a7f57dd1e..18cdf3fae6f6de6012f541beed6b134937db5e0d 100644 (file)
@@ -237,6 +237,7 @@ int Incremental(char *devname, int verbose, int runstop,
                /* Have to guess a bit. */
                int use_partitions = 1;
                char *np, *ep;
+               char *nm, nbuf[1024];
                if ((autof&7) == 3 || (autof&7) == 5)
                        use_partitions = 0;
                np = strchr(info.name, ':');
@@ -252,6 +253,24 @@ int Incremental(char *devname, int verbose, int runstop,
                } else
                        devnum = -1;
 
+               if (match)
+                       nm = match->devname;
+               else {
+                       sprintf(nbuf, "/dev/md/%s", np);
+                       nm = nbuf;
+               }
+               if (stat(nm, &stb) == 0 &&
+                   S_ISBLK(stb.st_mode) &&
+                   major(stb.st_rdev) == (use_partitions ?
+                                          get_mdp_major() : MD_MAJOR)) {
+                       if (use_partitions)
+                               devnum = minor(stb.st_rdev) >> MdpMinorShift;
+                       else
+                               devnum = minor(stb.st_rdev);
+                       if (mddev_busy(use_partitions ? (-1-devnum) : devnum))
+                               devnum = -1;
+               }
+
                if (devnum < 0) {
                        /* Haven't found anything yet, choose something free */
                        devnum = find_free_devnum(use_partitions);
@@ -774,6 +793,28 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
                                devnum = -1;
                }
 
+               if (devnum < 0) {
+                       char *nm = ra->name;
+                       char nbuf[1024];
+                       struct stat stb;
+                       if (strchr(nm, ':'))
+                               nm = strchr(nm, ':')+1;
+                       sprintf(nbuf, "/dev/md/%s", nm);
+
+                       if (stat(nbuf, &stb) == 0 &&
+                           S_ISBLK(stb.st_mode) &&
+                           major(stb.st_rdev) == (usepart ?
+                                                  get_mdp_major() : MD_MAJOR)){
+                               if (usepart)
+                                       devnum = minor(stb.st_rdev)
+                                               >> MdpMinorShift;
+                               else
+                                       devnum = minor(stb.st_rdev);
+                               if (mddev_busy(usepart ? (-1-devnum) : devnum))
+                                       devnum = -1;
+                       }
+               }
+
                if (devnum >= 0)
                        devnum = usepart ? (-1-devnum) : devnum;
                else
index 285563b4cb051aaab751557f9934c07abce83499..f0cb1f1fe83dc4dbdac61b84956b4ea5c4ad635d 100644 (file)
@@ -2670,7 +2670,6 @@ struct superswitch super_ddf = {
 
 /* for mdmon */
        .open_new       = ddf_open_new,
-       .load_super     = load_super_ddf,
        .mark_clean     = ddf_mark_clean,
        .set_disk       = ddf_set_disk,
        .sync_metadata  = ddf_sync_metadata,
@@ -2687,8 +2686,10 @@ struct superswitch super_ddf_container = {
        .write_init_super = write_init_super_ddf,
 #endif
 
+       .load_super     = load_super_ddf,
        .init_super     = init_super_ddf,
        .add_to_super   = add_to_super_ddf,
+       .getinfo_super  = getinfo_super_ddf,
 
        .free_super     = free_super_ddf,