dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/mdadm-3.2.6-Grow-exit-background-thread-cleanly-on-SIGTERM.patch

fc6001
From 84d11e6c6a3b827b2daa32e16303235ce33d49f5 Mon Sep 17 00:00:00 2001
fc6001
From: NeilBrown <neilb@suse.de>
fc6001
Date: Thu, 1 Aug 2013 11:16:14 +1000
fc6001
Subject: [PATCH] Grow: exit background thread cleanly on SIGTERM.
fc6001
fc6001
If the mdadm thread that monitors a reshape gets SIGTERM it should
fc6001
exit cleanly and clear the 'suspended' region of the array.
fc6001
However it mustn't clear 'sync_max' as that would allow the
fc6001
reshape to continue unmonitored.
fc6001
fc6001
If the thread ever does get killed, the array should really be
fc6001
shutdown soon after if possible.
fc6001
fc6001
Signed-off-by: NeilBrown <neilb@suse.de>
fc6001
---
fc6001
 Grow.c        | 15 +++++++++++++--
fc6001
 super-intel.c |  2 ++
fc6001
 2 files changed, 15 insertions(+), 2 deletions(-)
fc6001
fc6001
diff --git a/Grow.c b/Grow.c
fc6001
index ff4ed5d..ce80c52 100644
fc6001
--- a/Grow.c
fc6001
+++ b/Grow.c
fc6001
@@ -24,6 +24,7 @@
fc6001
 #include	"mdadm.h"
fc6001
 #include	"dlink.h"
fc6001
 #include	<sys/mman.h>
fc6001
+#include	<signal.h>
fc6001
 
fc6001
 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
fc6001
 #error no endian defined
fc6001
@@ -729,7 +730,8 @@ void abort_reshape(struct mdinfo *sra)
fc6001
 	sysfs_set_num(sra, NULL, "suspend_hi", 0);
fc6001
 	sysfs_set_num(sra, NULL, "suspend_lo", 0);
fc6001
 	sysfs_set_num(sra, NULL, "sync_min", 0);
fc6001
-	sysfs_set_str(sra, NULL, "sync_max", "max");
fc6001
+	// It isn't safe to reset sync_max as we aren't monitoring.
fc6001
+	// Array really should be stopped at this point.
fc6001
 }
fc6001
 
fc6001
 int remove_disks_for_takeover(struct supertype *st,
fc6001
@@ -2726,6 +2728,12 @@ static int impose_level(int fd, int level, char *devname, int verbose)
fc6001
 	return ret_val;
fc6001
 }
fc6001
 
fc6001
+int sigterm = 0;
fc6001
+static void catch_term(int sig)
fc6001
+{
fc6001
+	sigterm = 1;
fc6001
+}
fc6001
+
fc6001
 static int reshape_array(char *container, int fd, char *devname,
fc6001
 			 struct supertype *st, struct mdinfo *info,
fc6001
 			 int force, struct mddev_dev *devlist,
fc6001
@@ -3260,6 +3268,8 @@ started:
fc6001
 		fd = -1;
fc6001
 	mlockall(MCL_FUTURE);
fc6001
 
fc6001
+	signal(SIGTERM, catch_term);
fc6001
+
fc6001
 	if (st->ss->external) {
fc6001
 		/* metadata handler takes it from here */
fc6001
 		done = st->ss->manage_reshape(
fc6001
@@ -4243,7 +4253,8 @@ int child_monitor(int afd, struct mdinfo *sra, struct reshape *reshape,
fc6001
 				forget_backup(dests, destfd,
fc6001
 					      destoffsets, 1);
fc6001
 		}
fc6001
-
fc6001
+		if (sigterm)
fc6001
+			rv = -2;
fc6001
 		if (rv < 0) {
fc6001
 			if (rv == -1)
fc6001
 				done = 1;
fc6001
diff --git a/super-intel.c b/super-intel.c
fc6001
index 4df33f4..7b24068 100644
fc6001
--- a/super-intel.c
fc6001
+++ b/super-intel.c
fc6001
@@ -10444,6 +10444,8 @@ static int imsm_manage_reshape(
fc6001
 			dprintf("wait_for_reshape_imsm returned error!\n");
fc6001
 			goto abort;
fc6001
 		}
fc6001
+		if (sigterm)
fc6001
+			goto abort;
fc6001
 
fc6001
 		if (save_checkpoint_imsm(st, sra, UNIT_SRC_NORMAL) == 1) {
fc6001
 			/* ignore error == 2, this can mean end of reshape here
fc6001
-- 
fc6001
1.8.4.2
fc6001