dissect-image: wait for the main device and all partitions to be known by udev
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 13 Dec 2018 15:39:05 +0000 (16:39 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 17 Dec 2018 12:50:57 +0000 (13:50 +0100)
commita8040b6d0ad43e5cb7168fd3b739c8c68aaa61b1
treee267246850fdcea0554c10136a455e47bf6fd7a0
parentb887c8b8a836963c2949ae6a11b77430886d0b77
dissect-image: wait for the main device and all partitions to be known by udev

Fixes #10526.

Even if we waited for the root device to appear, the mount could still fail if
we didn't wait for udev to initalize the device. In particular, the
/dev/block/n:m path used to mount the device is created by udev, and nspawn
would sometimes win the race and the mount would fail with -ENOENT.

The same wait is done for partitions, since if we try to mount them, the same
considerations apply.

Note: I first implemented a version which just does a loop (with a short wait).
In that approach, udev takes on average ~800 µs to initialize the loopback
device. The approach where we set up a monitor and avoid the loop is a bit
nicer. There doesn't seem to be a significant difference in speed.
With 1000 invocations of 'systemd-nspawn -i image.squashfs echo':

loop (previous approach):
real 4m52.625s
user 0m37.094s
sys 2m14.705s

monitor (this patch):
real 4m50.791s
user 0m36.619s
sys 2m14.039s
src/shared/dissect-image.c