Skip to content

Commit

Permalink
udiskslinuxblockobject: Try issuing BLKRRPART ioctl harder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tbzatek committed Nov 14, 2023
1 parent 524dea5 commit eb1d4a2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/udiskslinuxblockobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit eb1d4a2

Please sign in to comment.