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