Add 'force' flag to *hot_remove_disk().

In rare circumstances, the short period that *hot_remove_disk()
waits isn't long enough to IO to complete.  This particularly happens
when a device is failing and many retries are still happening.

We don't want to increase the normal wait time for "mdadm --remove"
as that might be use just to test if a device is active or not, and a
delay would be problematic.
So allow "--force" to mean that mdadm should try extra hard for a
--remove to complete, waiting up to 5 seconds.

Note that this patch fixes a comment which claim the previous
wait time was half a second, where it was really 50msec.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
This commit is contained in:
NeilBrown 2017-03-27 14:36:56 +11:00 committed by Jes Sorensen
parent fdd015696c
commit 1ab9ed2afb
4 changed files with 13 additions and 13 deletions

2
Grow.c
View File

@ -2749,7 +2749,7 @@ static int impose_level(int fd, int level, char *devname, int verbose)
continue; continue;
ioctl(fd, SET_DISK_FAULTY, ioctl(fd, SET_DISK_FAULTY,
makedev(disk.major, disk.minor)); makedev(disk.major, disk.minor));
hot_remove_disk(fd, makedev(disk.major, disk.minor)); hot_remove_disk(fd, makedev(disk.major, disk.minor), 1);
} }
} }
c = map_num(pers, level); c = map_num(pers, level);

View File

@ -1110,7 +1110,7 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
} }
int Manage_remove(struct supertype *tst, int fd, struct mddev_dev *dv, int Manage_remove(struct supertype *tst, int fd, struct mddev_dev *dv,
int sysfd, unsigned long rdev, int verbose, char *devname) int sysfd, unsigned long rdev, int force, int verbose, char *devname)
{ {
int lfd = -1; int lfd = -1;
int err; int err;
@ -1177,9 +1177,9 @@ int Manage_remove(struct supertype *tst, int fd, struct mddev_dev *dv,
/* device has been removed and we don't know /* device has been removed and we don't know
* the major:minor number * the major:minor number
*/ */
err = sys_hot_remove_disk(sysfd); err = sys_hot_remove_disk(sysfd, force);
} else { } else {
err = hot_remove_disk(fd, rdev); err = hot_remove_disk(fd, rdev, force);
if (err && errno == ENODEV) { if (err && errno == ENODEV) {
/* Old kernels rejected this if no personality /* Old kernels rejected this if no personality
* is registered */ * is registered */
@ -1603,7 +1603,7 @@ int Manage_subdevs(char *devname, int fd,
if (dv->disposition == 'F') if (dv->disposition == 'F')
/* Need to remove first */ /* Need to remove first */
hot_remove_disk(fd, rdev); hot_remove_disk(fd, rdev, force);
/* Make sure it isn't in use (in 2.6 or later) */ /* Make sure it isn't in use (in 2.6 or later) */
tfd = dev_open(dv->devname, O_RDONLY|O_EXCL); tfd = dev_open(dv->devname, O_RDONLY|O_EXCL);
if (tfd >= 0) { if (tfd >= 0) {
@ -1645,7 +1645,7 @@ int Manage_subdevs(char *devname, int fd,
rv = -1; rv = -1;
} else } else
rv = Manage_remove(tst, fd, dv, sysfd, rv = Manage_remove(tst, fd, dv, sysfd,
rdev, verbose, rdev, verbose, force,
devname); devname);
if (sysfd >= 0) if (sysfd >= 0)
close(sysfd); close(sysfd);

View File

@ -1476,8 +1476,8 @@ extern int add_disk(int mdfd, struct supertype *st,
struct mdinfo *sra, struct mdinfo *info); struct mdinfo *sra, struct mdinfo *info);
extern int remove_disk(int mdfd, struct supertype *st, extern int remove_disk(int mdfd, struct supertype *st,
struct mdinfo *sra, struct mdinfo *info); struct mdinfo *sra, struct mdinfo *info);
extern int hot_remove_disk(int mdfd, unsigned long dev); extern int hot_remove_disk(int mdfd, unsigned long dev, int force);
extern int sys_hot_remove_disk(int statefd); extern int sys_hot_remove_disk(int statefd, int force);
extern int set_array_info(int mdfd, struct supertype *st, struct mdinfo *info); extern int set_array_info(int mdfd, struct supertype *st, struct mdinfo *info);
unsigned long long min_recovery_start(struct mdinfo *array); unsigned long long min_recovery_start(struct mdinfo *array);

10
util.c
View File

@ -1795,15 +1795,15 @@ int remove_disk(int mdfd, struct supertype *st,
return rv; return rv;
} }
int hot_remove_disk(int mdfd, unsigned long dev) int hot_remove_disk(int mdfd, unsigned long dev, int force)
{ {
int cnt = 5; int cnt = force ? 500 : 5;
int ret; int ret;
/* HOT_REMOVE_DISK can fail with EBUSY if there are /* HOT_REMOVE_DISK can fail with EBUSY if there are
* outstanding IO requests to the device. * outstanding IO requests to the device.
* In this case, it can be helpful to wait a little while, * In this case, it can be helpful to wait a little while,
* up to half a second, for that IO to flush. * up to 5 seconds if 'force' is set, or 50 msec if not.
*/ */
while ((ret = ioctl(mdfd, HOT_REMOVE_DISK, dev)) == -1 && while ((ret = ioctl(mdfd, HOT_REMOVE_DISK, dev)) == -1 &&
errno == EBUSY && errno == EBUSY &&
@ -1813,9 +1813,9 @@ int hot_remove_disk(int mdfd, unsigned long dev)
return ret; return ret;
} }
int sys_hot_remove_disk(int statefd) int sys_hot_remove_disk(int statefd, int force)
{ {
int cnt = 5; int cnt = force ? 500 : 5;
int ret; int ret;
while ((ret = write(statefd, "remove", 6)) == -1 && while ((ret = write(statefd, "remove", 6)) == -1 &&