]> xenbits.xensource.com Git - people/aperard/libvirt.git/commitdiff
conf: split out hostdev <driver> parse/format to their own functions
authorLaine Stump <laine@redhat.com>
Fri, 5 Jan 2024 01:12:51 +0000 (20:12 -0500)
committerLaine Stump <laine@redhat.com>
Mon, 8 Jan 2024 04:57:09 +0000 (23:57 -0500)
This is done so that we can re-use the same parser/formatter for
<network> and <networkport>

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/conf/device_conf.c
src/conf/device_conf.h
src/conf/domain_conf.c

index a80b90121474309081da572f8dce0cc1d41007ff..68a8c7690ad33843b420aa8eec7f3ce0014c5b22 100644 (file)
@@ -55,6 +55,46 @@ VIR_ENUM_IMPL(virDomainDeviceAddress,
               "unassigned",
 );
 
+
+int
+virDeviceHostdevPCIDriverInfoParseXML(xmlNodePtr node,
+                                      virDeviceHostdevPCIDriverInfo *driver)
+{
+    if (virXMLPropEnum(node, "name",
+                       virDeviceHostdevPCIDriverNameTypeFromString,
+                       VIR_XML_PROP_NONZERO,
+                       &driver->name) < 0) {
+        return -1;
+    }
+
+    return 0;
+}
+
+
+int
+virDeviceHostdevPCIDriverInfoFormat(virBuffer *buf,
+                                    const virDeviceHostdevPCIDriverInfo *driver)
+{
+    g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
+
+    if (driver->name != VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) {
+        const char *driverName = virDeviceHostdevPCIDriverNameTypeToString(driver->name);
+
+        if (!driverName) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("unexpected pci hostdev driver name %1$d"),
+                           driver->name);
+            return -1;
+        }
+
+        virBufferAsprintf(&driverAttrBuf, " name='%s'", driverName);
+    }
+
+    virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
+    return 0;
+}
+
+
 static int
 virZPCIDeviceAddressParseXML(xmlNodePtr node,
                              virPCIDeviceAddress *addr)
index 1f7e0661427ed83eaf01aeeca9977aaaabf197a6..0b3f17a3aa8f973ca62cf04bcfe35705b7dad989 100644 (file)
@@ -25,6 +25,7 @@
 #include <libxml/xpath.h>
 
 #include "internal.h"
+#include "virconftypes.h"
 #include "virbuffer.h"
 #include "virccw.h"
 #include "virpci.h"
@@ -185,6 +186,12 @@ struct _virDomainDeviceInfo {
     bool isolationGroupLocked;
 };
 
+int virDeviceHostdevPCIDriverInfoParseXML(xmlNodePtr node,
+                                          virDeviceHostdevPCIDriverInfo *driver);
+
+int virDeviceHostdevPCIDriverInfoFormat(virBuffer *buf,
+                                        const virDeviceHostdevPCIDriverInfo *driver);
+
 void virDomainDeviceInfoClear(virDomainDeviceInfo *info);
 void virDomainDeviceInfoFree(virDomainDeviceInfo *info);
 
index 65864e26e643341d22735d53bbf295ff88556615..9906cf7315d58abaa37dea7f1ea5434c8cfdf1d6 100644 (file)
@@ -6283,13 +6283,9 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
         if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, flags) < 0)
             return -1;
 
-        if ((driver_node = virXPathNode("./driver", ctxt))) {
-            if (virXMLPropEnum(driver_node, "name",
-                               virDeviceHostdevPCIDriverNameTypeFromString,
-                               VIR_XML_PROP_NONZERO,
-                               &pcisrc->driver.name) < 0) {
-                return -1;
-            }
+        if ((driver_node = virXPathNode("./driver", ctxt)) &&
+            virDeviceHostdevPCIDriverInfoParseXML(driver_node, &pcisrc->driver) < 0) {
+            return -1;
         }
         break;
 
@@ -23424,25 +23420,12 @@ virDomainHostdevDefFormatSubsysPCI(virBuffer *buf,
                                    unsigned int flags,
                                    bool includeTypeInAddr)
 {
-    g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
     g_auto(virBuffer) sourceAttrBuf = VIR_BUFFER_INITIALIZER;
     g_auto(virBuffer) sourceChildBuf = VIR_BUFFER_INIT_CHILD(buf);
     virDomainHostdevSubsysPCI *pcisrc = &def->source.subsys.u.pci;
 
-    if (pcisrc->driver.name != VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) {
-        const char *driverName = virDeviceHostdevPCIDriverNameTypeToString(pcisrc->driver.name);
-
-        if (!driverName) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("unexpected pci hostdev driver type %1$d"),
-                           pcisrc->driver.name);
-            return -1;
-        }
-
-        virBufferAsprintf(&driverAttrBuf, " name='%s'", driverName);
-    }
-
-    virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
+    if (virDeviceHostdevPCIDriverInfoFormat(buf, &pcisrc->driver) < 0)
+        return -1;
 
     if (def->writeFiltering != VIR_TRISTATE_BOOL_ABSENT)
             virBufferAsprintf(&sourceAttrBuf, " writeFiltering='%s'",