]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - managemon.c
Detail: fix handling of 'disks' array.
[thirdparty/mdadm.git] / managemon.c
index 6cd93e5165bcb24a09d8bf850d14f76c2fdf5c77..9b14d1ec3d6a60c68507ef860e6e91f43c7f5d8e 100644 (file)
@@ -289,7 +289,7 @@ static void add_disk_to_container(struct supertype *st, struct mdinfo *sd)
         */
        st2 = dup_super(st);
        if (st2->ss->load_super(st2, dfd, NULL) == 0) {
-               st2->ss->getinfo_super(st, &info, NULL);
+               st2->ss->getinfo_super(st2, &info, NULL);
                if (st->ss->compare_super(st, st2) == 0 &&
                    info.disk.raid_disk >= 0) {
                        /* Looks like a good member of array.
@@ -402,6 +402,20 @@ static void manage_container(struct mdstat_ent *mdstat,
        }
 }
 
+static int sysfs_open2(char *devnum, char *name, char *attr)
+{
+       int fd = sysfs_open(devnum, name, attr);
+       if (fd >= 0) {
+               /* seq_file in the kernel allocates buffer space
+                * on the first read.  Do that now so 'monitor'
+                * never needs too.
+                */
+               char buf[200];
+               read(fd, buf, sizeof(buf));
+       }
+       return fd;
+}
+
 static int disk_init_and_add(struct mdinfo *disk, struct mdinfo *clone,
                             struct active_array *aa)
 {
@@ -409,10 +423,11 @@ static int disk_init_and_add(struct mdinfo *disk, struct mdinfo *clone,
                return -1;
 
        *disk = *clone;
-       disk->recovery_fd = sysfs_open(aa->info.sys_name, disk->sys_name, "recovery_start");
+       disk->recovery_fd = sysfs_open2(aa->info.sys_name, disk->sys_name,
+                                       "recovery_start");
        if (disk->recovery_fd < 0)
                return -1;
-       disk->state_fd = sysfs_open(aa->info.sys_name, disk->sys_name, "state");
+       disk->state_fd = sysfs_open2(aa->info.sys_name, disk->sys_name, "state");
        if (disk->state_fd < 0) {
                close(disk->recovery_fd);
                return -1;
@@ -450,9 +465,11 @@ static void manage_member(struct mdstat_ent *mdstat,
                /* Raced with something */
                return;
 
-       // FIXME
-       a->info.array.raid_disks = mdstat->raid_disks;
-       // MORE
+       if (mdstat->active) {
+               // FIXME
+               a->info.array.raid_disks = mdstat->raid_disks;
+               // MORE
+       }
 
        if (sysfs_get_ll(&a->info, NULL, "component_size", &component_size) >= 0)
                a->info.component_size = component_size << 1;
@@ -492,7 +509,7 @@ static void manage_member(struct mdstat_ent *mdstat,
        if (a->container == NULL)
                return;
 
-       if (sigterm && a->info.safe_mode_delay > 1) {
+       if (sigterm && a->info.safe_mode_delay != 1) {
                sysfs_set_safemode(&a->info, 1);
                a->info.safe_mode_delay = 1;
        }
@@ -652,7 +669,7 @@ 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_DEVS|GET_OFFSET|GET_SIZE|GET_STATE|GET_LAYOUT);
 
        if (!mdi)
                return;
@@ -690,12 +707,13 @@ static void manage_new(struct mdstat_ent *mdstat,
                }
        }
 
-       new->action_fd = sysfs_open(new->info.sys_name, NULL, "sync_action");
-       new->info.state_fd = sysfs_open(new->info.sys_name, NULL, "array_state");
-       new->resync_start_fd = sysfs_open(new->info.sys_name, NULL, "resync_start");
-       new->metadata_fd = sysfs_open(new->info.sys_name, NULL, "metadata_version");
-       new->sync_completed_fd = sysfs_open(new->info.sys_name, NULL, "sync_completed");
-       dprintf("%s: inst: %d action: %d state: %d\n", __func__, atoi(inst),
+       new->action_fd = sysfs_open2(new->info.sys_name, NULL, "sync_action");
+       new->info.state_fd = sysfs_open2(new->info.sys_name, NULL, "array_state");
+       new->resync_start_fd = sysfs_open2(new->info.sys_name, NULL, "resync_start");
+       new->metadata_fd = sysfs_open2(new->info.sys_name, NULL, "metadata_version");
+       new->sync_completed_fd = sysfs_open2(new->info.sys_name, NULL, "sync_completed");
+
+       dprintf("%s: inst: %s action: %d state: %d\n", __func__, inst,
                new->action_fd, new->info.state_fd);
 
        if (sigterm)
@@ -817,7 +835,8 @@ static void handle_message(struct supertype *container, struct metadata_update *
                mu->space_list = NULL;
                mu->next = NULL;
                if (container->ss->prepare_update)
-                       container->ss->prepare_update(container, mu);
+                       if (!container->ss->prepare_update(container, mu))
+                               free_updates(&mu);
                queue_metadata_update(mu);
        }
 }