From 6d9fc3310cedf321f54530c0652998b67979e613 Mon Sep 17 00:00:00 2001 Message-Id: <6d9fc3310cedf321f54530c0652998b67979e613@dist-git> From: Boris Fiuczynski Date: Fri, 13 May 2022 12:31:09 +0200 Subject: [PATCH] util: add ccw device address parsing into virccw Add virCCWDeviceAddressParseFromString and use it in nodedev udev. Signed-off-by: Boris Fiuczynski Reviewed-by: Michal Privoznik (cherry picked from commit 8d52f99f0b55ddfee4e0c00e756ca6c01250107d) Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2165011 Signed-off-by: Thomas Huth --- 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 44b551fb60..6f1292e0c4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1904,6 +1904,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 a9e8bf10da..ffcb3e8640 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" @@ -1090,9 +1091,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 #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.39.1