dom0+vm/qvm-usb: intermediate

This commit is contained in:
Alexandre Bezroutchko 2012-10-11 01:08:49 +02:00
parent 73d8922e25
commit db4d49b19c
4 changed files with 31 additions and 12 deletions

View File

@ -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 <backend-id> <frontend-id> <device-id>
Attach
~~~~~~

View File

@ -532,6 +532,9 @@ def usb_check_attached(backend_vm, device):
if dev == device:
frontend = "%s-%s" % (frontend_dev, port)
vm_name = xl_ctx.domid_to_name(int(vm))
if vm_name is None:
# FIXME: should we wipe references to frontends running on nonexistent VMs?
continue
attached_dev = {"xid":int(vm), "frontend": frontend, "devid": device, "vm": vm_name}
break
xs.transaction_end(xs_trans)

View File

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

View File

@ -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 <frontendvm-xid> <backendvm-device> <frontendvm-device> [<backendvm-xid>]'
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 <controller>-<port> 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)