From d2d583884720e01dbda46fbc853b70ab665bfbd3 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 4 Apr 2022 08:17:32 +0200 Subject: [qemu] Add device passthrough debug mode --- .../vmchooser/plugins/qemukvm/run-virt.include | 4 ++ .../java/org/openslx/runvirt/plugin/qemu/App.java | 2 +- .../runvirt/plugin/qemu/cmdln/CommandLineArgs.java | 12 ++++ ...sformationSpecificQemuGpuPassthroughNvidia.java | 8 ++- ...sformationSpecificQemuMdevPassthroughIntel.java | 8 ++- .../org/openslx/runvirt/plugin/qemu/AppTest.java | 8 +-- .../plugin/qemu/cmdln/CommandLineArgsTest.java | 64 ++++++++++++++++++++++ 7 files changed, 95 insertions(+), 11 deletions(-) (limited to 'core/modules/qemu') 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 3e0aa68c..678ce7af 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 @@ -73,11 +73,15 @@ run_plugin() { gsettings set "${GSETTINGS_SCHEMA_NAME_PREFIX}.vm:${GSETTINGS_SCHEMA_PATH_PREFIX}/vm/" "resize-guest" "1" fi + # set device passthrough debug mode + debug_pth="false" + # call the Libvirt Java tool to finalize configuration and start VM declare -rg VIRTCMD="java" VIRTCMDOPTS=( "-jar" "${QEMU_PLUGIN_DIR}/runvirt-plugin-qemu.jar" ) notempty DEBUG && VIRTCMDOPTS+=( "-debug" "${DEBUG}" ) + notempty debug_pth && VIRTCMDOPTS+=( "-debugpth" "${debug_pth}" ) notempty firmware_path && VIRTCMDOPTS+=( "-firmware" "${firmware_path}" ) notempty VM_CLEANNAME && VIRTCMDOPTS+=( "-vmname" "${VM_CLEANNAME}" ) notempty VM_DISPLAYNAME && VIRTCMDOPTS+=( "-vmdsplname" "${VM_DISPLAYNAME}" ) 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 3457f224..0a2af04a 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 @@ -199,7 +199,7 @@ public class App // create specific viewer to display Libvirt VM final Viewer vmViewer; - if ( cmdLn.isNvidiaGpuPassthroughEnabled() ) { + if ( cmdLn.isNvidiaGpuPassthroughEnabled() && !cmdLn.isDebugDevicePassthroughEnabled() ) { // viewer for GPU passthrough (framebuffer access) is required vmViewer = new ViewerLookingGlassClient( vm, hypervisor, cmdLn.isDebugEnabled() ); } else { 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 49825813..d0fb3068 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 @@ -160,6 +160,17 @@ public class CommandLineArgs return ( "true".equals( debugArg ) ) ? true : false; } + /** + * Returns the state of the command line option {@link CmdLnOption#DEBUG_PTH}. + * + * @return state of the command line option {@link CmdLnOption#DEBUG_PTH}. + */ + public boolean isDebugDevicePassthroughEnabled() + { + final String debugArg = this.getArgument( CmdLnOption.DEBUG_PTH ); + return ( "true".equals( debugArg ) ) ? true : false; + } + /** * Returns the argument of the command line option {@link CmdLnOption#FIRMWARE}. * @@ -437,6 +448,7 @@ public class CommandLineArgs // @formatter:off HELP ( 'h', "help", 0, "" ), DEBUG ( 'b', "debug", 1, "Enable or disable debug mode" ), + DEBUG_PTH ( 'j', "debugpth", 1, "Enable or disable device passthrough debug mode" ), FIRMWARE ( 'x', "firmware", 1, "Path to QEMU firmware specifications directory" ), VM_CFGINP ( 'i', "vmcfginp", 1, "File name of an existing and filtered Libvirt domain XML configuration file" ), VM_CFGOUT ( 'o', "vmcfgout", 1, "File name to output a finalized Libvirt domain XML configuration file" ), diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuGpuPassthroughNvidia.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuGpuPassthroughNvidia.java index 788c2fd1..e06c4419 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuGpuPassthroughNvidia.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuGpuPassthroughNvidia.java @@ -233,9 +233,11 @@ public class TransformationSpecificQemuGpuPassthroughNvidia config.setFeatureKvmHiddenState( true ); } - // disable all software video devices by disable them - for ( Video videoDevice : config.getVideoDevices() ) { - videoDevice.disable(); + // disable all software video devices if device passthrough debug mode is not enabled + if ( !args.isDebugDevicePassthroughEnabled() ) { + for ( Video videoDevice : config.getVideoDevices() ) { + videoDevice.disable(); + } } // force SPICE graphics to listen on local address for looking-glass-client diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuMdevPassthroughIntel.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuMdevPassthroughIntel.java index 89266b97..1550a233 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuMdevPassthroughIntel.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationSpecificQemuMdevPassthroughIntel.java @@ -128,9 +128,11 @@ public class TransformationSpecificQemuMdevPassthroughIntel config.addQemuCmdlnArgument( "device.hostdev0.romfile=" + INTEL_GVT_G_UEFI_ROMFILE ); } - // disable all software video devices by disable them - for ( Video videoDevice : config.getVideoDevices() ) { - videoDevice.disable(); + // disable all software video devices if device passthrough debug mode is not enabled + if ( !args.isDebugDevicePassthroughEnabled() ) { + for ( Video videoDevice : config.getVideoDevices() ) { + videoDevice.disable(); + } } // enable OpenGL on all SPICE graphics devices diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java index 1a24174a..21185b07 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java @@ -63,7 +63,7 @@ public class AppTest assertTrue( shortHelpOptionCorrectOutput.contains( App.APP_DESC ) ); // test that no error was logged and output is available - assertEquals( 2740, shortHelpOptionCorrectOutput.length() ); + assertEquals( 2826, shortHelpOptionCorrectOutput.length() ); assertEquals( 0, shortHelpOptionCorrectErrOutput.length() ); } @@ -91,7 +91,7 @@ public class AppTest assertTrue( longHelpOptionCorrectOutput.contains( App.APP_DESC ) ); // test that no error was logged and output is available - assertEquals( 2740, longHelpOptionCorrectOutput.length() ); + assertEquals( 2826, longHelpOptionCorrectOutput.length() ); assertEquals( 0, longHelpOptionCorrectErrOutput.length() ); } @@ -119,7 +119,7 @@ public class AppTest assertTrue( shortHelpOptionIncorrectOutput.contains( App.APP_DESC ) ); // test that error was logged and output is available - assertEquals( 2740, shortHelpOptionIncorrectOutput.length() ); + assertEquals( 2826, shortHelpOptionIncorrectOutput.length() ); assertEquals( 0, shortHelpOptionIncorrectErrOutput.length() ); } @@ -147,7 +147,7 @@ public class AppTest assertTrue( longHelpOptionIncorrectOutput.contains( App.APP_DESC ) ); // test that error was logged and output is available - assertEquals( 2740, longHelpOptionIncorrectOutput.length() ); + assertEquals( 2826, longHelpOptionIncorrectOutput.length() ); assertEquals( 0, longHelpOptionIncorrectErrOutput.length() ); } diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java index b61e41d9..c968da24 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java @@ -141,6 +141,70 @@ public class CommandLineArgsTest assertFalse( cmdLnDebugMissing.isDebugEnabled() ); } + @Test + @DisplayName( "Test the parsing of the enabled debug device passthrough command line option (short version)" ) + public void testCmdlnOptionDebugDevicePassthroughEnabledShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.DEBUG_PTH.getShortOption(), + CMDLN_TEST_DEBUG_ON + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertTrue( cmdLn.isDebugDevicePassthroughEnabled() ); + } + + @Test + @DisplayName( "Test the parsing of the enabled debug device passthrough command line option (long version)" ) + public void testCmdlnOptionDebugDevicePassthroughEnabledLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.DEBUG_PTH.getLongOption(), + CMDLN_TEST_DEBUG_ON + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertTrue( cmdLn.isDebugDevicePassthroughEnabled() ); + } + + @Test + @DisplayName( "Test the parsing of the disabled debug device passthrough command line option (short version)" ) + public void testCmdlnOptionDebugDevicePassthroughDisabledShort() throws CommandLineArgsException + { + final String[] argsDebugPthOff = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.DEBUG_PTH.getShortOption(), + CMDLN_TEST_DEBUG_OFF + }; + + final String[] argsDebugPthMissing = {}; + + CommandLineArgs cmdLnDebugPthOff = new CommandLineArgs( argsDebugPthOff ); + CommandLineArgs cmdLnDebugPthMissing = new CommandLineArgs( argsDebugPthMissing ); + + assertFalse( cmdLnDebugPthOff.isDebugDevicePassthroughEnabled() ); + assertFalse( cmdLnDebugPthMissing.isDebugDevicePassthroughEnabled() ); + } + + @Test + @DisplayName( "Test the parsing of the disabled debug device passthrough command line option (long version)" ) + public void testCmdlnOptionDebugDevicePasshtroughDisabledLong() throws CommandLineArgsException + { + final String[] argsDebugPthOff = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.DEBUG_PTH.getLongOption(), + CMDLN_TEST_DEBUG_OFF + }; + + final String[] argsDebugMissing = {}; + + CommandLineArgs cmdLnDebugPthOff = new CommandLineArgs( argsDebugPthOff ); + CommandLineArgs cmdLnDebugPthMissing = new CommandLineArgs( argsDebugMissing ); + + assertFalse( cmdLnDebugPthOff.isDebugDevicePassthroughEnabled() ); + assertFalse( cmdLnDebugPthMissing.isDebugDevicePassthroughEnabled() ); + } + @Test @DisplayName( "Test the parsing of the firmware path command line option (short version)" ) public void testCmdlnOptionFirmwareShort() throws CommandLineArgsException -- cgit v1.2.3-55-g7522