]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Retry writing 'inactive' state during stopping array
authorKrzysztof Wojcik <krzysztof.wojcik@intel.com>
Fri, 18 Mar 2011 01:42:17 +0000 (12:42 +1100)
committerNeilBrown <neilb@suse.de>
Fri, 18 Mar 2011 01:42:17 +0000 (12:42 +1100)
Issue observed:
Sporadicaly stopping arrays using "mdadm -Ss" command does not succeded.
Cause:
Writting "inactive" to the array state not succeded- array is busy
(accessed by udev, blkid etc.)
Resolution:
If writing 'inactive' fails, wait and retry again (because it is possibly
a transient failure)

Signed-off-by: Krzysztof Wojcik <krzysztof.wojcik@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Manage.c

index 5fd7014ab331771f50d002eb16051cade46ac4a6..5808557ca90dfaea24007740db1fda65962c7a3f 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -224,7 +224,9 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet)
                                close(fd);
                        fprintf(stderr,
                                Name ": Cannot get exclusive access to %s:"
-                               " possibly it is still in use.\n",
+                               "Perhaps a running "
+                               "process, mounted filesystem "
+                               "or active volume group?\n",
                                devname);
                        return 1;
                }
@@ -232,14 +234,23 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet)
                if (mdi &&
                    mdi->array.level > 0 &&
                    is_subarray(mdi->text_version)) {
+                       int err;
                        /* This is mdmon managed. */
                        close(fd);
-                       if (sysfs_set_str(mdi, NULL,
-                                         "array_state", "inactive") < 0) {
-                               if (quiet == 0)
-                                       fprintf(stderr, Name
-                                               ": failed to stop array %s: %s\n",
-                                               devname, strerror(errno));
+
+                       count = 25;
+                       while (count &&
+                              (err = sysfs_set_str(mdi, NULL,
+                                                   "array_state",
+                                                   "inactive")) < 0
+                              && errno == EBUSY) {
+                               usleep(200000);
+                               count--;
+                       }
+                       if (err && !quiet) {
+                               fprintf(stderr, Name
+                                       ": failed to stop array %s: %s\n",
+                                       devname, strerror(errno));
                                return 1;
                        }