[PATCH v2 2/3] xenconfig: add support for 'permissive' option of a PCI device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add support for xl.cfg(5) pci device 'permissive' option in
domXML-to-xenconfig converter. And a test for it.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
---
Changes in v2:
 - new patch
---
 src/libxl/xen_common.c                   | 51 +++++++++++++++++++++---
 tests/xlconfigdata/test-fullvirt-pci.cfg | 25 ++++++++++++-
 tests/xlconfigdata/test-fullvirt-pci.xml | 53 +++++++++++++++++++++++++-
 tests/xlconfigtest.c                     |  1 +-
 4 files changed, 125 insertions(+), 5 deletions(-)
 create mode 100644 tests/xlconfigdata/test-fullvirt-pci.cfg
 create mode 100644 tests/xlconfigdata/test-fullvirt-pci.xml

diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index 5c37e43..050b2a0 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 permissivebool = 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;
+            permissivebool = valueint ? VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO;
+        }
+    }
+
     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->permissive = permissivebool;
     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;
@@ -1857,12 +1883,27 @@ 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;
+
+            switch (def->hostdevs[i]->permissive) {
+                case VIR_TRISTATE_BOOL_YES:
+                    permissive_str = ",permissive=1";
+                    break;
+                case VIR_TRISTATE_BOOL_NO:
+                    permissive_str = ",permissive=0";
+                    break;
+                case VIR_TRISTATE_BOOL_ABSENT:
+                case VIR_TRISTATE_BOOL_LAST:
+                    permissive_str = "";
+                    break;
+            }
 
-            buf = g_strdup_printf("%04x:%02x:%02x.%x",
+            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 0000000..5a3f572
--- /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 0000000..dec390a
--- /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' permissive='yes'>
+      <driver name='xen'/>
+      <source>
+        <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 b2e045d..35f437b 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);
-- 
git-series 0.9.1






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux