render / rpms / libvirt

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