dvp/qvm-usb: implemented usb_check_attached method, now "qvm-usb -l" indicate attachments

This commit is contained in:
Alexandre Bezroutchko 2012-10-09 23:16:32 +02:00
parent de10323742
commit 1a4dbdacff
2 changed files with 92 additions and 0 deletions

25
misc/xl-qvm-usb-attach.py Executable file
View File

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

View File

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