From patchwork Tue Jan 8 05:56:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 1944051 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork1.kernel.org (Postfix) with ESMTP id 10E933FED4 for ; Tue, 8 Jan 2013 06:02:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r085ueK1013816; Tue, 8 Jan 2013 00:56:42 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r085ucRl010135 for ; Tue, 8 Jan 2013 00:56:38 -0500 Received: from ether.msp.redhat.com (ether.msp.redhat.com [10.15.80.119]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r085ubFM008183 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 8 Jan 2013 00:56:38 -0500 Received: from ether.msp.redhat.com (localhost.localdomain [127.0.0.1]) by ether.msp.redhat.com (8.14.1/8.14.1) with ESMTP id r085ubcE016927; Mon, 7 Jan 2013 23:56:37 -0600 Received: (from bmarzins@localhost) by ether.msp.redhat.com (8.14.1/8.14.1/Submit) id r085uaHD016926; Mon, 7 Jan 2013 23:56:36 -0600 Date: Mon, 7 Jan 2013 23:56:35 -0600 From: Benjamin Marzinski To: device-mapper development Message-ID: <20130108055635.GG19059@ether.msp.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH] multipath: Fix kpartx and udevd race X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com 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 --- kpartx/lopart.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel 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);