]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - managemon.c
Discard get_sync_pos. We should be using get_resync_start.
[thirdparty/mdadm.git] / managemon.c
index c5ba2f4c40a7b4d88069f889a1723e9018212fae..91755f92db7b3068f913634254aa42d61d4d7547 100644 (file)
@@ -75,6 +75,7 @@
 #include       "mdadm.h"
 #include       "mdmon.h"
 #include       <sys/socket.h>
+#include       <signal.h>
 
 static void close_aa(struct active_array *aa)
 {
@@ -86,7 +87,6 @@ static void close_aa(struct active_array *aa)
        close(aa->action_fd);
        close(aa->info.state_fd);
        close(aa->resync_start_fd);
-       close(aa->sync_pos_fd);
 }
 
 static void free_aa(struct active_array *aa)
@@ -116,6 +116,17 @@ static void write_wakeup(struct supertype *c)
        read(c->mon_pipe[0], &err, 1);
 }
 
+static void remove_old(void)
+{
+       if (discard_this) {
+               discard_this->next = NULL;
+               free_aa(discard_this);
+               if (pending_discard == discard_this)
+                       pending_discard = NULL;
+               discard_this = NULL;
+       }
+}
+
 static void replace_array(struct supertype *container,
                          struct active_array *old,
                          struct active_array *new)
@@ -126,16 +137,12 @@ static void replace_array(struct supertype *container,
         * and put it on 'discard_this'.  We take it from there
         * and discard it.
         */
-
+       remove_old();
        while (pending_discard) {
+               write_wakeup(container);
                while (discard_this == NULL)
                        sleep(1);
-               if (discard_this != pending_discard)
-                       abort();
-               discard_this->next = NULL;
-               free_aa(discard_this);
-               discard_this = NULL;
-               pending_discard = NULL;
+               remove_old();
        }
        pending_discard = old;
        new->replaces = old;
@@ -144,7 +151,6 @@ static void replace_array(struct supertype *container,
        write_wakeup(container);
 }
 
-
 static void manage_container(struct mdstat_ent *mdstat,
                             struct supertype *container)
 {
@@ -203,6 +209,8 @@ static void manage_new(struct mdstat_ent *mdstat,
 
        new = malloc(sizeof(*new));
 
+       memset(new, 0, sizeof(*new));
+
        new->devnum = mdstat->devnum;
 
        new->prev_state = new->curr_state = new->next_state = inactive;
@@ -256,8 +264,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->sync_pos_fd = sysfs_open(new->devnum, NULL, "sync_completed");
-       new->sync_pos = 0;
+       new->resync_start = 0;
 
        sysfs_free(mdi);
        // finds and compares.
@@ -271,8 +278,7 @@ static void manage_new(struct mdstat_ent *mdstat,
        return;
 }
 
-void manage(struct mdstat_ent *mdstat, struct active_array *aa,
-           struct supertype *container)
+void manage(struct mdstat_ent *mdstat, struct supertype *container)
 {
        /* We have just read mdstat and need to compare it with
         * the known active arrays.
@@ -294,7 +300,7 @@ void manage(struct mdstat_ent *mdstat, struct active_array *aa,
                        /* Not for this array */
                        continue;
                /* Looks like a member of this container */
-               for (a = aa; a; a = a->next) {
+               for (a = container->arrays; a; a = a->next) {
                        if (mdstat->devnum == a->devnum) {
                                if (a->container)
                                        manage_member(mdstat, a);
@@ -367,19 +373,45 @@ void read_sock(struct supertype *container)
 
        close(fd);
 }
+
+static int woke = 0;
+void wake_me(int sig)
+{
+       woke = 1;
+}
+
+int exit_now = 0;
+int manager_ready = 0;
 void do_manager(struct supertype *container)
 {
        struct mdstat_ent *mdstat;
+       sigset_t block, orig;
+
+       sigemptyset(&block);
+       sigaddset(&block, SIGUSR1);
+
+       signal(SIGUSR1, wake_me);
 
        do {
+               woke = 0;
+
+               if (exit_now)
+                       exit(0);
+
                mdstat = mdstat_read(1, 0);
 
-               manage(mdstat, array_list, container);
+               manage(mdstat, container);
 
                read_sock(container);
 
                free_mdstat(mdstat);
 
-               mdstat_wait_fd(container->sock);
+               remove_old();
+
+               manager_ready = 1;
+               sigprocmask(SIG_SETMASK, &block, &orig);
+               if (woke == 0)
+                       mdstat_wait_fd(container->sock, &orig);
+               sigprocmask(SIG_SETMASK, &orig, NULL);
        } while(1);
 }