]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdmon: fix removed disk handling
authorDan Williams <dan.j.williams@intel.com>
Wed, 25 Feb 2009 01:45:57 +0000 (18:45 -0700)
committerDan Williams <dan.j.williams@intel.com>
Wed, 25 Feb 2009 01:45:57 +0000 (18:45 -0700)
Use SKIP_GONE_DEVS when reading the container, and correct some confused
logic in manage_new().

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

index c9b054ff4a0605953a28792a463e959a067c24f1..c48c8517f443b62af3ecad1985dca8f8542e111d 100644 (file)
@@ -283,7 +283,7 @@ static void manage_container(struct mdstat_ent *mdstat,
                 * To see what is removed and what is added.
                 * These need to be remove from, or added to, the array
                 */
-               mdi = sysfs_read(-1, mdstat->devnum, GET_DEVS);
+               mdi = sysfs_read(-1, mdstat->devnum, GET_DEVS|SKIP_GONE_DEVS);
                if (!mdi) {
                        /* invalidate the current count so we can try again */
                        container->devcnt = -1;
@@ -460,7 +460,7 @@ static void manage_new(struct mdstat_ent *mdstat,
                        if (i == di->disk.raid_disk)
                                break;
 
-               if (di) {
+               if (di && newd) {
                        memcpy(newd, di, sizeof(*newd));
 
                        newd->state_fd = sysfs_open(new->devnum,
@@ -469,13 +469,16 @@ static void manage_new(struct mdstat_ent *mdstat,
 
                        newd->prev_state = read_dev_state(newd->state_fd);
                        newd->curr_state = newd->prev_state;
-               } else if (failed + 1 > new->info.array.failed_disks) {
-                       /* we cannot properly monitor without all working disks */
-                       new->container = NULL;
-                       break;
                } else {
+                       if (newd)
+                               free(newd);
+
                        failed++;
-                       free(newd);
+                       if (failed > new->info.array.failed_disks) {
+                               /* we cannot properly monitor without all working disks */
+                               new->container = NULL;
+                               break;
+                       }
                        continue;
                }
                sprintf(newd->sys_name, "rd%d", i);
diff --git a/mdmon.c b/mdmon.c
index acb36a2d6f2621ad9ec26daf95522bbe04b3c4aa..7dc9120bbc5e21e46164c01535aa7c8f09587545 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -400,7 +400,7 @@ int mdmon(char *devname, int devnum, int scan, char *switchroot)
        }
 
        mdi = sysfs_read(mdfd, container->devnum,
-                        GET_VERSION|GET_LEVEL|GET_DEVS);
+                        GET_VERSION|GET_LEVEL|GET_DEVS|SKIP_GONE_DEVS);
 
        if (!mdi) {
                fprintf(stderr, "mdmon: failed to load sysfs info for %s\n",