]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - monitor.c
Improve partition table code.
[thirdparty/mdadm.git] / monitor.c
index 3388d31c5c57aaab6d60fde1ef04e7dd940743eb..e43e545ce196f1370ad68b78c9b02dac67ae89f9 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -1,8 +1,8 @@
 /*
  * mdmon - monitor external metadata arrays
  *
- * Copyright (C) 2007-2008 Neil Brown <neilb@suse.de>
- * Copyright (C) 2007-2008 Intel Corporation
+ * Copyright (C) 2007-2009 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2007-2009 Intel Corporation
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -66,23 +66,20 @@ static int read_attr(char *buf, int len, int fd)
        return n;
 }
 
-int get_resync_start(struct active_array *a)
+static unsigned long long read_resync_start(int fd)
 {
        char buf[30];
        int n;
 
-       n = read_attr(buf, 30, a->resync_start_fd);
+       n = read_attr(buf, 30, fd);
        if (n <= 0)
-               return n;
+               return 0;
        if (strncmp(buf, "none", 4) == 0)
-               a->resync_start = ~0ULL;
+               return MaxSector;
        else
-               a->resync_start = strtoull(buf, NULL, 10);
-
-       return 1;
+               return strtoull(buf, NULL, 10);
 }
 
-
 static enum array_state read_state(int fd)
 {
        char buf[20];
@@ -208,22 +205,23 @@ static int read_and_act(struct active_array *a)
 
        a->curr_state = read_state(a->info.state_fd);
        a->curr_action = read_action(a->action_fd);
+       a->info.resync_start = read_resync_start(a->resync_start_fd);
        for (mdi = a->info.devs; mdi ; mdi = mdi->next) {
                mdi->next_state = 0;
-               if (mdi->state_fd >= 0)
+               if (mdi->state_fd >= 0) {
+                       mdi->recovery_start = read_resync_start(mdi->recovery_fd);
                        mdi->curr_state = read_dev_state(mdi->state_fd);
+               }
        }
 
        if (a->curr_state <= inactive &&
            a->prev_state > inactive) {
                /* array has been stopped */
-               get_resync_start(a);
                a->container->ss->set_array_state(a, 1);
                a->next_state = clear;
                deactivate = 1;
        }
        if (a->curr_state == write_pending) {
-               get_resync_start(a);
                a->container->ss->set_array_state(a, 0);
                a->next_state = active;
                dirty = 1;
@@ -236,7 +234,6 @@ static int read_and_act(struct active_array *a)
                dirty = 1;
        }
        if (a->curr_state == clean) {
-               get_resync_start(a);
                a->container->ss->set_array_state(a, 1);
        }
        if (a->curr_state == active ||
@@ -253,7 +250,6 @@ static int read_and_act(struct active_array *a)
                        /* explicit request for readonly array.  Leave it alone */
                        ;
                } else {
-                       get_resync_start(a);
                        if (a->container->ss->set_array_state(a, 2))
                                a->next_state = read_auto; /* array is clean */
                        else {
@@ -271,7 +267,6 @@ static int read_and_act(struct active_array *a)
                 * until the array goes inactive or readonly though.
                 * Just check if we need to fiddle spares.
                 */
-               get_resync_start(a);
                a->container->ss->set_array_state(a, a->curr_state <= clean);
                check_degraded = 1;
        }
@@ -486,7 +481,11 @@ static int wait_and_act(struct supertype *container, int nowait)
                                dprintf("caught sigterm, all clean... exiting\n");
                        else
                                dprintf("no arrays to monitor... exiting\n");
-                       remove_pidfile(container->devname);
+                       if (!sigterm)
+                               /* On SIGTERM, someone (the take-over mdmon) will
+                                * clean up
+                                */
+                               remove_pidfile(container->devname);
                        exit_now = 1;
                        signal_manager();
                        exit(0);
@@ -498,7 +497,7 @@ static int wait_and_act(struct supertype *container, int nowait)
                sigprocmask(SIG_UNBLOCK, NULL, &set);
                sigdelset(&set, SIGUSR1);
                monitor_loop_cnt |= 1;
-               rv = pselect(maxfd+1, &rfds, NULL, NULL, NULL, &set);
+               rv = pselect(maxfd+1, NULL, NULL, &rfds, NULL, &set);
                monitor_loop_cnt += 1;
                if (rv == -1 && errno == EINTR)
                        rv = 0;