]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Grow: exit background thread cleanly on SIGTERM.
authorNeilBrown <neilb@suse.de>
Thu, 1 Aug 2013 01:16:14 +0000 (11:16 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 1 Aug 2013 03:58:10 +0000 (13:58 +1000)
If the mdadm thread that monitors a reshape gets SIGTERM it should
exit cleanly and clear the 'suspended' region of the array.
However it mustn't clear 'sync_max' as that would allow the
reshape to continue unmonitored.

If the thread ever does get killed, the array should really be
shutdown soon after if possible.

Signed-off-by: NeilBrown <neilb@suse.de>
Grow.c
super-intel.c

diff --git a/Grow.c b/Grow.c
index ff4ed5dd9a95b752c2b0c040a3427c85e80f45d5..ce80c523f715cfdf6768957d7730b7a4d04ca16e 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -25,6 +25,7 @@
 #include       "dlink.h"
 #include       <sys/mman.h>
 #include       <stdint.h>
+#include       <signal.h>
 
 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
 #error no endian defined
@@ -729,7 +730,8 @@ void abort_reshape(struct mdinfo *sra)
        sysfs_set_num(sra, NULL, "suspend_hi", 0);
        sysfs_set_num(sra, NULL, "suspend_lo", 0);
        sysfs_set_num(sra, NULL, "sync_min", 0);
-       sysfs_set_str(sra, NULL, "sync_max", "max");
+       // It isn't safe to reset sync_max as we aren't monitoring.
+       // Array really should be stopped at this point.
 }
 
 int remove_disks_for_takeover(struct supertype *st,
@@ -2726,6 +2728,12 @@ static int impose_level(int fd, int level, char *devname, int verbose)
        return 0;
 }
 
+int sigterm = 0;
+static void catch_term(int sig)
+{
+       sigterm = 1;
+}
+
 static int reshape_array(char *container, int fd, char *devname,
                         struct supertype *st, struct mdinfo *info,
                         int force, struct mddev_dev *devlist,
@@ -3260,6 +3268,8 @@ started:
                fd = -1;
        mlockall(MCL_FUTURE);
 
+       signal(SIGTERM, catch_term);
+
        if (st->ss->external) {
                /* metadata handler takes it from here */
                done = st->ss->manage_reshape(
@@ -4243,7 +4253,8 @@ int child_monitor(int afd, struct mdinfo *sra, struct reshape *reshape,
                                forget_backup(dests, destfd,
                                              destoffsets, 1);
                }
-
+               if (sigterm)
+                       rv = -2;
                if (rv < 0) {
                        if (rv == -1)
                                done = 1;
index 4df33f4222319789293169aa7bbada5adf899492..7b24068664938162864c6f1677c41d291e53714f 100644 (file)
@@ -10444,6 +10444,8 @@ static int imsm_manage_reshape(
                        dprintf("wait_for_reshape_imsm returned error!\n");
                        goto abort;
                }
+               if (sigterm)
+                       goto abort;
 
                if (save_checkpoint_imsm(st, sra, UNIT_SRC_NORMAL) == 1) {
                        /* ignore error == 2, this can mean end of reshape here