Blame SOURCES/mdadm-3.2.6-Manage_runstop-call-flush_mdmon-if-O_EXCL-fails-on-s.patch

373056
From 2fdf559d74a48806900b63f1b4504a18dec048a9 Mon Sep 17 00:00:00 2001
373056
From: NeilBrown <neilb@suse.de>
373056
Date: Mon, 22 Apr 2013 17:05:33 +1000
373056
Subject: [PATCH] Manage_runstop: call flush_mdmon if O_EXCL fails on stopping
373056
 mdmon array.
373056
373056
When stopping an mdmon array, at reshape might be being aborted
373056
which inhibets O_EXCL.  So if that is possible, call flush_mdmon
373056
to make sure mdmon isn't still busy.
373056
373056
Reported-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
373056
Signed-off-by: NeilBrown <neilb@suse.de>
373056
---
373056
 Manage.c | 29 ++++++++++++++++++++++++-----
373056
 1 file changed, 24 insertions(+), 5 deletions(-)
373056
373056
diff --git a/Manage.c b/Manage.c
373056
index e3d3041..e37f415 100644
373056
--- a/Manage.c
373056
+++ b/Manage.c
373056
@@ -221,8 +222,19 @@ int Manage_runstop(char *devname, int fd, int runstop,
373056
 		/* Get EXCL access first.  If this fails, then attempting
373056
 		 * to stop is probably a bad idea.
373056
 		 */
373056
-		close(fd);
373056
-		fd = open(devname, O_RDONLY|O_EXCL);
373056
+		mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION);
373056
+		close(fd);
373056
+		count = 5;
373056
+		while (((fd = open(devname, O_RDONLY|O_EXCL)) < 0
373056
+			|| fd2devnum(fd) != devnum)
373056
+			&& mdi && !is_subarray(mdi->text_version)
373056
+			&& mdmon_running(devname2devnum(mdi->sys_name))
373056
+			&& count) {
373056
+			if (fd >= 0)
373056
+				close(fd);
373056
+			flush_mdmon(mdi->sys_name);
373056
+			count--;
373056
+		}
373056
 		if (fd < 0 || fd2devnum(fd) != devnum) {
373056
 			if (fd >= 0)
373056
 				close(fd);
373056
@@ -237,7 +257,6 @@ int Manage_runstop(char *devname, int fd, int runstop,
373056
 				devname);
373056
 			return 1;
373056
 		}
373056
-		mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION);
373056
 		if (mdi &&
373056
 		    mdi->array.level > 0 &&
373056
 		    is_subarray(mdi->text_version)) {
373056
373056
-- 
373056
1.8.3.1
373056