]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdmon: remove devices from container
authorDan Williams <dan.j.williams@intel.com>
Tue, 19 Aug 2008 04:55:12 +0000 (14:55 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 19 Aug 2008 04:55:12 +0000 (14:55 +1000)
Once the monitor thread has kicked a drive from all managed arrays mdadm
-r is permitted.  We are guaranteed that the drive is marked failed at
this point, so allow the drive to be re-added as a spare.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
managemon.c
mdmon.c

index b211d8f446b17d6e2f5111c206bd0b8f51073dde..d2925ae482061ea63f5523c5d0659c32f9da2bda 100644 (file)
@@ -228,12 +228,35 @@ static void manage_container(struct mdstat_ent *mdstat,
         * about spare assignment.... probably not.
         */
        if (mdstat->devcnt != container->devcnt) {
+               struct mdinfo **cdp, *cd, *di, *mdi;
+               int found;
+
                /* read /sys/block/NAME/md/dev-??/block/dev to find out
                 * what is there, and compare with container->info.devs
                 * To see what is removed and what is added.
                 * These need to be remove from, or added to, the array
                 */
-               // FIXME
+               mdi = sysfs_read(-1, mdstat->devnum, GET_DEVS);
+               if (!mdi)
+                       return;
+
+               /* check for removals */
+               for (cdp = &container->devs; *cdp; ) {
+                       found = 0;
+                       for (di = mdi->devs; di; di = di->next)
+                               if (di->disk.major == (*cdp)->disk.major &&
+                                   di->disk.minor == (*cdp)->disk.minor) {
+                                       found = 1;
+                                       break;
+                               }
+                       if (!found) {
+                               cd = *cdp;
+                               *cdp = (*cdp)->next;
+                               free(cd);
+                       } else
+                               cdp = &(*cdp)->next;
+               }
+               sysfs_free(mdi);
                container->devcnt = mdstat->devcnt;
        }
 }
diff --git a/mdmon.c b/mdmon.c
index 85f44bc27f0355000e6c1be614e7c4ba30bdf2bc..9485757a3d6d2de68f33752840d51b638ce36c1d 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -292,7 +292,7 @@ int main(int argc, char *argv[])
        container->devs = NULL;
        for (di = mdi->devs; di; di = di->next) {
                struct mdinfo *cd = malloc(sizeof(*cd));
-               cd = di;
+               *cd = *di;
                cd->next = container->devs;
                container->devs = cd;
        }