dom0/core: detect if PCI device not already attached to some other VM (#522)

This commit is contained in:
Marek Marczykowski 2012-04-18 11:09:53 +02:00
parent c5d0b4e5de
commit 300d0e1841
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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']