dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone
Blob Blame History Raw
From 2fdf559d74a48806900b63f1b4504a18dec048a9 Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@suse.de>
Date: Mon, 22 Apr 2013 17:05:33 +1000
Subject: [PATCH] Manage_runstop: call flush_mdmon if O_EXCL fails on stopping
 mdmon array.

When stopping an mdmon array, at reshape might be being aborted
which inhibets O_EXCL.  So if that is possible, call flush_mdmon
to make sure mdmon isn't still busy.

Reported-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
---
 Manage.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/Manage.c b/Manage.c
index e3d3041..e37f415 100644
--- a/Manage.c
+++ b/Manage.c
@@ -221,8 +222,19 @@ int Manage_runstop(char *devname, int fd, int runstop,
 		/* Get EXCL access first.  If this fails, then attempting
 		 * to stop is probably a bad idea.
 		 */
-		close(fd);
-		fd = open(devname, O_RDONLY|O_EXCL);
+		mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION);
+		close(fd);
+		count = 5;
+		while (((fd = open(devname, O_RDONLY|O_EXCL)) < 0
+			|| fd2devnum(fd) != devnum)
+			&& mdi && !is_subarray(mdi->text_version)
+			&& mdmon_running(devname2devnum(mdi->sys_name))
+			&& count) {
+			if (fd >= 0)
+				close(fd);
+			flush_mdmon(mdi->sys_name);
+			count--;
+		}
 		if (fd < 0 || fd2devnum(fd) != devnum) {
 			if (fd >= 0)
 				close(fd);
@@ -237,7 +257,6 @@ int Manage_runstop(char *devname, int fd, int runstop,
 				devname);
 			return 1;
 		}
-		mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION);
 		if (mdi &&
 		    mdi->array.level > 0 &&
 		    is_subarray(mdi->text_version)) {

-- 
1.8.3.1