Race condition in map_partitions method in Disk class

Bug #1363574 reported by M. Vefa Bicakci
22
This bug affects 5 people
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/loop2p1']
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/loop2p1']) returned 1. stdout: , stderr: mke2fs 1.42.12 (29-Aug-2014)
The file /dev/mapper/loop2p1 does not exist and no size was specified.
=== >8 ===

Revision history for this message
M. Vefa Bicakci (mvb) wrote :

(Sorry for changing the type to "Public Security". I did this by accident and then reverted my accidental change.)

information type: Public → Public Security
information type: Public Security → Public
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Hi - sleep 3 did fix it for me, but is racy. Changing the kpartx to add '-s' (sync) also fixed it fo rme, so I'm adding that to the bzr tree. It will be in x-series when I post the new release there.

Changed in vmbuilder:
importance: Undecided → High
status: New → Fix Committed
Revision history for this message
W. J. van der Laan (laanwj) wrote :

Still happens on Wily.
Serge Hallyn's fix to add '-s' worked.

Revision history for this message
Cristian Klein (cristiklein) wrote :

The '-s' workaround helped me too.

Is there any update on this bug? Has anybody notified the vmbuilder developers so they can fix the source code?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.