diff options
| author | Simon Rettberg | 2025-03-27 14:12:49 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2025-03-27 14:12:49 +0100 |
| commit | 9a5f5e1f9ff51b59ea003c8f8cf8d43154454465 (patch) | |
| tree | dfa29bd893702ebd14651240818bd0f8918be601 | |
| parent | [run-virt] Conditionally pass through USB ethernet adapters (diff) | |
| download | mltk-9a5f5e1f9ff51b59ea003c8f8cf8d43154454465.tar.gz mltk-9a5f5e1f9ff51b59ea003c8f8cf8d43154454465.tar.xz mltk-9a5f5e1f9ff51b59ea003c8f8cf8d43154454465.zip | |
[qemu] Honor SLX_PASSTHROUGH_USB_ID for USB autoconnect on startup
4 files changed, 34 insertions, 6 deletions
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include index e578de88..22f954d0 100644 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include @@ -126,7 +126,7 @@ run_plugin() { # See if there are any USB devices connected that we want to pass through immediately # --spice-usbredir-redirect-on-connect="0x03,-1,-1,-1,0|-1,-1,-1,-1,1" - VIRTCMDOPTS+=( $( get_usb_devices '-usbredir -1,%VENDOR%,%PRODUCT%,-1,1' ) ) + VIRTCMDOPTS+=( $( get_usb_devices '--usbredir=-1,0x%VENDOR%,0x%PRODUCT%,-1,1' ) ) if [ "${SHARE_REMAP_MODE}" -gt 1 ]; then diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java index 7d660c9e..ac83d37b 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java @@ -99,7 +99,7 @@ public class App App.printUsage( cmdLn ); System.exit( 1 ); } - + if ( cmdLn.isDebugEnabled() || cmdLn.isDebugDevicePassthroughEnabled() ) { // Someone please exterminate all Java devs. What's wrong with those fuckheads who come up with this? // https://stackoverflow.com/a/65151249/2043481 @@ -279,7 +279,7 @@ public class App vmViewer = new ViewerVirtManager( vm, hypervisor ); } else { // create Virtual Viewer if debug mode is disabled - vmViewer = new ViewerVirtViewer( vm, hypervisor ); + vmViewer = new ViewerVirtViewer( vm, hypervisor, cmdLn.getUsbRedirDevices() ); } } diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java index a2aeef78..136640cb 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java @@ -468,6 +468,20 @@ public class CommandLineArgs return nvidiaPciIds; } + + public List<String> getUsbRedirDevices() + { + final String[] usbRaw = this.getArguments( CmdLnOption.USBREDIR ); + final ArrayList<String> retval; + + if ( usbRaw == null || usbRaw.length <= 0 ) { + retval = new ArrayList<String>(); + } else { + retval = new ArrayList<String>( Arrays.asList( usbRaw ) ); + } + + return retval; + } /** * Returns the state whether a passthrough of a NVIDIA GPU is requested. @@ -543,6 +557,7 @@ public class CommandLineArgs + " Each group can contain commas or dashes to mark ranges. E.g. 0,1;2-3;4;5;6;7;8,9,10,11" ), MANAGER ( '2', "manager", 0, "Force using virt-manager even if not in debug mode" ), VALIDATE ( '3', "validate", 0, "Validate input file only, exit immediately with exit code 0 on success, 42 otherwise" ), + USBREDIR ( '4', "usbredir", 1, "Add USB auto-redirect option to virt-viewer call. Can be passed multiple times." ), VM_MAC0 ( 'a', "vmmac0", 1, "MAC address for the first network interface" ), DEBUG ( 'b', "debug", 1, "Enable or disable debug mode" ), VM_NCPUS ( 'c', "vmncpus", 1, "Number of virtual CPUs for the virtual machine" ), diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/viewer/ViewerVirtViewer.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/viewer/ViewerVirtViewer.java index d696e109..876f5f2e 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/viewer/ViewerVirtViewer.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/viewer/ViewerVirtViewer.java @@ -1,8 +1,12 @@ package org.openslx.runvirt.viewer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.logging.log4j.util.Strings; import org.openslx.runvirt.virtualization.LibvirtHypervisor; import org.openslx.runvirt.virtualization.LibvirtHypervisorException; import org.openslx.runvirt.virtualization.LibvirtVirtualMachine; @@ -26,15 +30,19 @@ public class ViewerVirtViewer extends Viewer */ private final static int NUM_SUPPORTED_DISPLAYS = Integer.MAX_VALUE; + private final List<String> usbAutoconnect; + /** * Creates a new Virtual Viewer for a Libvirt virtual machine running on a Libvirt hypervisor. * * @param machine virtual machine to display. * @param hypervisor remote (hypervisor) endpoint for the viewer to connect to. + * @param usbRedirOptions list of usb redir autoconnect rules */ - public ViewerVirtViewer( LibvirtVirtualMachine machine, LibvirtHypervisor hypervisor ) + public ViewerVirtViewer( LibvirtVirtualMachine machine, LibvirtHypervisor hypervisor, List<String> usbRedirOptions ) { super( ViewerVirtViewer.NAME, ViewerVirtViewer.NUM_SUPPORTED_DISPLAYS, machine, hypervisor ); + this.usbAutoconnect = usbRedirOptions; } @Override @@ -88,10 +96,15 @@ public class ViewerVirtViewer extends Viewer throw new ViewerException( "The URI of the hypervisor backend or the UUID of the machine to display is missing!" ); } + ArrayList<String> args = new ArrayList<String>(); + if ( !this.usbAutoconnect.isEmpty() ) { + args.add( "--spice-usbredir-redirect-on-connect=" + Strings.join( this.usbAutoconnect, '|' ) ); + } + args.addAll( Arrays.asList( new String[] { "--full-screen", "--wait", + "--attach", "--connect=" + connectionUri, "--uuid", "--", machineUuid } ) ); // execute viewer process with arguments: // "virt-viewer --full-screen --wait --attach --connect=<URI> --domain-name -- <DOMAIN-UUID>" - ViewerUtils.executeViewer( ViewerVirtViewer.NAME, new String[] { "--full-screen", "--wait", - "--attach", "--connect=" + connectionUri, "--uuid", "--", machineUuid } ); + ViewerUtils.executeViewer( ViewerVirtViewer.NAME, args.toArray( new String[ args.size() ] ) ); } } |
