udisks-2.11.0-BLKRRPART_harder.patch 1.9 KB

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