Retry writing 'inactive' state during stopping array

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>
This commit is contained in:
Krzysztof Wojcik 2011-03-18 12:42:17 +11:00 committed by NeilBrown
parent 983fff45a1
commit 1ae42d9d99
1 changed files with 18 additions and 7 deletions

View File

@ -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;
}