s390-tools/dasdfmt-retry-BIODASDINFO-if-device-is-busy.patch

67 lines
1.8 KiB
Diff

From 943e577440d74ad7f8787af2590c8ab4579a459b Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
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 <hare@suse.de>
---
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
@@ -588,7 +616,7 @@
*/
static void check_disk(dasdfmt_info_t *info, char *devname)
{
- int ro, errno_save;
+ int ro, errno_save, i = 0;
if (ioctl(filedes, BLKROGET, &ro) != 0) {
errno_save = errno;
@@ -602,9 +630,27 @@
if (ro)
ERRMSG_EXIT(EXIT_FAILURE, "Disk is read only!\n");
- if (!info->force)
+ if (!info->force) {
+ /*
+ * udev strikes again.
+ * Modern udev will issue a 'change' event whenever
+ * a device opened with O_RDWR is closed again.
+ * On the grounds that program _might_ have changed
+ * the partition table.
+ * And confusing the hell out ouf anyone else.
+ * Bah.
+ */
+ for ( i = 0 ; i < 6 ; i++ ) {
+ if (info->dasd_info.open_count > 1) {
+ get_device_info(info);
+ sleep(1);
+ }
+ else break;
+
+ }
if (info->dasd_info.open_count > 1)
ERRMSG_EXIT(EXIT_BUSY, "Disk in use!\n");
+ }
if (strncmp(info->dasd_info.type, "ECKD", 4) != 0) {
ERRMSG_EXIT(EXIT_FAILURE,
--
1.8.4.5