Fix partition races while partitioning
Fix partition races while partitioning

Every so often we've seen races where seemingly the partition device
disappeared when trying to use it. These became a bit more frequent
after some speedups in fakemachine. Digging deeper it turns out that
udev helpfully ask the kernel to rescan the partition table when it gets
told via inotify that something might have written to it.

As we're using parted, which already tells the kernel about partitions
it created, this gets rather confusion. The new partition device would pop up
(triggered by parted), parted would close the disk device node; This
then would notify udev, which asked the kernel to rescan the partition
table on the device *again*, which in turn causes all the partition
device nodes to disappear and re-appear, leaving a nice window for
things to go horribly horribly wrong.

Ofcourse this all happens asynchronously, so there is really no way to
know everything settled down..

Luckily there is one upside to this depressing story, udev only does
this when it can get an exclusive lock on the disk device (e.g. none of
the partitions are mounted and nobody else holds an exclusive lock). So
we can avoid all this madness by simply holding an exclusive device
lock and only releasing it after mounting has happened.

As one last unexpected side-effect, while we do hold the exclusive lock
it turns out udev also does not setup the various symlinks. So instead
for the partition device use the canonical device names rather then the
aliases. On the bright side those device nodes are generated directly by
the kernel with devtmpfs, so there is no need to wait for udev to have
done its processing anymore.

Closes #50

Signed-off-by: Sjoerd Simons <1371fd10dd05a897e5b55dc6ae4fbafa1f84c6ec@collabora.co.uk>

go-debos/debos,d4s/debos