From f8f04f4b38242073f98943c2dc7bdacd6d900028 Mon Sep 17 00:00:00 2001 From: Alexandre Bezroutchko Date: Thu, 11 Oct 2012 01:08:49 +0200 Subject: [PATCH] dom0+vm/qvm-usb: intermediate --- README.pvusb | 3 +++ misc/vusb-ctl.py | 4 ++-- misc/xl-qvm-usb-attach.py | 33 +++++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.pvusb b/README.pvusb index 51b83eb..00e2bb6 100644 --- a/README.pvusb +++ b/README.pvusb @@ -25,6 +25,9 @@ In usbvm, after each reboot: In appvms, after each reboot: sudo ./install-pvusb-frontend.sh +In dom0, after each usbvm and appvm reboot (FIXME): + sudo initpv.py + Attach ~~~~~~ diff --git a/misc/vusb-ctl.py b/misc/vusb-ctl.py index d7e43c7..eae621c 100755 --- a/misc/vusb-ctl.py +++ b/misc/vusb-ctl.py @@ -16,9 +16,9 @@ if len(sys.argv)!=3: device=sys.argv[2] if sys.argv[1] == 'bind': vusb_util.bind_usb_device(device) -elif sys.argv[1] == 'ubind': +elif sys.argv[1] == 'unbind': vusb_util.unbind_usb_device(device) -else +else: print "Invalid command, must be 'bind' or 'unbind'" sys.exit(1) diff --git a/misc/xl-qvm-usb-attach.py b/misc/xl-qvm-usb-attach.py index dfa29a6..5eca16d 100755 --- a/misc/xl-qvm-usb-attach.py +++ b/misc/xl-qvm-usb-attach.py @@ -1,26 +1,39 @@ #!/usr/bin/python -from xen.util import vusb_util + +## +## This script is for dom0 +## The syntax is modelled after "xl block-attach" +## + import sys import os +import xen.lowlevel.xl -if len(sys.argv)!=5: - print 'usage: xl-qvm-usb-attach.py domain device frontend backend' + +# parse command line +if (len(sys.argv)<4) or (len(sys.argv)>5): + print 'usage: xl-qvm-usb-attach.py []' sys.exit(1) -domain=sys.argv[1] -device=sys.argv[2] +frontendvm_xid=sys.argv[1] +backendvm_device=sys.argv[2] frontend=sys.argv[3].split('-') if len(frontend)!=2: - print 'frontend in controller/port format' + print 'Error: frontendvm-device must be in - format' sys.exit(1) (controller, port)=frontend -backend=sys.argv[4] +backendvm_xid=0 +if len(sys.argv)>4: + backendvm_xid=sys.argv[4] + +# determine the name of the backend-vm +backendvm_name=xen.lowlevel.xl.ctx().domid_to_name(int(backendvm_xid)) # FIXME: command injection os.system("xenstore-write /local/domain/%s/backend/vusb/%s/%s/port/%s %s" - % (backend, domain, controller, port, device)) + % (backendvm_xid, frontendvm_xid, controller, port, backendvm_device)) -# FIXME: should this happen in the backend domain? -vusb_util.bind_usb_device(device) +# FIXME: vm.run +print "### qvm-run %s sudo /usr/lib/qubes/vusb-ctl.py unbind %s" % (backendvm_name, backendvm_device)