]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - managemon.c
imsm: validate multiple ppls during assemble
[thirdparty/mdadm.git] / managemon.c
index ec4586b2f5fffbc39fe4d473e3f8b6da324a4331..cc3c6f103ba902bcb5739450d93a292031e7ba3d 100644 (file)
@@ -115,6 +115,8 @@ static void close_aa(struct active_array *aa)
        for (d = aa->info.devs; d; d = d->next) {
                close(d->recovery_fd);
                close(d->state_fd);
+               close(d->bb_fd);
+               close(d->ubb_fd);
        }
 
        if (aa->action_fd >= 0)
@@ -410,7 +412,9 @@ static int sysfs_open2(char *devnum, char *name, char *attr)
                 * never needs too.
                 */
                char buf[200];
-               read(fd, buf, sizeof(buf));
+               if (read(fd, buf, sizeof(buf)) < 0)
+                       /* pretend not to ignore return value */
+                       return fd;
        }
        return fd;
 }
@@ -431,6 +435,21 @@ static int disk_init_and_add(struct mdinfo *disk, struct mdinfo *clone,
                close(disk->recovery_fd);
                return -1;
        }
+       disk->bb_fd = sysfs_open2(aa->info.sys_name, disk->sys_name,
+                                "bad_blocks");
+       if (disk->bb_fd < 0) {
+               close(disk->recovery_fd);
+               close(disk->state_fd);
+               return -1;
+       }
+       disk->ubb_fd = sysfs_open2(aa->info.sys_name, disk->sys_name,
+                                 "unacknowledged_bad_blocks");
+       if (disk->ubb_fd < 0) {
+               close(disk->recovery_fd);
+               close(disk->state_fd);
+               close(disk->bb_fd);
+               return -1;
+       }
        disk->prev_state = read_dev_state(disk->state_fd);
        disk->curr_state = disk->prev_state;
        disk->next = aa->info.devs;
@@ -458,7 +477,7 @@ static void manage_member(struct mdstat_ent *mdstat,
        char buf[64];
        int frozen;
        struct supertype *container = a->container;
-       unsigned long long int component_size = 0;
+       struct mdinfo *mdi;
 
        if (container == NULL)
                /* Raced with something */
@@ -470,8 +489,13 @@ static void manage_member(struct mdstat_ent *mdstat,
                // MORE
        }
 
-       if (sysfs_get_ll(&a->info, NULL, "component_size", &component_size) >= 0)
-               a->info.component_size = component_size << 1;
+       mdi = sysfs_read(-1, mdstat->devnm,
+                        GET_COMPONENT|GET_CONSISTENCY_POLICY);
+       if (mdi) {
+               a->info.component_size = mdi->component_size;
+               a->info.consistency_policy = mdi->consistency_policy;
+               sysfs_free(mdi);
+       }
 
        /* honor 'frozen' */
        if (sysfs_get_str(&a->info, NULL, "metadata_version", buf, sizeof(buf)) > 0)
@@ -480,9 +504,9 @@ static void manage_member(struct mdstat_ent *mdstat,
                frozen = 1; /* can't read metadata_version assume the worst */
 
        /* If sync_action is not 'idle' then don't try recovery now */
-       if (!frozen
-           && sysfs_get_str(&a->info, NULL, "sync_action", buf, sizeof(buf)) > 0
-           && strncmp(buf, "idle", 4) != 0)
+       if (!frozen &&
+           sysfs_get_str(&a->info, NULL, "sync_action",
+                         buf, sizeof(buf)) > 0 && strncmp(buf, "idle", 4) != 0)
                frozen = 1;
 
        if (mdstat->level) {
@@ -561,8 +585,8 @@ static void manage_member(struct mdstat_ent *mdstat,
                        usleep(15*1000);
                }
                replace_array(container, a, newa);
-               if (sysfs_set_str(&a->info, NULL, "sync_action", "recover")
-                   == 0)
+               if (sysfs_set_str(&a->info, NULL,
+                                 "sync_action", "recover") == 0)
                        newa->prev_action = recover;
                dprintf("recovery started on %s\n", a->info.sys_name);
  out:
@@ -607,8 +631,8 @@ static void manage_member(struct mdstat_ent *mdstat,
                        newd = xmalloc(sizeof(*newd));
                        disk_init_and_add(newd, d, newa);
                }
-               if (sysfs_get_ll(info, NULL, "array_size", &array_size) == 0
-                   && a->info.custom_array_size > array_size*2) {
+               if (sysfs_get_ll(info, NULL, "array_size", &array_size) == 0 &&
+                   a->info.custom_array_size > array_size*2) {
                        sysfs_set_num(info, NULL, "array_size",
                                      a->info.custom_array_size/2);
                }
@@ -666,8 +690,8 @@ static void manage_new(struct mdstat_ent *mdstat,
 
        mdi = sysfs_read(-1, mdstat->devnm,
                         GET_LEVEL|GET_CHUNK|GET_DISKS|GET_COMPONENT|
-                        GET_DEGRADED|GET_SAFEMODE|
-                        GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE|GET_LAYOUT);
+                        GET_SAFEMODE|GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE|
+                        GET_LAYOUT);
 
        if (!mdi)
                return;