udisks2/udisks-2.11.0-BLKRRPART_harder.patch

56 lines
1.9 KiB
Diff
Raw Normal View History

From eb1d4a2bcbb8744074d17553bd0d55ffbd76bdeb Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Tue, 14 Nov 2023 13:16:39 +0000
Subject: [PATCH] udiskslinuxblockobject: Try issuing BLKRRPART ioctl harder
For some reason even after acquiring a voluntary BSD lock on
the device the BLKRRPART ioctl still fails with EBUSY. Wait
a couple of msec and everything is fine.
So try harder, several attempts, if busy. There might be number
of things going on in the system and it's out of our control
even when holding a lock.
---
src/udiskslinuxblockobject.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/udiskslinuxblockobject.c b/src/udiskslinuxblockobject.c
index d5da4bc4d9..33604df841 100644
--- a/src/udiskslinuxblockobject.c
+++ b/src/udiskslinuxblockobject.c
@@ -1098,23 +1098,31 @@ udisks_linux_block_object_reread_partition_table (UDisksLinuxBlockObject *objec
}
else
{
- gint num_tries = 0;
+ gint num_tries;
/* acquire an exclusive BSD lock to prevent udev probes.
* See also https://systemd.io/BLOCK_DEVICE_LOCKING
*/
+ num_tries = 10;
while (flock (fd, LOCK_EX | LOCK_NB) != 0)
{
g_usleep (100 * 1000); /* microseconds */
- if (num_tries++ > 5)
+ if (num_tries-- < 0)
break;
}
- if (ioctl (fd, BLKRRPART) != 0)
+ num_tries = 5;
+ while (ioctl (fd, BLKRRPART) != 0)
{
+ if (errno == EBUSY && num_tries-- >= 0)
+ {
+ g_usleep (200 * 1000); /* microseconds */
+ continue;
+ }
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
"Error re-reading partition table (BLKRRPART ioctl) on %s: %m", device_file);
ret = FALSE;
+ break;
}
close (fd);
}