Blob Blame History Raw
From a89df2d899e6e93ab7bccdaa1afb130d01d9b286 Mon Sep 17 00:00:00 2001
Message-Id: <a89df2d899e6e93ab7bccdaa1afb130d01d9b286@dist-git>
From: Boris Fiuczynski <fiuczy@linux.ibm.com>
Date: Thu, 8 Oct 2020 11:06:56 -0400
Subject: [PATCH] node_device: refactor udevProcessCCW

Refactor out CCW address parsing for later reuse.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
(cherry picked from commit 0e7f8bb6c1c3a63cf892f7afcd34fcb979ef0155)
https://bugzilla.redhat.com/show_bug.cgi?id=1853289
https://bugzilla.redhat.com/show_bug.cgi?id=1865932
Message-Id: <20201008150700.52157-2-bfiuczyn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
---
 src/node_device/node_device_udev.c | 31 ++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index ae3d081e66..9667a042bd 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1058,27 +1058,38 @@ udevProcessMediatedDevice(struct udev_device *dev,
 
 
 static int
-udevProcessCCW(struct udev_device *device,
-               virNodeDeviceDefPtr def)
+udevGetCCWAddress(const char *sysfs_path,
+                  virNodeDevCapDataPtr data)
 {
-    int online;
     char *p;
-    virNodeDevCapDataPtr data = &def->caps->data;
-
-    /* process only online devices to keep the list sane */
-    if (udevGetIntSysfsAttr(device, "online", &online, 0) < 0 || online != 1)
-        return -1;
 
-    if ((p = strrchr(def->sysfs_path, '/')) == NULL ||
+    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) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to parse the CCW address from sysfs path: '%s'"),
-                       def->sysfs_path);
+                       sysfs_path);
         return -1;
     }
 
+    return 0;
+}
+
+
+static int
+udevProcessCCW(struct udev_device *device,
+               virNodeDeviceDefPtr def)
+{
+    int online;
+
+    /* process only online devices to keep the list sane */
+    if (udevGetIntSysfsAttr(device, "online", &online, 0) < 0 || online != 1)
+        return -1;
+
+    if (udevGetCCWAddress(def->sysfs_path, &def->caps->data) < 0)
+        return -1;
+
     if (udevGenerateDeviceName(device, def, NULL) != 0)
         return -1;
 
-- 
2.28.0