From 1a4dbdacff6f3489495043b38e8a70ada0244f01 Mon Sep 17 00:00:00 2001 From: Alexandre Bezroutchko Date: Tue, 9 Oct 2012 23:16:32 +0200 Subject: [PATCH] dvp/qvm-usb: implemented usb_check_attached method, now "qvm-usb -l" indicate attachments --- misc/xl-qvm-usb-attach.py | 25 ++++++++++ test/pvusb-003-list-attach-use-detach | 67 +++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100755 misc/xl-qvm-usb-attach.py create mode 100755 test/pvusb-003-list-attach-use-detach diff --git a/misc/xl-qvm-usb-attach.py b/misc/xl-qvm-usb-attach.py new file mode 100755 index 0000000..3f58713 --- /dev/null +++ b/misc/xl-qvm-usb-attach.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +from xen.util import vusb_util +import sys +import os + +if len(sys.argv)!=5: + print 'usage: xl-qvm-usb-attach.py domain device frontend backend' + sys.exit(1) + +domain=sys.argv[1] +device=sys.argv[2] + +frontend=sys.argv[3].split('-') +if len(frontend)!=2: + print 'frontend in controller/port format' + sys.exit(1) +(controller, port)=frontend + +backend=sys.argv[4] + +# FIXME command injection +os.system("xenstore-write /local/domain/%s/backend/vusb/%s/%s/port/%s %s" + % (backend, domain, controller, port, device)) + +vusb_util.bind_usb_device(device) diff --git a/test/pvusb-003-list-attach-use-detach b/test/pvusb-003-list-attach-use-detach new file mode 100755 index 0000000..929e34c --- /dev/null +++ b/test/pvusb-003-list-attach-use-detach @@ -0,0 +1,67 @@ +#!/bin/sh + +tmpf=`mktemp` +domu='qdvp' + +## === List +echo 'qvm-usb -l' +qvm-usb -l | sort > $tmpf + +cat <<'END' | diff -u - $tmpf +dom0:2-1 046a:0021 046a_0021 +dom0:2-2 045e:0745 Microsoft_Microsoft®_Nano_Transceiver_v1.0 +dom0:7-1 07d1:3c0a Ralink_11n_Adapter_1.0 +dom0:7-5 0781:5530 SanDisk_Cruzer_1942531DB09038A6 +END + +## === Attach +echo 'qvm-usb -a' +qvm-usb -a $domu dom0:7-5 | diff -u /dev/null - +#echo 'pvusb-script/usb-attach.py' +#sudo /home/abb/pvusb-scripts/usb-attach.py 7-5 3 1 + +## === List again +echo 'qvm-usb -l' +qvm-usb -l | sort > $tmpf + +# FIXME +cat <<'END' | diff -u - $tmpf +dom0:2-1 046a:0021 046a_0021 +dom0:2-2 045e:0745 Microsoft_Microsoft®_Nano_Transceiver_v1.0 +dom0:7-1 07d1:3c0a Ralink_11n_Adapter_1.0 +dom0:7-5 0781:5530 SanDisk_Cruzer_1942531DB09038A6 +END + +read -p 'Press ENTER to continue' + +## === Use: try ls +echo 'qvm-run $domu ls /dev/sda' +qvm-run -p $domu 'ls /dev/sda' > $tmpf +cat <<'END' | diff -u - $tmpf +/dev/sda +END + +## === Use: try fdisk +echo 'qvm-run $domu fdisk' +qvm-run -p $domu 'su - root -c "fdisk -l /dev/sda"' > $tmpf + +cat <<'END' | diff -u - $tmpf + +Disk /dev/sda: 4022 MB, 4022337024 bytes +124 heads, 62 sectors/track, 1021 cylinders, total 7856127 sectors +Units = sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 512 bytes +I/O size (minimum/optimal): 512 bytes / 512 bytes +Disk identifier: 0x3963a77b + + Device Boot Start End Blocks Id System +/dev/sda1 * 62 7849447 3924693 c W95 FAT32 (LBA) +END + +## === Detach +#echo 'qvm-usb -d' +#qvm-usb -d $domu:7-5 | diff -u /dev/null - +echo 'pvusb-script/usb-detach.py' +sudo /home/abb/pvusb-scripts/usb-detach.py 7-5 4 1 + +rm $tmpf