Race condition in map_partitions method in Disk class
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
VMBuilder |
Fix Committed
|
High
|
Unassigned |
Bug Description
Hello,
I have been experimenting with gitian, which uses vmbuilder to build virtual machines. I noticed that vmbuilder uses kpartx to map partitions from a disk image to loopback block devices in /dev/mapper, and then creates ext4 filesystems on the partitions.
In my set-up, however, mapping the partitions to loopback block devices seems to take some time, which introduces a race condition, as vmbuilder expects that the loopback devices are available right after the execution of kpartx. Please see the debugging log output below.
If I add a "time.sleep(3)" call to the end of the map_partitions method in the Disk class in disk.py, then this problem disappears.
Would it be possible to either sleep for a few seconds and/or poll the existence of the loopback block devices, so as to remove this race condition?
Thank you!
=== 8< ===
2014-08-31 01:33 DEBUG : ['kpartx', '-av', '/tmp/tmpwgateA']
2014-08-31 01:33 DEBUG : add map loop2p1 (253:14): 0 19997984 linear /dev/loop2 63
2014-08-31 01:33 DEBUG : add map loop2p2 (253:15): 0 1996800 linear /dev/loop2 20000768
2014-08-31 01:33 INFO : Creating file systems
2014-08-31 01:33 DEBUG : ['mkfs.ext4', '-F', '/dev/mapper/
2014-08-31 01:33 INFO : mke2fs 1.42.12 (29-Aug-2014)
2014-08-31 01:33 INFO : The file /dev/mapper/loop2p1 does not exist and no size was specified.
2014-08-31 01:33 INFO : Cleaning up
2014-08-31 01:33 DEBUG : ['kpartx', '-d', '/tmp/tmpwgateA']
2014-08-31 01:33 DEBUG : loop deleted : /dev/loop2
2014-08-31 01:33 DEBUG : ['kpartx', '-d', '/tmp/tmpwgateA']
2014-08-31 01:33 DEBUG : Removing partition /dev/mapper/loop2p1
2014-08-31 01:33 DEBUG : ['dmsetup', 'info', 'loop2pp1']
2014-08-31 01:33 DEBUG : Device does not exist.
2014-08-31 01:33 DEBUG : Command failed
2014-08-31 01:33 DEBUG : Removing partition /dev/mapper/loop2p2
2014-08-31 01:33 DEBUG : ['dmsetup', 'info', 'loop2pp2']
2014-08-31 01:33 DEBUG : Device does not exist.
2014-08-31 01:33 DEBUG : Command failed
2014-08-31 01:33 ERROR : Process (['mkfs.ext4', '-F', '/dev/mapper/
The file /dev/mapper/loop2p1 does not exist and no size was specified.
=== >8 ===
(Sorry for changing the type to "Public Security". I did this by accident and then reverted my accidental change.)