The property is parsed using virTristateBoolTypeFromString() but formatted as if it was a regular bool, which results in the following incorrect conversion: BOOL_ABSENT -> managed='no' BOOL_YES -> managed='yes' BOOL_NO -> managed='yes' Use the virTristateBoolTypeToString() helper to ensure the setting can survive a roundtrip conversion. Fixes: 4b4a981d60d3372fb73bb3546ab1052844b2e3d5 Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> --- src/conf/virnetworkportdef.c | 7 +++++-- .../plug-hostdev-pci-unmanaged.xml | 12 ++++++++++++ tests/virnetworkportxml2xmltest.c | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/virnetworkportxml2xmldata/plug-hostdev-pci-unmanaged.xml diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index fcd9e55a55..aa35374fb0 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -384,8 +384,11 @@ virNetworkPortDefFormatBuf(virBuffer *buf, break; case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: - virBufferAsprintf(buf, " managed='%s'>\n", - def->plug.hostdevpci.managed ? "yes" : "no"); + if (def->plug.hostdevpci.managed) { + virBufferAsprintf(buf, " managed='%s'", + virTristateBoolTypeToString(def->plug.hostdevpci.managed)); + } + virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); if (def->plug.hostdevpci.driver) virBufferEscapeString(buf, "<driver name='%s'/>\n", diff --git a/tests/virnetworkportxml2xmldata/plug-hostdev-pci-unmanaged.xml b/tests/virnetworkportxml2xmldata/plug-hostdev-pci-unmanaged.xml new file mode 100644 index 0000000000..da5f568031 --- /dev/null +++ b/tests/virnetworkportxml2xmldata/plug-hostdev-pci-unmanaged.xml @@ -0,0 +1,12 @@ +<networkport> + <uuid>5d744f21-ba4a-4d6e-bdb2-30a35ff3207d</uuid> + <owner> + <name>memtest</name> + <uuid>d54df46f-1ab5-4a22-8618-4560ef5fac2c</uuid> + </owner> + <mac address='52:54:00:7b:35:93'/> + <plug type='hostdev-pci' managed='no'> + <driver name='vfio'/> + <address domain='0x0001' bus='0x02' slot='0x03' function='0x4'/> + </plug> +</networkport> diff --git a/tests/virnetworkportxml2xmltest.c b/tests/virnetworkportxml2xmltest.c index 093d855633..176f52d675 100644 --- a/tests/virnetworkportxml2xmltest.c +++ b/tests/virnetworkportxml2xmltest.c @@ -85,6 +85,7 @@ mymain(void) DO_TEST("plug-bridge-mactbl"); DO_TEST("plug-direct"); DO_TEST("plug-hostdev-pci"); + DO_TEST("plug-hostdev-pci-unmanaged"); DO_TEST("plug-network"); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -- 2.35.1