]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - managemon.c
Make sure resync_start is initialised properly and maintained properly
[thirdparty/mdadm.git] / managemon.c
index 191721829707d7673c79ec20b4c9419568e24bbd..447d8ea0001f19e51cbf7e6291b71783aff42a5f 100644 (file)
@@ -159,6 +159,7 @@ static void remove_old(void)
                if (pending_discard == discard_this)
                        pending_discard = NULL;
                discard_this = NULL;
+               wakeup_monitor();
        }
 }
 
@@ -174,7 +175,6 @@ static void replace_array(struct supertype *container,
         */
        remove_old();
        while (pending_discard) {
-               wakeup_monitor();
                while (discard_this == NULL)
                        sleep(1);
                remove_old();
@@ -289,7 +289,7 @@ static void manage_member(struct mdstat_ent *mdstat,
                         * and open files for each newdev */
                        for (d = newdev; d ; d = d->next) {
                                struct mdinfo *newd;
-                               if (sysfs_add_disk(&newa->info, d))
+                               if (sysfs_add_disk(&newa->info, d) < 0)
                                        continue;
                                newd = newa->info.devs;
                                newd->state_fd = sysfs_open(a->devnum,
@@ -336,7 +336,7 @@ static void manage_new(struct mdstat_ent *mdstat,
        inst = &mdstat->metadata_version[10+strlen(container->devname)+1];
 
        mdi = sysfs_read(-1, new->devnum,
-                        GET_LEVEL|GET_CHUNK|GET_DISKS|
+                        GET_LEVEL|GET_CHUNK|GET_DISKS|GET_COMPONENT|
                         GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE);
        if (!mdi) {
                /* Eeek. Cannot monitor this array.
@@ -348,6 +348,7 @@ static void manage_new(struct mdstat_ent *mdstat,
        }
 
        new->info.array = mdi->array;
+       new->info.component_size = mdi->component_size;
 
        for (i = 0; i < new->info.array.raid_disks; i++) {
                struct mdinfo *newd = malloc(sizeof(*newd));
@@ -378,7 +379,7 @@ static void manage_new(struct mdstat_ent *mdstat,
        new->action_fd = sysfs_open(new->devnum, NULL, "sync_action");
        new->info.state_fd = sysfs_open(new->devnum, NULL, "array_state");
        new->resync_start_fd = sysfs_open(new->devnum, NULL, "resync_start");
-       new->resync_start = 0;
+       get_resync_start(new);
        dprintf("%s: inst: %d action: %d state: %d\n", __func__, atoi(inst),
                new->action_fd, new->info.state_fd);
 
@@ -428,9 +429,25 @@ void manage(struct mdstat_ent *mdstat, struct supertype *container)
        }
 }
 
-static int handle_message(struct supertype *container, struct metadata_update *msg)
+static void handle_message(struct supertype *container, struct metadata_update *msg)
 {
-       return -1;
+       /* queue this metadata update through to the monitor */
+
+       struct metadata_update *mu;
+
+       if (msg->len == 0) {
+               wait_update_handled();
+       } else {
+               mu = malloc(sizeof(*mu));
+               mu->len = msg->len;
+               mu->buf = msg->buf;
+               msg->buf = NULL;
+               mu->space = NULL;
+               mu->next = NULL;
+               if (container->ss->prepare_update)
+                       container->ss->prepare_update(container, mu);
+               queue_metadata_update(mu);
+       }
 }
 
 void read_sock(struct supertype *container)
@@ -460,8 +477,6 @@ void read_sock(struct supertype *container)
                } else
                        terminate = 1;
 
-               if (msg.buf)
-                       free(msg.buf);
        } while (!terminate);
 
        close(fd);