render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
2cf05b
From ef8c30a091b5b0f08f9405878b49c21c5525dd0a Mon Sep 17 00:00:00 2001
2cf05b
Message-Id: <ef8c30a091b5b0f08f9405878b49c21c5525dd0a@dist-git>
2cf05b
From: Boris Fiuczynski <fiuczy@linux.ibm.com>
2cf05b
Date: Fri, 13 May 2022 12:31:12 +0200
2cf05b
Subject: [PATCH] nodedev: refactor ccw device address parsing from XML
2cf05b
2cf05b
Move ccw device address XML parsing into new method for later reuse.
2cf05b
2cf05b
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
2cf05b
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2cf05b
(cherry picked from commit 4402295d371a62ab8632d23002283b8a7721e6a7)
2cf05b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2165011
2cf05b
Signed-off-by: Thomas Huth <thuth@redhat.com>
2cf05b
---
2cf05b
 src/conf/node_device_conf.c | 96 ++++++++++++++++++++++---------------
2cf05b
 1 file changed, 58 insertions(+), 38 deletions(-)
2cf05b
2cf05b
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
2cf05b
index 1e00f65717..8982368465 100644
2cf05b
--- a/src/conf/node_device_conf.c
2cf05b
+++ b/src/conf/node_device_conf.c
2cf05b
@@ -1141,6 +1141,58 @@ virNodeDevAPMatrixCapabilityParseXML(xmlXPathContextPtr ctxt,
2cf05b
 }
2cf05b
 
2cf05b
 
2cf05b
+static int
2cf05b
+virNodeDevCCWDeviceAddressParseXML(xmlXPathContextPtr ctxt,
2cf05b
+                                   xmlNodePtr node,
2cf05b
+                                   const char *dev_name,
2cf05b
+                                   virCCWDeviceAddress *ccw_addr)
2cf05b
+{
2cf05b
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
2cf05b
+    g_autofree char *cssid = NULL;
2cf05b
+    g_autofree char *ssid = NULL;
2cf05b
+    g_autofree char *devno = NULL;
2cf05b
+
2cf05b
+    ctxt->node = node;
2cf05b
+
2cf05b
+    if (!(cssid = virXPathString("string(./cssid[1])", ctxt))) {
2cf05b
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
+                       _("missing cssid value for '%s'"), dev_name);
2cf05b
+        return -1;
2cf05b
+    }
2cf05b
+    if (virStrToLong_uip(cssid, NULL, 0, &ccw_addr->cssid) < 0) {
2cf05b
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
+                       _("invalid cssid value '%s' for '%s'"),
2cf05b
+                       cssid, dev_name);
2cf05b
+        return -1;
2cf05b
+    }
2cf05b
+
2cf05b
+    if (!(ssid = virXPathString("string(./ssid[1])", ctxt))) {
2cf05b
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
+                       _("missing ssid value for '%s'"), dev_name);
2cf05b
+        return -1;
2cf05b
+    }
2cf05b
+    if (virStrToLong_uip(ssid, NULL, 0, &ccw_addr->ssid) < 0) {
2cf05b
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
+                       _("invalid ssid value '%s' for '%s'"),
2cf05b
+                       ssid, dev_name);
2cf05b
+        return -1;
2cf05b
+    }
2cf05b
+
2cf05b
+    if (!(devno = virXPathString("string(./devno[1])", ctxt))) {
2cf05b
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
+                       _("missing devno value for '%s'"), dev_name);
2cf05b
+        return -1;
2cf05b
+    }
2cf05b
+    if (virStrToLong_uip(devno, NULL, 16, &ccw_addr->devno) < 0) {
2cf05b
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
+                       _("invalid devno value '%s' for '%s'"),
2cf05b
+                       devno, dev_name);
2cf05b
+        return -1;
2cf05b
+    }
2cf05b
+
2cf05b
+    return 0;
2cf05b
+}
2cf05b
+
2cf05b
 static int
2cf05b
 virNodeDevCSSCapabilityParseXML(xmlXPathContextPtr ctxt,
2cf05b
                                 xmlNodePtr node,
2cf05b
@@ -1178,50 +1230,18 @@ virNodeDevCapCCWParseXML(xmlXPathContextPtr ctxt,
2cf05b
     g_autofree xmlNodePtr *nodes = NULL;
2cf05b
     int n = 0;
2cf05b
     size_t i = 0;
2cf05b
-    g_autofree char *cssid = NULL;
2cf05b
-    g_autofree char *ssid = NULL;
2cf05b
-    g_autofree char *devno = NULL;
2cf05b
+    g_autofree virCCWDeviceAddress *ccw_addr = NULL;
2cf05b
 
2cf05b
     ctxt->node = node;
2cf05b
 
2cf05b
-    if (!(cssid = virXPathString("string(./cssid[1])", ctxt))) {
2cf05b
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
-                       _("missing cssid value for '%s'"), def->name);
2cf05b
-        return -1;
2cf05b
-    }
2cf05b
-
2cf05b
-    if (virStrToLong_uip(cssid, NULL, 0, &ccw_dev->cssid) < 0) {
2cf05b
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
-                       _("invalid cssid value '%s' for '%s'"),
2cf05b
-                       cssid, def->name);
2cf05b
-        return -1;
2cf05b
-    }
2cf05b
-
2cf05b
-    if (!(ssid = virXPathString("string(./ssid[1])", ctxt))) {
2cf05b
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
-                       _("missing ssid value for '%s'"), def->name);
2cf05b
-        return -1;
2cf05b
-    }
2cf05b
+    ccw_addr = g_new0(virCCWDeviceAddress, 1);
2cf05b
 
2cf05b
-    if (virStrToLong_uip(ssid, NULL, 0, &ccw_dev->ssid) < 0) {
2cf05b
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
-                       _("invalid ssid value '%s' for '%s'"),
2cf05b
-                       ssid, def->name);
2cf05b
+    if (virNodeDevCCWDeviceAddressParseXML(ctxt, node, def->name, ccw_addr) < 0)
2cf05b
         return -1;
2cf05b
-    }
2cf05b
 
2cf05b
-    if (!(devno = virXPathString("string(./devno[1])", ctxt))) {
2cf05b
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
-                       _("missing devno value for '%s'"), def->name);
2cf05b
-        return -1;
2cf05b
-    }
2cf05b
-
2cf05b
-    if (virStrToLong_uip(devno, NULL, 16, &ccw_dev->devno) < 0) {
2cf05b
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
2cf05b
-                       _("invalid devno value '%s' for '%s'"),
2cf05b
-                       devno, def->name);
2cf05b
-        return -1;
2cf05b
-    }
2cf05b
+    ccw_dev->cssid = ccw_addr->cssid;
2cf05b
+    ccw_dev->ssid = ccw_addr->ssid;
2cf05b
+    ccw_dev->devno = ccw_addr->devno;
2cf05b
 
2cf05b
     if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0)
2cf05b
         return -1;
2cf05b
-- 
2cf05b
2.39.1
2cf05b