[PATCH V3 2/3] Xen: Add support for writeFiltering in config converter

Jim Fehlig jfehlig at suse.com
Fri Aug 14 21:43:28 UTC 2020


Add support for the writeFiltering attribute in the domXML to native
config converter. Also include a test.

Signed-off-by: Jim Fehlig <jfehlig at suse.com>
Signed-off-by: Marek Marczykowski-Górecki <marmarek at invisiblethingslab.com>
---
 src/libxl/xen_common.c                   | 52 ++++++++++++++++++++---
 tests/xlconfigdata/test-fullvirt-pci.cfg | 25 +++++++++++
 tests/xlconfigdata/test-fullvirt-pci.xml | 53 ++++++++++++++++++++++++
 tests/xlconfigtest.c                     |  1 +
 4 files changed, 126 insertions(+), 5 deletions(-)

diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index 75fe7e0644..a15a3c6007 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -381,10 +381,11 @@ xenParsePCI(char *entry)
     int busID;
     int slotID;
     int funcID;
+    virTristateBool filtered = VIR_TRISTATE_BOOL_ABSENT;
 
     domain[0] = bus[0] = slot[0] = func[0] = '\0';
 
-    /* pci=['0000:00:1b.0','0000:00:13.0'] */
+    /* pci=['0000:00:1b.0','0000:00:13.0,permissive=1'] */
     if (!(key = entry))
         return NULL;
     if (!(nextkey = strchr(key, ':')))
@@ -414,14 +415,38 @@ xenParsePCI(char *entry)
     }
 
     key = nextkey + 1;
-    if (strlen(key) != 1)
+    if (!(nextkey = strchrnul(key, ',')))
         return NULL;
-    if (virStrncpy(func, key, 1, sizeof(func)) < 0) {
+    if (virStrncpy(func, key, (nextkey - key), sizeof(func)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Function %s too big for destination"), key);
         return NULL;
     }
 
+    /* options */
+    while (*nextkey != '\0') {
+        char *data;
+        key = nextkey + 1;
+        if (!(data = strchr(key, '=')))
+            return NULL;
+        data++;
+        if (!(nextkey = strchrnul(key, ',')))
+            return NULL;
+        if (STRPREFIX(key, "permissive=")) {
+            char valuestr[5];
+            int valueint;
+            if (virStrncpy(valuestr, data, (nextkey - data), sizeof(valuestr)) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("Permissive %s too big for destination"), data);
+                return NULL;
+            }
+            /* xl.cfg(5) specifies false as 0 and true as any other numeric value */
+            if (virStrToLong_i(valuestr, NULL, 10, &valueint) < 0)
+                return NULL;
+            filtered = valueint ? VIR_TRISTATE_BOOL_NO : VIR_TRISTATE_BOOL_YES;
+        }
+    }
+
     if (virStrToLong_i(domain, NULL, 16, &domainID) < 0)
         return NULL;
     if (virStrToLong_i(bus, NULL, 16, &busID) < 0)
@@ -435,6 +460,7 @@ xenParsePCI(char *entry)
        return NULL;
 
     hostdev->managed = false;
+    hostdev->writeFiltering = filtered;
     hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
     hostdev->source.subsys.u.pci.addr.domain = domainID;
     hostdev->source.subsys.u.pci.addr.bus = busID;
@@ -1849,12 +1875,28 @@ xenFormatPCI(virConfPtr conf, virDomainDefPtr def)
             def->hostdevs[i]->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
             virConfValuePtr val, tmp;
             char *buf;
+            const char *permissive_str = NULL;
 
-            buf = g_strdup_printf("%04x:%02x:%02x.%x",
+            switch (def->hostdevs[i]->writeFiltering) {
+                case VIR_TRISTATE_BOOL_YES:
+                    permissive_str = ",permissive=0";
+                    break;
+                case VIR_TRISTATE_BOOL_NO:
+                    permissive_str = ",permissive=1";
+                    break;
+                case VIR_TRISTATE_BOOL_ABSENT:
+                case VIR_TRISTATE_BOOL_LAST:
+                    permissive_str = "";
+                    break;
+            }
+
+            buf = g_strdup_printf("%04x:%02x:%02x.%x%s",
                                   def->hostdevs[i]->source.subsys.u.pci.addr.domain,
                                   def->hostdevs[i]->source.subsys.u.pci.addr.bus,
                                   def->hostdevs[i]->source.subsys.u.pci.addr.slot,
-                                  def->hostdevs[i]->source.subsys.u.pci.addr.function);
+                                  def->hostdevs[i]->source.subsys.u.pci.addr.function,
+                                  permissive_str);
+
 
             if (VIR_ALLOC(val) < 0) {
                 VIR_FREE(buf);
diff --git a/tests/xlconfigdata/test-fullvirt-pci.cfg b/tests/xlconfigdata/test-fullvirt-pci.cfg
new file mode 100644
index 0000000000..5a3f572e25
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-pci.cfg
@@ -0,0 +1,25 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+pae = 1
+acpi = 1
+apic = 1
+viridian = 0
+rtc_timeoffset = 0
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+device_model = "/usr/lib/xen/bin/qemu-system-i386"
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = "127.0.0.1"
+pci = [ "0000:01:1a.1", "0000:02:00.0,permissive=1" ]
+parallel = "none"
+serial = "none"
+builder = "hvm"
+boot = "d"
+disk = [ "format=raw,vdev=hda,access=rw,backendtype=phy,target=/dev/HostVG/XenGuest2" ]
diff --git a/tests/xlconfigdata/test-fullvirt-pci.xml b/tests/xlconfigdata/test-fullvirt-pci.xml
new file mode 100644
index 0000000000..75aa6ac25b
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-pci.xml
@@ -0,0 +1,53 @@
+<domain type='xen'>
+  <name>XenGuest2</name>
+  <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>592896</memory>
+  <currentMemory unit='KiB'>403456</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='xenfv'>hvm</type>
+    <loader type='rom'>/usr/lib/xen/boot/hvmloader</loader>
+    <boot dev='cdrom'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <pae/>
+  </features>
+  <clock offset='variable' adjustment='0' basis='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/lib/xen/bin/qemu-system-i386</emulator>
+    <disk type='block' device='disk'>
+      <driver name='phy' type='raw'/>
+      <source dev='/dev/HostVG/XenGuest2'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='xenbus' index='0'/>
+    <controller type='ide' index='0'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
+      <listen type='address' address='127.0.0.1'/>
+    </graphics>
+    <video>
+      <model type='cirrus' vram='8192' heads='1' primary='yes'/>
+    </video>
+    <hostdev mode='subsystem' type='pci' managed='no'>
+      <driver name='xen'/>
+      <source>
+        <address domain='0x0000' bus='0x01' slot='0x1a' function='0x1'/>
+      </source>
+    </hostdev>
+    <hostdev mode='subsystem' type='pci' managed='no'>
+      <driver name='xen'/>
+      <source writeFiltering='no'>
+        <address domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
+      </source>
+    </hostdev>
+    <memballoon model='xen'/>
+  </devices>
+</domain>
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index b2e045dfa5..35f437bde1 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -260,6 +260,7 @@ mymain(void)
     DO_TEST("fullvirt-nestedhvm-disabled");
     DO_TEST("fullvirt-cpuid");
     DO_TEST("fullvirt-acpi-slic");
+    DO_TEST("fullvirt-pci");
 #ifdef LIBXL_HAVE_VNUMA
     DO_TEST("fullvirt-vnuma");
     DO_TEST_PARSE("fullvirt-vnuma-autocomplete", false);
-- 
2.28.0





More information about the libvir-list mailing list