In src/udiskslinuxpartitiontable.c, handle_create_partition():
1- New partition is created by calling parted
2- udisks_linux_block_object_trigger_uevent() is called to trigger udev
3- Wait for partition to show up by using wait_for_partition()
4- Wipe new partition by calling wipefs
5- udisks_linux_block_object_trigger_uevent() is called to trigger udev
The problem arises because #2 and #5 aren't done synchronously. When udev processes the device change request, it removes the newly created partition device (ie: sdb1), and then adds it back again. This happens in a race with #4, and results in wipefs being called while the device is removed.
This issue can be solved in a few ways, from best to worst:
1- Create a sync version of udisks_linux_block_object_trigger_uevent() that waits until the device is actually handled in #2 and #5
2- Make sure there are no pending events in the udev queue after #2 and #5
3- Adding an artificial delay after #2 and #5 to wait until the device has settled down (some places in the code add a udisks_linux_block_object_reread_partition_table(), which I assume results in enough delay to not hit the race most of the time.)
I've tried removing #2 and #5 altogether, and that appeared to work also, but then gnome-disks crashes because udev hasn't added the device back fast enough after the wipefs.
Here's my understanding of this issue:
In src/udiskslinux partitiontable. c, handle_ create_ partition( ):
1- New partition is created by calling parted linux_block_ object_ trigger_ uevent( ) is called to trigger udev partition( ) linux_block_ object_ trigger_ uevent( ) is called to trigger udev
2- udisks_
3- Wait for partition to show up by using wait_for_
4- Wipe new partition by calling wipefs
5- udisks_
The problem arises because #2 and #5 aren't done synchronously. When udev processes the device change request, it removes the newly created partition device (ie: sdb1), and then adds it back again. This happens in a race with #4, and results in wipefs being called while the device is removed.
This issue can be solved in a few ways, from best to worst:
1- Create a sync version of udisks_ linux_block_ object_ trigger_ uevent( ) that waits until the device is actually handled in #2 and #5 linux_block_ object_ reread_ partition_ table() , which I assume results in enough delay to not hit the race most of the time.)
2- Make sure there are no pending events in the udev queue after #2 and #5
3- Adding an artificial delay after #2 and #5 to wait until the device has settled down (some places in the code add a udisks_
I've tried removing #2 and #5 altogether, and that appeared to work also, but then gnome-disks crashes because udev hasn't added the device back fast enough after the wipefs.