From 8171b93700f8f6f6a646d8b894e7cd5ba7236783 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Tue, 13 Sep 2011 15:13:41 +0000 Subject: [PATCH] Retry DM_DEVICE_REMOVE ioctl if device is busy. This is a workaround for long-lasting problem with using the WATCH udev rule. When trying to remove a DM device, this one can still be opened while processing the event in parallel (generated based on the WATCH udev rule). Let's use this until we have a proper solution. --- WHATS_NEW_DM | 1 + libdm/ioctl/libdm-iface.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index a761f1ba1..eec750e07 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.68 - ================================== + Retry DM_DEVICE_REMOVE ioctl if device is busy. Remove unused passed parameters for _mirror_emit_segment_line(). Add dm_config and string character escaping functions to libdevmapper. Mark unreleased memory pools as internal error. diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c index 816f1e645..a6097d35d 100644 --- a/libdm/ioctl/libdm-iface.c +++ b/libdm/ioctl/libdm-iface.c @@ -1539,11 +1539,14 @@ static const char *_sanitise_message(char *message) return sanitised_message; } +#define DM_REMOVE_IOCTL_RETRIES 25 + static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command, unsigned repeat_count) { struct dm_ioctl *dmi; int ioctl_with_uevent; + int retries = DM_REMOVE_IOCTL_RETRIES; dmi = _flatten(dmt, repeat_count); if (!dmi) { @@ -1627,11 +1630,23 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command, dmt->sector, _sanitise_message(dmt->message), dmi->data_size); #ifdef DM_IOCTLS +repeat_dm_ioctl: if (ioctl(_control_fd, command, dmi) < 0) { if (errno == ENXIO && ((dmt->type == DM_DEVICE_INFO) || (dmt->type == DM_DEVICE_MKNODES) || (dmt->type == DM_DEVICE_STATUS))) dmi->flags &= ~DM_EXISTS_FLAG; /* FIXME */ + /* + * FIXME: This is a workaround for asynchronous events generated + * as a result of using the WATCH udev rule with which we + * have no way of synchronizing. Processing such events in + * parallel causes devices to be open. + */ + else if (errno == EBUSY && (dmt->type == DM_DEVICE_REMOVE) && retries--) { + log_debug("device-mapper: device is busy, retrying removal"); + usleep(200000); + goto repeat_dm_ioctl; + } else { if (_log_suppress) log_verbose("device-mapper: %s ioctl "