]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - monitor.c
Make sure resync_start is initialised properly and maintained properly
[thirdparty/mdadm.git] / monitor.c
index fda3fc01049f2504340d66b55f76a9f35550694b..314889657aaae88629241ab4ae69d80b4832284a 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -48,7 +48,7 @@ static int read_attr(char *buf, int len, int fd)
 }
 
 
-static int get_resync_start(struct active_array *a)
+int get_resync_start(struct active_array *a)
 {
        char buf[30];
        int n;
@@ -251,7 +251,8 @@ static int read_and_act(struct active_array *a)
                }
        }
 
-       if (a->curr_action == idle &&
+       if (!deactivate &&
+           a->curr_action == idle &&
            a->prev_action == resync) {
                /* A resync has finished.  The endpoint is recorded in
                 * 'sync_start'.  We don't update the metadata
@@ -263,14 +264,19 @@ static int read_and_act(struct active_array *a)
                check_degraded = 1;
        }
 
-       if (a->curr_action == idle &&
+       if (!deactivate &&
+           a->curr_action == idle &&
            a->prev_action == recover) {
+               /* A recovery has finished.  Some disks may be in sync now,
+                * and the array may no longer be degraded
+                */
                for (mdi = a->info.devs ; mdi ; mdi = mdi->next) {
                        a->container->ss->set_disk(a, mdi->disk.raid_disk,
                                                   mdi->curr_state);
                        if (! (mdi->curr_state & DS_INSYNC))
                                check_degraded = 1;
                }
+               a->container->ss->set_array_state(a, 0);
        }
 
        for (mdi = a->info.devs ; mdi ; mdi = mdi->next) {
@@ -445,9 +451,9 @@ static int wait_and_act(struct supertype *container, int nowait)
                if (fd >= 0 || errno != EBUSY) {
                        /* OK, we are safe to leave */
                        dprintf("no arrays to monitor... exiting\n");
+                       remove_pidfile(container->devname);
                        exit_now = 1;
                        signal_manager();
-                       remove_pidfile(container->devname);
                        exit(0);
                }
        }