All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] multipath: Fix kpartx and udevd race
@ 2013-01-10 20:56 Benjamin Marzinski
  0 siblings, 0 replies; only message in thread
From: Benjamin Marzinski @ 2013-01-10 20:56 UTC (permalink / raw)
  To: device-mapper development; +Cc: Christophe Varoqui

Sometimes when kpartx is used to view partition data on disk image files,
udev still has the loop device open when kpartx is trying to tear it down.
This causes the LOOP_CLR_FD ioctl to fail with EBUSY.  kpartx now retries
in this case.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 kpartx/lopart.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Index: multipath-tools-130107/kpartx/lopart.c
===================================================================
--- multipath-tools-130107.orig/kpartx/lopart.c
+++ multipath-tools-130107/kpartx/lopart.c
@@ -286,6 +286,7 @@ set_loop (const char *device, const char
 extern int 
 del_loop (const char *device)
 {
+	int retries = 3;
 	int fd;
 
 	if ((fd = open (device, O_RDONLY)) < 0) {
@@ -295,10 +296,17 @@ del_loop (const char *device)
 		return 1;
 	}
 
-	if (ioctl (fd, LOOP_CLR_FD, 0) < 0) {
-		perror ("ioctl: LOOP_CLR_FD");
-		close (fd);
-		return 1;
+	while (ioctl (fd, LOOP_CLR_FD, 0) < 0) {
+		if (errno != EBUSY || retries-- <= 0) {
+			perror ("ioctl: LOOP_CLR_FD");
+			close (fd);
+			return 1;
+		}
+		fprintf(stderr,
+			"loop: device %s still in use, retrying delete\n",
+			device);
+		sleep(1);
+		continue;
 	}
 
 	close (fd);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-01-10 20:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-10 20:56 [PATCH v2] multipath: Fix kpartx and udevd race Benjamin Marzinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.