From: Benjamin Marzinski <bmarzins@redhat.com>
To: device-mapper development <dm-devel@redhat.com>
Cc: Christophe Varoqui <christophe.varoqui@gmail.com>
Subject: [PATCH] multipath: Fix kpartx and udevd race
Date: Mon, 7 Jan 2013 23:56:35 -0600 [thread overview]
Message-ID: <20130108055635.GG19059@ether.msp.redhat.com> (raw)
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);
reply other threads:[~2013-01-08 5:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130108055635.GG19059@ether.msp.redhat.com \
--to=bmarzins@redhat.com \
--cc=christophe.varoqui@gmail.com \
--cc=dm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox