From d27d22a3cfe3f8d7ee2e65eaa497b5a340506f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 1 Aug 2015 21:51:02 +0200 Subject: [PATCH] Merge remote-tracking branch 'qubesos/pr/5' * qubesos/pr/5: fix VM autostart race condition Fixes qubesos/qubes-issues#1075 Conflicts: linux/aux-tools/prepare-volatile-img.sh --- linux/aux-tools/prepare-volatile-img.sh | 37 +++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/linux/aux-tools/prepare-volatile-img.sh b/linux/aux-tools/prepare-volatile-img.sh index a31c92e4..33dfc9b9 100755 --- a/linux/aux-tools/prepare-volatile-img.sh +++ b/linux/aux-tools/prepare-volatile-img.sh @@ -31,20 +31,23 @@ sfdisk --no-reread -u M "$FILENAME" > /dev/null 2> /dev/null < /dev/null -if [ "$created" = "yes" ]; then - rm -f ${loopdev}p* -fi -losetup -d ${loopdev} || : -chown --reference `dirname "$FILENAME"` "$FILENAME" +( + flock 200 + loopdev=`losetup -f --show --partscan "$FILENAME"` + udevadm settle + created= + if [ ! -e ${loopdev}p1 ]; then + # device wasn't created automatically, probably udev isn't running; + # create devs manually + for partdev in /sys/block/$(basename ${loopdev})/loop*p*; do + mknod /dev/$(basename ${partdev}) b $(cat ${partdev}/dev | tr : ' ') + done + created=yes + fi + mkswap -f ${loopdev}p1 > /dev/null + if [ "$created" = "yes" ]; then + rm -f ${loopdev}p* + fi + losetup -d ${loopdev} || : + chown --reference `dirname "$FILENAME"` "$FILENAME" +) 200>"/var/run/qubes/prepare-volatile-img.lock"