From a465359a5d09373f4abc66381dccfb90631345cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 17 May 2016 22:41:51 +0200 Subject: [PATCH] udev: fix deadlock on xenstore access during dom0 boot During early dom0 boot, before xenstored is started any access to it through /proc/xen/xenbus (or /dev/xen/xenbus) will wait until xenstored is started. If that happens in script ordered to start before xenstored, we have a deadlock. Prevent this by using `xenstore-ls -s` in dom0, which will fail immediately when xenstored isn't running yet. This fail isn't a problem, because when xenstored isn't running yet, surely device isn't attached anywhere. QubesOS/qubes-issues#1081 (cherry picked from commit cdbcb2eb55036b21ef31bb5ab5d698a4874d903c) --- udev/udev-block-add-change | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/udev/udev-block-add-change b/udev/udev-block-add-change index 90eac10..b9f970b 100755 --- a/udev/udev-block-add-change +++ b/udev/udev-block-add-change @@ -2,6 +2,7 @@ shopt -s nullglob + export LC_CTYPE=en_US.UTF-8 NAME=${DEVNAME#/dev/} DESC="`echo "${ID_MODEL} (${ID_FS_LABEL})" | iconv -f utf8 -t ascii//TRANSLIT`" @@ -36,9 +37,18 @@ is_used() { return 1 } +# communicate with xenstored through socket in dom0 +# trying to access xenstore before xenstored is started, hang forever (in +# non-killable state), so better fail ('-s' in VM if /proc/xen isn't mounted +# yet) than hang dom0 boot +if [ ! -r /proc/xen/capabilities ] || grep -q control_d /proc/xen/capabilities; then + XENSTORE_LS="xenstore-ls -s" +else + XENSTORE_LS="xenstore-ls" +fi is_attached() { dev_hex=$(stat -c %t:%T /dev/$(basename $1)) - xenstore-ls backend/vbd | grep -q "physical-device = \"$dev_hex\"" + $XENSTORE_LS backend/vbd | grep -q "physical-device = \"$dev_hex\"" } # update info about parent devices, if any: