Skip to contentSkip to conversation

Manage.c: Try to get EXCL access more times while stopping the array

PATCH New Pawel Baldysiak 1 participant 1 message Apr 3, 2013 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Manage.c: Try to get EXCL access more times while stopping the array

If mdadm does not get EXCL access to the array, it should try again after a while, because there still can be (for example) a process of mdmon that is finishing aborting reshape. If this fails couple of times, mdadm should stop
trying, print an error and abort stopping the array.

---
 Manage.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
Manage.c +8 -1
index 6267c0c..23e7c85 100644
@@ -222,7 +222,14 @@ int Manage_runstop(char *devname, int fd, int runstop,
 		 * to stop is probably a bad idea.
 		 */
 		close(fd);
-		fd = open(devname, O_RDONLY|O_EXCL);
+		count = 5;
+		while (((fd = open(devname, O_RDONLY|O_EXCL)) < 0 ||
+				strcmp(fd2devnm(fd), devnm) != 0) && count) {
+			if (fd >= 0)
+				close(fd);
+			usleep(200000);
+			count--;
+		}
 		if (fd < 0 || strcmp(fd2devnm(fd), devnm) != 0) {
 			if (fd >= 0)
 				close(fd);