[PATCH 10/17] util: add ccw device address parsing into virccw

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add virCCWDeviceAddressParseFromString and use it in nodedev udev.

Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx>
---
 src/libvirt_private.syms           |  1 +
 src/node_device/node_device_udev.c |  8 +++++---
 src/util/virccw.c                  | 18 ++++++++++++++++++
 src/util/virccw.h                  |  5 +++++
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 09867b7876..148d016e0e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1927,6 +1927,7 @@ virCCWDeviceAddressAsString;
 virCCWDeviceAddressEqual;
 virCCWDeviceAddressIncrement;
 virCCWDeviceAddressIsValid;
+virCCWDeviceAddressParseFromString;
 
 
 # util/vircgroup.h
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index b68dc12158..4bb841c66b 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -36,6 +36,7 @@
 #include "viruuid.h"
 #include "virbuffer.h"
 #include "virfile.h"
+#include "virccw.h"
 #include "virpci.h"
 #include "virpidfile.h"
 #include "virstring.h"
@@ -1086,9 +1087,10 @@ udevGetCCWAddress(const char *sysfs_path,
     char *p;
 
     if ((p = strrchr(sysfs_path, '/')) == NULL ||
-        virStrToLong_ui(p + 1, &p, 16, &data->ccw_dev.cssid) < 0 || p == NULL ||
-        virStrToLong_ui(p + 1, &p, 16, &data->ccw_dev.ssid) < 0 || p == NULL ||
-        virStrToLong_ui(p + 1, &p, 16, &data->ccw_dev.devno) < 0) {
+        virCCWDeviceAddressParseFromString(p + 1,
+                                           &data->ccw_dev.cssid,
+                                           &data->ccw_dev.ssid,
+                                           &data->ccw_dev.devno) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to parse the CCW address from sysfs path: '%s'"),
                        sysfs_path);
diff --git a/src/util/virccw.c b/src/util/virccw.c
index e2785bd9ab..33df1c2428 100644
--- a/src/util/virccw.c
+++ b/src/util/virccw.c
@@ -20,6 +20,7 @@
 
 #include <config.h>
 #include "virccw.h"
+#include "virstring.h"
 
 
 bool
@@ -60,3 +61,20 @@ virCCWDeviceAddressIncrement(virCCWDeviceAddress *addr)
     *addr = ccwaddr;
     return 0;
 }
+
+int
+virCCWDeviceAddressParseFromString(const char *address,
+                                   unsigned int *cssid,
+                                   unsigned int *ssid,
+                                   unsigned int *devno)
+{
+    char *p;
+
+    if (address == NULL || virStrToLong_ui(address, &p, 16, cssid) < 0 ||
+        p == NULL || virStrToLong_ui(p + 1, &p, 16, ssid) < 0 ||
+        p == NULL || virStrToLong_ui(p + 1, &p, 16, devno) < 0) {
+        return -1;
+    }
+
+    return 0;
+}
diff --git a/src/util/virccw.h b/src/util/virccw.h
index aebbd4ab6d..df0273bcac 100644
--- a/src/util/virccw.h
+++ b/src/util/virccw.h
@@ -42,3 +42,8 @@ bool virCCWDeviceAddressEqual(virCCWDeviceAddress *addr1,
 char* virCCWDeviceAddressAsString(virCCWDeviceAddress *addr)
     ATTRIBUTE_NONNULL(1);
 int virCCWDeviceAddressIncrement(virCCWDeviceAddress *addr);
+
+int virCCWDeviceAddressParseFromString(const char *address,
+                                       unsigned int *cssid,
+                                       unsigned int *ssid,
+                                       unsigned int *devno);
-- 
2.33.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux