3a9410
From 6d9fc3310cedf321f54530c0652998b67979e613 Mon Sep 17 00:00:00 2001
3a9410
Message-Id: <6d9fc3310cedf321f54530c0652998b67979e613@dist-git>
3a9410
From: Boris Fiuczynski <fiuczy@linux.ibm.com>
3a9410
Date: Fri, 13 May 2022 12:31:09 +0200
3a9410
Subject: [PATCH] util: add ccw device address parsing into virccw
3a9410
3a9410
Add virCCWDeviceAddressParseFromString and use it in nodedev udev.
3a9410
3a9410
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
3a9410
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3a9410
(cherry picked from commit 8d52f99f0b55ddfee4e0c00e756ca6c01250107d)
3a9410
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2165011
3a9410
Signed-off-by: Thomas Huth <thuth@redhat.com>
3a9410
---
3a9410
 src/libvirt_private.syms           |  1 +
3a9410
 src/node_device/node_device_udev.c |  8 +++++---
3a9410
 src/util/virccw.c                  | 18 ++++++++++++++++++
3a9410
 src/util/virccw.h                  |  5 +++++
3a9410
 4 files changed, 29 insertions(+), 3 deletions(-)
3a9410
3a9410
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
3a9410
index 44b551fb60..6f1292e0c4 100644
3a9410
--- a/src/libvirt_private.syms
3a9410
+++ b/src/libvirt_private.syms
3a9410
@@ -1904,6 +1904,7 @@ virCCWDeviceAddressAsString;
3a9410
 virCCWDeviceAddressEqual;
3a9410
 virCCWDeviceAddressIncrement;
3a9410
 virCCWDeviceAddressIsValid;
3a9410
+virCCWDeviceAddressParseFromString;
3a9410
 
3a9410
 
3a9410
 # util/vircgroup.h
3a9410
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
3a9410
index a9e8bf10da..ffcb3e8640 100644
3a9410
--- a/src/node_device/node_device_udev.c
3a9410
+++ b/src/node_device/node_device_udev.c
3a9410
@@ -36,6 +36,7 @@
3a9410
 #include "viruuid.h"
3a9410
 #include "virbuffer.h"
3a9410
 #include "virfile.h"
3a9410
+#include "virccw.h"
3a9410
 #include "virpci.h"
3a9410
 #include "virpidfile.h"
3a9410
 #include "virstring.h"
3a9410
@@ -1090,9 +1091,10 @@ udevGetCCWAddress(const char *sysfs_path,
3a9410
     char *p;
3a9410
 
3a9410
     if ((p = strrchr(sysfs_path, '/')) == NULL ||
3a9410
-        virStrToLong_ui(p + 1, &p, 16, &data->ccw_dev.cssid) < 0 || p == NULL ||
3a9410
-        virStrToLong_ui(p + 1, &p, 16, &data->ccw_dev.ssid) < 0 || p == NULL ||
3a9410
-        virStrToLong_ui(p + 1, &p, 16, &data->ccw_dev.devno) < 0) {
3a9410
+        virCCWDeviceAddressParseFromString(p + 1,
3a9410
+                                           &data->ccw_dev.cssid,
3a9410
+                                           &data->ccw_dev.ssid,
3a9410
+                                           &data->ccw_dev.devno) < 0) {
3a9410
         virReportError(VIR_ERR_INTERNAL_ERROR,
3a9410
                        _("failed to parse the CCW address from sysfs path: '%s'"),
3a9410
                        sysfs_path);
3a9410
diff --git a/src/util/virccw.c b/src/util/virccw.c
3a9410
index e2785bd9ab..33df1c2428 100644
3a9410
--- a/src/util/virccw.c
3a9410
+++ b/src/util/virccw.c
3a9410
@@ -20,6 +20,7 @@
3a9410
 
3a9410
 #include <config.h>
3a9410
 #include "virccw.h"
3a9410
+#include "virstring.h"
3a9410
 
3a9410
 
3a9410
 bool
3a9410
@@ -60,3 +61,20 @@ virCCWDeviceAddressIncrement(virCCWDeviceAddress *addr)
3a9410
     *addr = ccwaddr;
3a9410
     return 0;
3a9410
 }
3a9410
+
3a9410
+int
3a9410
+virCCWDeviceAddressParseFromString(const char *address,
3a9410
+                                   unsigned int *cssid,
3a9410
+                                   unsigned int *ssid,
3a9410
+                                   unsigned int *devno)
3a9410
+{
3a9410
+    char *p;
3a9410
+
3a9410
+    if (address == NULL || virStrToLong_ui(address, &p, 16, cssid) < 0 ||
3a9410
+        p == NULL || virStrToLong_ui(p + 1, &p, 16, ssid) < 0 ||
3a9410
+        p == NULL || virStrToLong_ui(p + 1, &p, 16, devno) < 0) {
3a9410
+        return -1;
3a9410
+    }
3a9410
+
3a9410
+    return 0;
3a9410
+}
3a9410
diff --git a/src/util/virccw.h b/src/util/virccw.h
3a9410
index aebbd4ab6d..df0273bcac 100644
3a9410
--- a/src/util/virccw.h
3a9410
+++ b/src/util/virccw.h
3a9410
@@ -42,3 +42,8 @@ bool virCCWDeviceAddressEqual(virCCWDeviceAddress *addr1,
3a9410
 char* virCCWDeviceAddressAsString(virCCWDeviceAddress *addr)
3a9410
     ATTRIBUTE_NONNULL(1);
3a9410
 int virCCWDeviceAddressIncrement(virCCWDeviceAddress *addr);
3a9410
+
3a9410
+int virCCWDeviceAddressParseFromString(const char *address,
3a9410
+                                       unsigned int *cssid,
3a9410
+                                       unsigned int *ssid,
3a9410
+                                       unsigned int *devno);
3a9410
-- 
3a9410
2.39.1
3a9410