From 300d0e184134ee46df3a2e8397794e4ff15caf48 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 18 Apr 2012 11:09:53 +0200 Subject: [PATCH] dom0/core: detect if PCI device not already attached to some other VM (#522) --- dom0/aux-tools/unbind_pci_device.sh | 8 ++++++++ dom0/qvm-core/qubes.py | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/dom0/aux-tools/unbind_pci_device.sh b/dom0/aux-tools/unbind_pci_device.sh index 3995ec06..8df56f2c 100755 --- a/dom0/aux-tools/unbind_pci_device.sh +++ b/dom0/aux-tools/unbind_pci_device.sh @@ -29,6 +29,14 @@ BDF=0000:$BDF #echo -n "Binding device $BDF to xen-pciback..." if [ -e /sys/bus/pci/drivers/pciback/$BDF ]; then # Already bound to pciback + # Check if device not assigned to any RUNNING VM + XS_PATH=/local/domain/0/backend/pci + GREP_RE="^$XS_PATH/[0-9]*/[0-9]*/dev-[0-9]* = \"$BDF\"" + if xenstore-ls -f $XS_PATH | grep -q "$GREP_RE"; then + DOMID=`xenstore-ls -f $XS_PATH | grep "$GREP_RE"|cut -d/ -f7` + echo "ERROR: Device already attached to the running VM '`xl domname $DOMID`'" >&2 + exit 1 + fi exit 0 fi diff --git a/dom0/qvm-core/qubes.py b/dom0/qvm-core/qubes.py index cdd99627..3d0f6e96 100755 --- a/dom0/qvm-core/qubes.py +++ b/dom0/qvm-core/qubes.py @@ -1372,7 +1372,10 @@ class QubesVm(object): # Bind pci devices to pciback driver for pci in self.pcidevs: - subprocess.check_call(['sudo', qubes_pciback_cmd, pci]) + try: + subprocess.check_call(['sudo', qubes_pciback_cmd, pci]) + except subprocess.CalledProcessError: + raise QubesException("Failed to prepare PCI device %s" % pci) xl_cmdline = ['sudo', '/usr/sbin/xl', 'create', self.conf_file, '-q', '-p']