From: Pawel Baldysiak Subject: [PATCH] Manage.c: Try to get EXCL access more times while stopping the array Date: Wed, 10 Apr 2013 16:00:29 +0200 References: bnc#813731 If mdadm does not get EXCL access to the array and it is managed by mdmon, it should flush monitor and try again, because there still can be (for example) a process that is finishing aborting reshape. If this fails couple of times, mdadm should stop trying, print an error and abort stopping the array. Modified to use mdi->text_version instead of devnm - neilb Signed-off-by: Pawel Baldysiak Signed-off-by: NeilBrown --- Manage.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) --- mdadm-3.2.6.orig/Manage.c +++ mdadm-3.2.6/Manage.c @@ -228,8 +228,19 @@ int Manage_runstop(char *devname, int fd /* Get EXCL access first. If this fails, then attempting * to stop is probably a bad idea. */ + mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION); close(fd); - fd = open(devname, O_RDONLY|O_EXCL); + count = 5; + while (((fd = open(devname, O_RDONLY|O_EXCL)) < 0 + || fd2devnum(fd) != devnum) + && mdi && is_subarray(mdi->text_version) + && mdmon_running(devname2devnum(mdi->text_version+1)) + && count) { + if (fd >= 0) + close(fd); + flush_mdmon(mdi->text_version); + count--; + } if (fd < 0 || fd2devnum(fd) != devnum) { if (fd >= 0) close(fd); @@ -239,9 +250,10 @@ int Manage_runstop(char *devname, int fd "process, mounted filesystem " "or active volume group?\n", devname); + if (mdi) + sysfs_free(mdi); return 1; } - mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION); if (mdi && mdi->array.level > 0 && is_subarray(mdi->text_version)) {