From 908c83eaa8fbac9363be1c1fa0f0f9cef16a5d6b Mon Sep 17 00:00:00 2001 From: Alexandre Bezroutchko Date: Fri, 12 Oct 2012 23:34:18 +0200 Subject: [PATCH] dom0/qvm-usb: detach operation appears to work --- README.pvusb | 2 +- install-pvusb-dom0.sh | 1 + misc/xl-qvm-usb-detach.py | 49 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 misc/xl-qvm-usb-detach.py diff --git a/README.pvusb b/README.pvusb index a38ef6a..9e7add8 100644 --- a/README.pvusb +++ b/README.pvusb @@ -74,7 +74,7 @@ Known issues * Virtual USB devices (ones created by PVUSB frontend) may be listed * The installation/configuration is not persistent, not retained between reboots * No logging / audit trail? -* When an attached device is physically unplugged, USB port remains mapped but not displayed in the list +* When an attached device is physically unplugged, USB port remains mapped but not displayed in the list. If device is plugged back it continues to work. Unlisted device cannot be detached. * We are not attaching actual devices, but USB ports (different behavior from VMWare, might be confusing) * After device is detached from the frontend and returned back to the backend it is not usable there diff --git a/install-pvusb-dom0.sh b/install-pvusb-dom0.sh index f96eaaf..81c5e07 100755 --- a/install-pvusb-dom0.sh +++ b/install-pvusb-dom0.sh @@ -7,5 +7,6 @@ # Copy files cp misc/xl-qvm-usb-attach.py /usr/lib/qubes/xl-qvm-usb-attach.py +cp misc/xl-qvm-usb-detach.py /usr/lib/qubes/xl-qvm-usb-detach.py cp dom0/qvm-core/qubesutils.py /usr/lib64/python2.6/site-packages/qubes/qubesutils.py cp dom0/qvm-tools/qvm-usb /usr/bin/qvm-usb diff --git a/misc/xl-qvm-usb-detach.py b/misc/xl-qvm-usb-detach.py new file mode 100755 index 0000000..478d8bb --- /dev/null +++ b/misc/xl-qvm-usb-detach.py @@ -0,0 +1,49 @@ +#!/usr/bin/python + +## +## This script is for dom0 +## The syntax is modelled after "xl block-attach" +## FIXME: should be modelled after block-detach instead +## + +import sys +import os +import xen.lowlevel.xl + +# parse command line +if (len(sys.argv)<4) or (len(sys.argv)>5): + print 'usage: xl-qvm-usb-detach.py []' + sys.exit(1) + +frontendvm_xid=sys.argv[1] +backendvm_device=sys.argv[2] + +frontend=sys.argv[3].split('-') +if len(frontend)!=2: + print 'Error: frontendvm-device must be in - format' + sys.exit(1) +(controller, port)=frontend + +if len(sys.argv)>4: + backendvm_xid=int(sys.argv[4]) + backendvm_name=xen.lowlevel.xl.ctx().domid_to_name(backendvm_xid) +else: + backendvm_xid=0 + +cmd = "/usr/lib/qubes/vusb-ctl.py unbind '%s'" % backendvm_device +if backendvm_xid == 0: + os.system("sudo %s" % cmd) +else: + from qubes.qubes import QubesVmCollection + qvm_collection = QubesVmCollection() + qvm_collection.lock_db_for_reading() + qvm_collection.load() + qvm_collection.unlock_db() + + # launch + qvm_collection.get_vm_by_name(backendvm_name).run("root: %s" % cmd) + +# FIXME: command injection +os.system("xenstore-write /local/domain/%s/backend/vusb/%s/%s/port/%s ''" + % (backendvm_xid, frontendvm_xid, controller, port)) +