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 <neilb@suse.de>
This commit is contained in:
NeilBrown 2013-08-01 11:16:14 +10:00
parent d81cc6a72e
commit 84d11e6c6a
2 changed files with 15 additions and 2 deletions

15
Grow.c
View File

@ -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;

View 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