diff options
author | Jonathan Bauer | 2018-04-13 18:13:25 +0200 |
---|---|---|
committer | Jonathan Bauer | 2018-04-13 18:13:25 +0200 |
commit | 0ed5e3423df24d5edac94288538033b7763f6dbc (patch) | |
tree | 6c2830b01ebccfb9ab1309881732c08a9f8de514 | |
parent | [run-virt] error msg for missing plugin dir (diff) | |
download | mltk-0ed5e3423df24d5edac94288538033b7763f6dbc.tar.gz mltk-0ed5e3423df24d5edac94288538033b7763f6dbc.tar.xz mltk-0ed5e3423df24d5edac94288538033b7763f6dbc.zip |
[vbox-src] more vbox plugin fixes
* use HW_CORES from /run/hwinfo
* add usb attach script [WIP]
* udev rule to trigger attach script when usb is connected
* edit_attr -> set_attr now always creating missing nodes/attributes
...and prolly more I cant think of now ...
6 files changed, 142 insertions, 47 deletions
diff --git a/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env b/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env index 1bd0db58..6c7136c5 100755 --- a/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env +++ b/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env @@ -103,28 +103,9 @@ MEM_SWAPCACHED=$(grep -i "^swapcached:" /proc/meminfo | awk '{print $2}') MEM_TOTAL="$(expr $(expr $MEM_FREE + $MEM_CACHED + $MEM_SWAPCACHED) / 1024)" echo "HOST_MEM_TOTAL=${MEM_TOTAL}" > "${VMCHOOSER_VIRT_CONF}" -# determine number of cpu cores -CPU_CORES=$(grep '^processor.*:' /proc/cpuinfo | wc -l) -if [ "${CPU_CORES}" -gt "1" 2>/dev/null ]; then - echo "CPU_CORES=${CPU_CORES}" >> "${VMCHOOSER_VIRT_CONF}" -else - echo 'CPU_CORES=1' >> "${VMCHOOSER_VIRT_CONF}" -fi - # general machine architecture (32/64bit) echo "HOST_ARCH=$(uname -m)" >> "${VMCHOOSER_VIRT_CONF}" -# check for VT enabled CPU -if grep -q '^flags.*\<vmx\>' "/proc/cpuinfo"; then - echo "VTFLAG=1" >> "${VMCHOOSER_VIRT_CONF}" - echo 'KVM_MODULE="kvm_intel"' >> "${VMCHOOSER_VIRT_CONF}" - elif grep -q '^flags.*\<svm\>' "/proc/cpuinfo"; then - echo "VTFLAG=1" >> "${VMCHOOSER_VIRT_CONF}" - echo 'KVM_MODULE="kvm_amd"' >> "${VMCHOOSER_VIRT_CONF}" - else - echo "VTFLAG=0" >> "${VMCHOOSER_VIRT_CONF}" -fi - # generated mac address parts from the host's mac address if [ -n "$SLX_PXE_MAC" ]; then HOSTMACADDR="${SLX_PXE_MAC}" @@ -175,6 +156,7 @@ done # Serial ports echo "SERIAL_PORTS='$(dmesg | grep -Eo 'ttyS[0-9]+' | sed 's,^,/dev/,' | tr '\n' ' ')'" >> "${VMCHOOSER_VIRT_CONF}" + # Parallel ports modprobe parport_pc diff --git a/core/modules/vbox-src/data/etc/udev/rules.d/85-vbox-usb.rules b/core/modules/vbox-src/data/etc/udev/rules.d/85-vbox-usb.rules new file mode 100644 index 00000000..e79667f4 --- /dev/null +++ b/core/modules/vbox-src/data/etc/udev/rules.d/85-vbox-usb.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="usb_device", ACTION=="add", ENV{PATH}="/usr/bin:/bin:/usr/sbin:/sbin:/opt/openslx/bin:/opt/openslx/sbin", RUN+="/opt/openslx/bin/attach-usb-to-vbox $attr{serial} $attr{idVendor}" +SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", ENV{PATH}="/usr/bin:/bin:/usr/sbin:/sbin:/opt/openslx/bin:/opt/openslx/sbin", RUN+="/opt/openslx/bin/attach-usb-to-vbox $attr{serial} $attr{idVendor}" diff --git a/core/modules/vbox-src/data/opt/openslx/bin/attach-usb-to-vbox b/core/modules/vbox-src/data/opt/openslx/bin/attach-usb-to-vbox new file mode 100755 index 00000000..46452f91 --- /dev/null +++ b/core/modules/vbox-src/data/opt/openslx/bin/attach-usb-to-vbox @@ -0,0 +1,63 @@ +#!/bin/bash + +# OBJECTIVES +# udev rules to detect usb type etc. +# figuring out the bus thing. + +# check that udev gave us a serial number to work with +udev_serial="$1" +if [ -z "$udev_serial" ]; then + logger "$0: Did not receive serial from udev" + exit 1 +fi +logger "udev_serial: $udev_serial" + +udev_vendorid="$2" +if [ -z "$udev_vendorid" ]; then + logger "$0: Did not receive vendorid from udev" + exit 1 +fi +logger "udev_vendorid: $udev_vendorid" + +user=$(ps auxf | grep /usr/lib/virtualbox/VirtualBox | grep -v grep | awk '{print $1}') +if [ -z "$user" ]; then + logger "$0: could not determine user" + exit 1 +fi + +# find UUID of running VM +vmuuid=$(su -c "/usr/lib/virtualbox/VBoxManage list runningvms | sed -r 's,^\"[^\{]+\{([a-z0-9\-]+)\}$,\1,g'" "$user") +if [ -z "$vmuuid" ]; then + logger "Failed to find running VirtualBox VM" + exit 1 +fi +logger "vmuuid: $vmuuid" + +devname="/dev/vboxusb/$BUSNUM/$DEVNUM" +for tts in 1 1 2 3 5 5 STOP; do + if [ "x$tts" = "xSTOP" ]; then + logger "$0: Could not find '$devname' as expected..." + exit 1 + fi + [ -e "$devname" ] && break + echo "waiting for $devname..." + sleep $tts +done + +usblistgrep=$(su -c "/usr/lib/virtualbox/VBoxManage list usbhost" "$user") +logger "USB list: $usblistgrep" + +usbaddress=$(su -c "/usr/lib/virtualbox/VBoxManage list usbhost | grep -A1 -E 'SerialNumber:\s*'"$1" | awk '/Address:/ {print \$2}'" "$user") +logger "USB address: $usbaddress" + +logger "Trying to attach...." +for tries in 1 2 3 4 5 6 7 8 9 10 STOP; do + if [ "$tries" = "STOP" ]; then + logger "$0: Failed to attach usb after 5 tries" + exit + fi + if su -c '/usr/lib/virtualbox/VBoxManage controlvm '"$vmuuid"' usbattach '"$usbaddress"'' "$user"; then + exit 0 + fi + sleep 1 +done diff --git a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/finalize_machine_config.inc b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/finalize_machine_config.inc index c5704f8c..ab9cd643 100755 --- a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/finalize_machine_config.inc +++ b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/finalize_machine_config.inc @@ -31,14 +31,6 @@ finalize_machine_config() { sed -i 's,%OpenSLX_CPU%,'"${CPU_CORES}"',g' $TMPCONFIG sed -i 's,%OpenSLX_MEMORY%,'"${VM_MEM}"',g' $TMPCONFIG - # Add a node for the SharedFolder - add_node "/VirtualBox/Machine/Hardware" "SharedFolders" - add_node \ - "/VirtualBox/Machine/Hardware/SharedFolders" "SharedFolder" \ - "name=${HOME_SHARE_NAME}" \ - "hostPath=${HOME_SHARE_PATH}" \ - "writable=true" \ - "autoMount=true" # Add a HardDisk node for the snapshot add_node \ "/VirtualBox/Machine/MediaRegistry/HardDisks/HardDisk" "HardDisk" \ @@ -46,6 +38,7 @@ finalize_machine_config() { "location=$VBOX_SNAPSHOT_DIR/{${SNAPSHOT_UUID}}.vdi" \ "format=VDI" \ "type=Normal" + # add storage controller and 2 floppies to it add_node \ "/VirtualBox/Machine/StorageControllers" "StorageController" \ @@ -71,20 +64,54 @@ finalize_machine_config() { '/VirtualBox/Machine/StorageControllers/StorageController/AttachedDevice[@device="1"]' "Image" \ "uuid={${SLX_FLOPPY_UUID}}" - # set Virtual Memory value - edit_attr "/VirtualBox/Machine/Hardware/Display" "VRAMSize" "${GUESTVRAM}" - edit_attr --create "/VirtualBox/Machine/Hardware/Display" "accelerate2DVideo" "true" + + # Add a node for the SharedFolder + add_node "/VirtualBox/Machine/Hardware" "SharedFolders" + if [ -n "${HOME_SHARE_NAME}" -a -n "${HOME_SHARE_PATH}" -a -d "${HOME_SHARE_PATH}" ]; then + add_node \ + "/VirtualBox/Machine/Hardware/SharedFolders" "SharedFolder" \ + "name=${HOME_SHARE_NAME}" \ + "hostPath=${HOME_SHARE_PATH}" \ + "writable=true" \ + "autoMount=true" + fi # set the MAC address - edit_attr "/VirtualBox/Machine/Hardware/Network/Adapter" "MACAddress" "${VM_VDE_MAC_ADDR}" + set_attr "/VirtualBox/Machine/Hardware/Network/Adapter" "MACAddress" "${VM_VDE_MAC_ADDR}" # check if KVM is available and activate it if so if source /run/hwinfo && [ "${HW_KVM}" = "ENABLED" ]; then - edit_attr --create "/VirtualBox/Machine/Hardware/Paravirt" "provider" "KVM" + set_attr "/VirtualBox/Machine/Hardware/Paravirt" "provider" "KVM" fi + # activate IOAPIC needed for multi core (?) if [ $CPU_CORES -gt 1 ]; then - edit_attr --create "/VirtualBox/Machine/Hardware/BIOS/IOAPIC" "enabled" "true" + set_attr "/VirtualBox/Machine/Hardware/BIOS/IOAPIC" "enabled" "true" + fi + + # PAE support? + local PAE_SUPPORT="$(grep -oE '\s+pae\s+' /proc/cpuinfo)" + local PAE_ENABLE="true" + [ -z "$PAE_SUPPORT" ] && PAE_ENABLE="false" + set_attr "/VirtualBox/Machine/Hardware/CPU/PAE" "enabled" "${PAE_ENABLE}" + + # LongMode? + local LM_SUPPORT="$(grep -oE '\s+lm\s+' /proc/cpuinfo)" + local LM_ENABLE="true" + [ -z "$LM_SUPPORT" ] && LM_ENABLE="false" + set_attr "/VirtualBox/Machine/Hardware/CPU/LongMode" "enabled" "${LM_ENABLE}" + + # Page size extensions? + local PSE_SUPPORT="$(grep -oE '\s+pse\s+' /proc/cpuinfo)" + local PSE_ENABLE="true" + [ -z "$PSE_SUPPORT" ] && PSE_ENABLE="false" + set_attr "/VirtualBox/Machine/Hardware/CPU/HardwareVirtExLargePages" "enabled" "${PSE_ENABLE}" + + # EXPERIMENTAL: check for USB 3 support + local XHCI_OK="$(lsusb -t | grep xhci)" + if [ -n "$XHCI_OK" ]; then + del_node "/VirtualBox/Machine/Hardware/USB" + add_node "/VirtualBox/Machine/Hardware/USB/Controllers" "Controller" "name=xHCI" "type=XHCI" fi cp $TMPCONFIG /tmp/vbox-last-config diff --git a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/guest_hardware_limits.inc b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/guest_hardware_limits.inc index ec720551..def5280c 100755 --- a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/guest_hardware_limits.inc +++ b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/guest_hardware_limits.inc @@ -110,8 +110,14 @@ set_hardware_limits() { declare -rg GUESTVRAM=$MAXVRAM + # check /run/hwinfo for CORE not THREADS + # vbox seems to only want maximum cores = number of + # physical cores of the cpu, so use that + if [ -e /run/hwinfo ]; then + . /run/hwinfo + notempty HW_CORES && CPU_CORES="$HW_CORES" + fi [ "${CPU_CORES}" -gt "{MAXCORES}" ] && CPU_CORES="${MAXCORES}" - [ "${VM_MEM}" -gt "${MAXMEM}" ] && VM_MEM="${MAXMEM}" return 0 diff --git a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/init_core.inc b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/init_core.inc index d30a0408..a1da3016 100755 --- a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/init_core.inc +++ b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/init_core.inc @@ -47,26 +47,32 @@ add_node() { ${ATTRS_OPTS} \ "${TMPCONFIG}" } -# edit_attr [--create] <node_xpath> <attr=value> -# --create would create the node if it does not exist -edit_attr() { - local CREATE= - if [ "$1" = "--create" ]; then - CREATE=yo - shift - fi +# set_attr <node_xpath> <attr> <value> +set_attr() { if [ $# -ne 3 ]; then writelog "${FUNCNAME[0]} requires 3 args, $# given." cleanexit 1 fi - if notempty CREATE && ! node_exists "$1"; then + if ! node_exists "$1"; then + writelog "Node $1 missing" add_node "${1%/*}" "${1##*/}" \ "$2=$3" else - xmlstarlet ed -L -N x="${VBOX_NAMESPACE}" \ - -u "$(print_namespaced "x" "$1")/@$2" \ - -v "$3" \ - "${TMPCONFIG}" + if ! attr_exists "$1" "$2"; then + writelog "Attr $2 of $1 missing" + xmlstarlet ed -L -N x="${VBOX_NAMESPACE}" \ + -i "$(print_namespaced "x" "$1")" \ + -t attr -n "$2" -v "$3" \ + "${TMPCONFIG}" + writelog "Returned with $?" + else + writelog "Attr $2 exists" + xmlstarlet ed -L -N x="${VBOX_NAMESPACE}" \ + -u "$(print_namespaced "x" "$1")/@$2" \ + -v "$3" \ + "${TMPCONFIG}" + writelog "Returned with $?" + fi fi } del_node() { @@ -78,6 +84,15 @@ del_node() { -d "$(print_namespaced "x" "$1")" \ "${TMPCONFIG}" } +attr_exists() { + if [ $# -ne 2 ]; then + writelog "${FUNCNAME[0]} requires node and attribute as args, $# given." + cleanexit 1 + fi + xmlstarlet -q sel -N x="${VBOX_NAMESPACE}" \ + -t -v "$(print_namespaced "x" "$1")/@$2" \ + "${TMPCONFIG}" +} node_exists() { if [ $# -ne 1 ]; then writelog "${FUNCNAME[0]} requires one arg, $# given." |