]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdmon: allow degraded arrays to be monitored
authorDan Williams <dan.j.williams@intel.com>
Fri, 15 Aug 2008 17:58:43 +0000 (10:58 -0700)
committerDan Williams <dan.j.williams@intel.com>
Fri, 15 Aug 2008 17:58:43 +0000 (10:58 -0700)
manage_new is too strict in the face of failed devices.  Teach it to
monitor degraded arrays.

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

index 7a1c06336a179fe6e3eeacaf534157a6ff56a263..0a251de72fe7d1ed30d540df7a67b1f69eeb6295 100644 (file)
@@ -341,6 +341,7 @@ static void manage_new(struct mdstat_ent *mdstat,
        struct mdinfo *mdi, *di;
        char *inst;
        int i;
+       int failed = 0;
 
        /* check if array is ready to be monitored */
        if (!mdstat->active)
@@ -348,7 +349,7 @@ static void manage_new(struct mdstat_ent *mdstat,
 
        mdi = sysfs_read(-1, mdstat->devnum,
                         GET_LEVEL|GET_CHUNK|GET_DISKS|GET_COMPONENT|
-                        GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE);
+                        GET_DEGRADED|GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE);
 
        new = malloc(sizeof(*new));
 
@@ -390,10 +391,14 @@ static void manage_new(struct mdstat_ent *mdstat,
 
                        newd->prev_state = read_dev_state(newd->state_fd);
                        newd->curr_state = newd->prev_state;
-               } else {
-                       /* we cannot properly monitor without all raid_disks */
+               } else if (failed + 1 > new->info.array.failed_disks) {
+                       /* we cannot properly monitor without all working disks */
                        new->container = NULL;
                        break;
+               } else {
+                       failed++;
+                       free(newd);
+                       continue;
                }
                sprintf(newd->sys_name, "rd%d", i);
                newd->next = new->info.devs;
diff --git a/mdadm.h b/mdadm.h
index 52d94352e8ff2a3211686fcc996b5f1220e3e14e..12eef2a2be10ef72419407695610639f8bd819ad 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -324,6 +324,7 @@ extern void map_add(struct map_ent **melp,
 #define        GET_MISMATCH    32
 #define        GET_VERSION     64
 #define        GET_DISKS       128
+#define        GET_DEGRADED    256
 
 #define        GET_DEVS        1024 /* gets role, major, minor */
 #define        GET_OFFSET      2048
diff --git a/sysfs.c b/sysfs.c
index 0ea17eb9d00b0020192930bae809eab6ad830c15..7ca40c3ada149df49ce873caf9fdb074f837105e 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -153,6 +153,12 @@ struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options)
                        goto abort;
                sra->array.raid_disks = strtoul(buf, NULL, 0);
        }
+       if (options & GET_DEGRADED) {
+               strcpy(base, "degraded");
+               if (load_sys(fname, buf))
+                       goto abort;
+               sra->array.failed_disks = strtoul(buf, NULL, 0);
+       }
        if (options & GET_COMPONENT) {
                strcpy(base, "component_size");
                if (load_sys(fname, buf))