]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: refactor ccw device address parsing from XML
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Fri, 13 May 2022 10:31:12 +0000 (12:31 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 23 May 2022 14:32:07 +0000 (16:32 +0200)
Move ccw device address XML parsing into new method for later reuse.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/node_device_conf.c

index 97779078e8f18035429b1066d7dfe4d2399a6a42..8d160185ebf78d1e569972d497ed1d0559be7253 100644 (file)
@@ -1143,6 +1143,58 @@ virNodeDevAPMatrixCapabilityParseXML(xmlXPathContextPtr ctxt,
 }
 
 
+static int
+virNodeDevCCWDeviceAddressParseXML(xmlXPathContextPtr ctxt,
+                                   xmlNodePtr node,
+                                   const char *dev_name,
+                                   virCCWDeviceAddress *ccw_addr)
+{
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
+    g_autofree char *cssid = NULL;
+    g_autofree char *ssid = NULL;
+    g_autofree char *devno = NULL;
+
+    ctxt->node = node;
+
+    if (!(cssid = virXPathString("string(./cssid[1])", ctxt))) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("missing cssid value for '%s'"), dev_name);
+        return -1;
+    }
+    if (virStrToLong_uip(cssid, NULL, 0, &ccw_addr->cssid) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("invalid cssid value '%s' for '%s'"),
+                       cssid, dev_name);
+        return -1;
+    }
+
+    if (!(ssid = virXPathString("string(./ssid[1])", ctxt))) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("missing ssid value for '%s'"), dev_name);
+        return -1;
+    }
+    if (virStrToLong_uip(ssid, NULL, 0, &ccw_addr->ssid) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("invalid ssid value '%s' for '%s'"),
+                       ssid, dev_name);
+        return -1;
+    }
+
+    if (!(devno = virXPathString("string(./devno[1])", ctxt))) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("missing devno value for '%s'"), dev_name);
+        return -1;
+    }
+    if (virStrToLong_uip(devno, NULL, 16, &ccw_addr->devno) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("invalid devno value '%s' for '%s'"),
+                       devno, dev_name);
+        return -1;
+    }
+
+    return 0;
+}
+
 static int
 virNodeDevCSSCapabilityParseXML(xmlXPathContextPtr ctxt,
                                 xmlNodePtr node,
@@ -1180,50 +1232,18 @@ virNodeDevCapCCWParseXML(xmlXPathContextPtr ctxt,
     g_autofree xmlNodePtr *nodes = NULL;
     int n = 0;
     size_t i = 0;
-    g_autofree char *cssid = NULL;
-    g_autofree char *ssid = NULL;
-    g_autofree char *devno = NULL;
+    g_autofree virCCWDeviceAddress *ccw_addr = NULL;
 
     ctxt->node = node;
 
-    if (!(cssid = virXPathString("string(./cssid[1])", ctxt))) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("missing cssid value for '%s'"), def->name);
-        return -1;
-    }
-
-    if (virStrToLong_uip(cssid, NULL, 0, &ccw_dev->cssid) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("invalid cssid value '%s' for '%s'"),
-                       cssid, def->name);
-        return -1;
-    }
-
-    if (!(ssid = virXPathString("string(./ssid[1])", ctxt))) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("missing ssid value for '%s'"), def->name);
-        return -1;
-    }
+    ccw_addr = g_new0(virCCWDeviceAddress, 1);
 
-    if (virStrToLong_uip(ssid, NULL, 0, &ccw_dev->ssid) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("invalid ssid value '%s' for '%s'"),
-                       ssid, def->name);
+    if (virNodeDevCCWDeviceAddressParseXML(ctxt, node, def->name, ccw_addr) < 0)
         return -1;
-    }
 
-    if (!(devno = virXPathString("string(./devno[1])", ctxt))) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("missing devno value for '%s'"), def->name);
-        return -1;
-    }
-
-    if (virStrToLong_uip(devno, NULL, 16, &ccw_dev->devno) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("invalid devno value '%s' for '%s'"),
-                       devno, def->name);
-        return -1;
-    }
+    ccw_dev->cssid = ccw_addr->cssid;
+    ccw_dev->ssid = ccw_addr->ssid;
+    ccw_dev->devno = ccw_addr->devno;
 
     if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0)
         return -1;