diff options
author | Simon Rettberg | 2016-02-24 11:53:16 +0100 |
---|---|---|
committer | Simon Rettberg | 2016-02-24 11:53:16 +0100 |
commit | c09edd06d2db7a787c0c35b879b6bc1eeea424d5 (patch) | |
tree | b416e72a6ae6155cf1ec3b8d372d95f7ef75b619 /remote | |
parent | Merge branch 'master' of git://git.openslx.org/openslx-ng/tm-scripts (diff) | |
download | tm-scripts-c09edd06d2db7a787c0c35b879b6bc1eeea424d5.tar.gz tm-scripts-c09edd06d2db7a787c0c35b879b6bc1eeea424d5.tar.xz tm-scripts-c09edd06d2db7a787c0c35b879b6bc1eeea424d5.zip |
[run-virt/vmware] Scan for usb devices that we should pass through before starting vm
Diffstat (limited to 'remote')
6 files changed, 101 insertions, 2 deletions
diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/usb_detector.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/usb_detector.inc new file mode 100644 index 00000000..43a75b2a --- /dev/null +++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/usb_detector.inc @@ -0,0 +1,77 @@ +# Helper function that will scan /dev/bus/usb for devices matching specific classes +# and then output the corresponding device ids. This can be used for selective +# handover of devices to a virtual machine + +declare -rg PASSTHROUGH_USB_DEVICES="2 0:5 0:6 0:7 0:14 0:16 0:17" + +# $1: expression to fill with device information. +# valid placeholders are: +# %VENDOR% - device vendor id +# %PRODUCT% - device product id +# $2-n: device classes to include in output +get_usb_devices_int() { + [ -z "$TMPDIR" ] && TMPDIR="/tmp" + local EXP=$1 + shift + if [ -z "$EXP" ]; then + writelog "No ouput expression template passed to get_usb_devices" + cleanexit 1 + fi + if [ $# -eq 0 ]; then + writelog "No device classes given to get_usb_devices" + cleanexit 1 + fi + local MATCH=';' + while [ $# -gt 0 ]; do + MATCH+="$1;" + [[ "$1" != *:* ]] && MATCH+="0:$1;" + shift + done + local dev= + local key value trailing + trailing= + local tmp="${TMPDIR}/lsusb.$$.$RANDOM" + for dev in /dev/bus/usb/*/*; do + if ! lsusb -D "$dev" > "$tmp" 2>/dev/null; then + writelog "Cannot lsusb $dev" + continue + fi + local DC= + local OK= + local VENDOR= + local PRODUCT= + while read -r key value trailing || [ -n "$key" ]; do + if [[ "$key" == "idVendor" ]]; then + [[ "$value" == 0x* ]] && VENDOR="${value:2}" + elif [[ "$key" == "idProduct" ]]; then + [[ "$value" == 0x* ]] && PRODUCT="${value:2}" + elif [ -z "$DC" ]; then + # No bDeviceClass seen yet + if [[ "$key" == "bDeviceClass" ]]; then + DC="$value" + [[ "$MATCH" == *";${DC};"* ]] && OK=yo + fi + else + # #DeviceClass is generic, look at sub class + if [[ "$key" == "bInterfaceClass" ]]; then + [[ "$MATCH" == *";${DC}:${value};"* ]] && OK=yo + fi + fi + if [ -n "$OK" -a -n "$VENDOR" -a -n "$PRODUCT" ]; then + echo "$EXP" | sed "s/%VENDOR%/${VENDOR}/g;s/%PRODUCT%/${PRODUCT}/g" + break + fi + done < "$tmp" + done + rm -f -- "$tmp" +} + +get_usb_devices() { + if which lsusb 2>/dev/null >&2 && lsusb --help 2>&1 | grep -q -- '-D' 2>/dev/null; then + [ $# -eq 1 ] && set -- "$1" $PASSTHROUGH_USB_DEVICES # no quotes here! + get_usb_devices_int "$@" | sort -u + else + writelog "Cannot scan usb bus: lsusb not found or doesn't support -D" + fi +} + diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt b/remote/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt index 8e1bbd0d..1e591389 100755 --- a/remote/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt +++ b/remote/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt @@ -28,6 +28,8 @@ source ${RUNVIRTINCLUDEDIR}/vmchooser_runvirt_functions.inc && trap 'trap "" SIG source ${RUNVIRTINCLUDEDIR}/set_runvirt_variables.inc # Function to detect whether we can use the new way (vmx via http) or the old way (legacy): source ${RUNVIRTINCLUDEDIR}/detect_legacy.inc # This yields LEGACY, IMGUUID, IMGVMX +# For scanning for certain usb classes +source "${RUNVIRTINCLUDEDIR}/usb_detector.inc" if [ "$LEGACY" ]; then # check for important files used (filecheck()) - vestigial? diff --git a/remote/modules/run-virt/module.build b/remote/modules/run-virt/module.build index ccb7c4e1..26762bca 100644 --- a/remote/modules/run-virt/module.build +++ b/remote/modules/run-virt/module.build @@ -4,7 +4,10 @@ fetch_source () { } build () { - : + local COPYLIST="list_dpkg_output" + rm -f -- "$COPYLIST" + list_packet_files > "$COPYLIST" + tarcopy "$(cat "$COPYLIST" | sort -u)" "${MODULE_BUILD_DIR}" } post_copy() { diff --git a/remote/modules/run-virt/module.conf b/remote/modules/run-virt/module.conf index 6778a258..bd24ba58 100644 --- a/remote/modules/run-virt/module.conf +++ b/remote/modules/run-virt/module.conf @@ -1 +1,4 @@ -# (void) +REQUIRED_BINARIES=" + lsusb +" + diff --git a/remote/modules/run-virt/module.conf.ubuntu b/remote/modules/run-virt/module.conf.ubuntu new file mode 100644 index 00000000..b285210b --- /dev/null +++ b/remote/modules/run-virt/module.conf.ubuntu @@ -0,0 +1,7 @@ +REQUIRED_INSTALLED_PACKAGES=" + usbutils +" +REQUIRED_CONTENT_PACKAGES=" + usbutils +" + diff --git a/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/run-virt.include b/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/run-virt.include index 5c76a180..e25947e0 100644 --- a/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/run-virt.include +++ b/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/run-virt.include @@ -60,6 +60,13 @@ if [ -n "$HWVER" ] && [ "$HWVER" -gt "$maxhardwareversion" ]; then sed -i 's/^virtualHW\.version.*$/virtualHW.version = "'$maxhardwareversion'"/I' "$conffile" fi +# See if there are any USB devices connected that we want to pass through immediately +get_usb_devices 'usb.autoConnect.deviceXXXXX = "0x%VENDOR%:0x%PRODUCT%"' \ + | sed -r 's/0x0+/0x/g' \ + | awk '{sub(/XXXXX/,NR-1)}1' \ + >> "$conffile" + + # For debugging cp "$conffile" "/tmp/vmware-last-config" |