From 70768cda9740d1fbc4b95460247bc5384d7e31a1 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Thu, 4 Aug 2022 10:27:40 +0200 Subject: [PATCH] vmx: Add support for dummy network interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also map it to an ethernet without connectionType and networkName. https://bugzilla.redhat.com/show_bug.cgi?id=1988211 Signed-off-by: Martin Kletzander Reviewed-by: Reviewed-by: Ján Tomko --- src/vmx/vmx.c | 21 ++++++++++++++--- .../vmx2xmldata/ethernet-unmanaged-nodev.vmx | 7 ++++++ .../vmx2xmldata/ethernet-unmanaged-nodev.xml | 23 +++++++++++++++++++ tests/vmx2xmltest.c | 1 + .../xml2vmx-ethernet-unmanaged-nodev.vmx | 13 +++++++++++ .../xml2vmx-ethernet-unmanaged-nodev.xml | 13 +++++++++++ tests/xml2vmxtest.c | 2 ++ 7 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 tests/vmx2xmldata/ethernet-unmanaged-nodev.vmx create mode 100644 tests/vmx2xmldata/ethernet-unmanaged-nodev.xml create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-unmanaged-nodev.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-unmanaged-nodev.xml diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 95e2d4ae24..49eef12e3e 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2826,7 +2826,7 @@ virVMXParseEthernet(virConf *conf, int controller, virDomainNetDef **def) STRCASEEQ(connectionType, "bridged") || STRCASEEQ(connectionType, "custom")) { if (virVMXGetConfigString(conf, networkName_name, &networkName, - false) < 0) + true) < 0) goto cleanup; } @@ -2837,7 +2837,20 @@ virVMXParseEthernet(virConf *conf, int controller, virDomainNetDef **def) } /* Setup virDomainNetDef */ - if (connectionType == NULL || STRCASEEQ(connectionType, "bridged")) { + if (connectionType == NULL && networkName == NULL) { + /* + * Having neither a connectionType nor a network name can mean two + * things: + * + * 1) there is no connection of that nic + * 2) the nic is connected to VMWare Distributed Switch + * + * But we do not see any difference between these and hence we report + * the closest thing to at least make virt-v2v and others work when they + * read the domain XML. + */ + (*def)->type = VIR_DOMAIN_NET_TYPE_DUMMY; + } else if (connectionType == NULL || STRCASEEQ(connectionType, "bridged")) { (*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE; (*def)->data.bridge.brname = g_steal_pointer(&networkName); } else if (STRCASEEQ(connectionType, "hostonly")) { @@ -3946,6 +3959,9 @@ virVMXFormatEthernet(virDomainNetDef *def, int controller, controller); break; + case VIR_DOMAIN_NET_TYPE_DUMMY: + break; + case VIR_DOMAIN_NET_TYPE_ETHERNET: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: @@ -3957,7 +3973,6 @@ virVMXFormatEthernet(virDomainNetDef *def, int controller, case VIR_DOMAIN_NET_TYPE_HOSTDEV: case VIR_DOMAIN_NET_TYPE_UDP: case VIR_DOMAIN_NET_TYPE_VDPA: - case VIR_DOMAIN_NET_TYPE_DUMMY: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported net type '%s'"), virDomainNetTypeToString(def->type)); return -1; diff --git a/tests/vmx2xmldata/ethernet-unmanaged-nodev.vmx b/tests/vmx2xmldata/ethernet-unmanaged-nodev.vmx new file mode 100644 index 0000000000..6e08536337 --- /dev/null +++ b/tests/vmx2xmldata/ethernet-unmanaged-nodev.vmx @@ -0,0 +1,7 @@ +config.version = "8" +virtualHW.version = "4" +ethernet0.present = "true" +ethernet0.virtualDev = "e1000e" +ethernet0.addressType = "vpx" +ethernet0.generatedAddress = "00:50:56:87:65:43" +displayName = "test" diff --git a/tests/vmx2xmldata/ethernet-unmanaged-nodev.xml b/tests/vmx2xmldata/ethernet-unmanaged-nodev.xml new file mode 100644 index 0000000000..a312430337 --- /dev/null +++ b/tests/vmx2xmldata/ethernet-unmanaged-nodev.xml @@ -0,0 +1,23 @@ + + test + 00000000-0000-0000-0000-000000000000 + 32768 + 32768 + 1 + + hvm + + + destroy + restart + destroy + + + + + + + + diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index dbd771017b..e08079512b 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -236,6 +236,7 @@ mymain(void) DO_TEST("ethernet-static"); DO_TEST("ethernet-vpx"); DO_TEST("ethernet-other"); + DO_TEST("ethernet-unmanaged-nodev"); DO_TEST("serial-file"); DO_TEST("serial-device"); diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-unmanaged-nodev.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-unmanaged-nodev.vmx new file mode 100644 index 0000000000..41ba2967c0 --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-ethernet-unmanaged-nodev.vmx @@ -0,0 +1,13 @@ +.encoding = "UTF-8" +config.version = "8" +virtualHW.version = "4" +guestOS = "other" +uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15" +displayName = "ethernet-vpx" +memsize = "4" +numvcpus = "1" +floppy0.present = "false" +floppy1.present = "false" +ethernet0.present = "true" +ethernet0.addressType = "vpx" +ethernet0.generatedAddress = "00:50:56:87:65:43" diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-unmanaged-nodev.xml b/tests/xml2vmxdata/xml2vmx-ethernet-unmanaged-nodev.xml new file mode 100644 index 0000000000..a071b2f215 --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-ethernet-unmanaged-nodev.xml @@ -0,0 +1,13 @@ + + ethernet-vpx + 564d9bef-acd9-b4e0-c8f0-aea8b9103515 + 4096 + + hvm + + + + + + + diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 1a7f2e4f33..0ea213d5d5 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -225,6 +225,8 @@ mymain(void) DO_TEST("ethernet-other", "ethernet-other", 4); DO_TEST("ethernet-mac-type", "ethernet-mac-type", 4); + DO_TEST("ethernet-unmanaged-nodev", "ethernet-unmanaged-nodev", 4); + DO_TEST("serial-file", "serial-file", 4); DO_TEST("serial-device", "serial-device", 4); DO_TEST("serial-pipe", "serial-pipe", 4);