From 943e577440d74ad7f8787af2590c8ab4579a459b Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Thu, 5 Nov 2015 10:57:38 +0100 Subject: [PATCH] dasdfmt: retry BIODASDINFO if device is busy Modern udev have the wonderful 'feature' to sending a 'change' event whenever a device opened with O_RDWR is closed again. The reasoning is that the said program _might_ have changed the partition table and hence we _might_ have missed a partition update. But in doing so it not only generated tons of pointless events but also confused the hell out of other programs. Idiots. References: bsc#937340 Signed-off-by: Hannes Reinecke --- dasdfmt/dasdfmt.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/dasdfmt/dasdfmt.c b/dasdfmt/dasdfmt.c index e1877ac..f03cbad 100644 --- a/dasdfmt/dasdfmt.c +++ b/dasdfmt/dasdfmt.c @@ -270,7 +270,7 @@ static void init_info(dasdfmt_info_t *info) static void check_disk(dasdfmt_info_t *info) { dasd_information_t dasd_info; - int ro, errno_save; + int ro, errno_save, i = 0; if (ioctl(filedes, BLKROGET, &ro) != 0) { errno_save = errno; @@ -283,7 +283,7 @@ static void check_disk(dasdfmt_info_t *info) if (ro) { ERRMSG_EXIT(EXIT_FAILURE, "Disk is read only!\n"); } - +retry: if (ioctl(filedes, BIODASDINFO, &dasd_info) != 0) { errno_save = errno; close(filedes); @@ -294,8 +294,23 @@ static void check_disk(dasdfmt_info_t *info) } if (!info->force) - if (dasd_info.open_count > 1) + /* + * udev strikes again. + * Modern udev will issue a 'change' event whenever + * a device opened with O_RDWR is closed again. + * On the ground that program _might_ have changed + * the partition table. + * And confusing the hell out ouf anyone else. + * Bah. + */ + if (dasd_info.open_count > 1) { + if (i < 5) { + ++i; + sleep(1); + goto retry; + } ERRMSG_EXIT(EXIT_BUSY, "Disk in use!\n"); + } info->usage_count = dasd_info.open_count; info->devno = dasd_info.devno; -- 1.8.4.5