From: NeilBrown Date: Thu, 1 Aug 2013 01:16:14 +0000 (+1000) Subject: Grow: exit background thread cleanly on SIGTERM. X-Git-Tag: mdadm-3.3~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84d11e6c6a3b827b2daa32e16303235ce33d49f5;p=thirdparty%2Fmdadm.git Grow: exit background thread cleanly on SIGTERM. 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 --- diff --git a/Grow.c b/Grow.c index ff4ed5dd..ce80c523 100644 --- a/Grow.c +++ b/Grow.c @@ -25,6 +25,7 @@ #include "dlink.h" #include #include +#include #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; diff --git a/super-intel.c b/super-intel.c index 4df33f42..7b240686 100644 --- a/super-intel.c +++ b/super-intel.c @@ -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