Skip to content

Commit

Permalink
lvm2: Try opening for unused device detection harder
Browse files Browse the repository at this point in the history
Though the voluntary BSD locks cannot be used here due to opening
O_EXCL already, let's make several attempts before bailing out.
  • Loading branch information
tbzatek committed Nov 5, 2024
1 parent 0889d70 commit d747e73
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion modules/lvm2/udiskslvm2daemonutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ udisks_daemon_util_lvm2_block_is_unused (UDisksBlock *block,
{
const gchar *device_file;
int fd;
gint num_tries = 0;

device_file = udisks_block_get_device (block);
fd = open (device_file, O_RDONLY | O_EXCL);

while ((fd = open (device_file, O_RDONLY | O_EXCL)) < 0)
{
g_usleep (100 * 1000); /* microseconds */
if (num_tries++ > 10)
break;
}
if (fd < 0)
{
g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
Expand Down

0 comments on commit d747e73

Please sign in to comment.