3a9410
From e5e849999b1d615c6a371839aeead37275599cf0 Mon Sep 17 00:00:00 2001
3a9410
Message-Id: <e5e849999b1d615c6a371839aeead37275599cf0@dist-git>
3a9410
From: Boris Fiuczynski <fiuczy@linux.ibm.com>
3a9410
Date: Fri, 13 May 2022 12:31:10 +0200
3a9410
Subject: [PATCH] util: add virCCWDeviceAddressFromString to virccw
3a9410
3a9410
Add a method to parse a ccw device address from a string.
3a9410
3a9410
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
3a9410
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3a9410
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3a9410
(cherry picked from commit 9453eb458a5c3ed6687188233d7e389c3e20c266)
3a9410
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2165011
3a9410
Conflicts:
3a9410
	po/POTFILES (file is called POTFILES.in in downstream)
3a9410
Signed-off-by: Thomas Huth <thuth@redhat.com>
3a9410
---
3a9410
 po/POTFILES.in           |  1 +
3a9410
 src/libvirt_private.syms |  1 +
3a9410
 src/util/virccw.c        | 23 +++++++++++++++++++++++
3a9410
 src/util/virccw.h        |  3 +++
3a9410
 4 files changed, 28 insertions(+)
3a9410
3a9410
diff --git a/po/POTFILES.in b/po/POTFILES.in
3a9410
index bf0a3b3529..327e20ec11 100644
3a9410
--- a/po/POTFILES.in
3a9410
+++ b/po/POTFILES.in
3a9410
@@ -246,6 +246,7 @@
3a9410
 @SRCDIR@src/util/virauth.c
3a9410
 @SRCDIR@src/util/virauthconfig.c
3a9410
 @SRCDIR@src/util/virbitmap.c
3a9410
+@SRCDIR@src/util/virccw.c
3a9410
 @SRCDIR@src/util/vircgroup.c
3a9410
 @SRCDIR@src/util/vircgroupbackend.c
3a9410
 @SRCDIR@src/util/vircgroupbackend.h
3a9410
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
3a9410
index 6f1292e0c4..7c558ad364 100644
3a9410
--- a/src/libvirt_private.syms
3a9410
+++ b/src/libvirt_private.syms
3a9410
@@ -1902,6 +1902,7 @@ virBufferVasprintf;
3a9410
 # util/virccw.h
3a9410
 virCCWDeviceAddressAsString;
3a9410
 virCCWDeviceAddressEqual;
3a9410
+virCCWDeviceAddressFromString;
3a9410
 virCCWDeviceAddressIncrement;
3a9410
 virCCWDeviceAddressIsValid;
3a9410
 virCCWDeviceAddressParseFromString;
3a9410
diff --git a/src/util/virccw.c b/src/util/virccw.c
3a9410
index 33df1c2428..d741743050 100644
3a9410
--- a/src/util/virccw.c
3a9410
+++ b/src/util/virccw.c
3a9410
@@ -20,8 +20,11 @@
3a9410
 
3a9410
 #include <config.h>
3a9410
 #include "virccw.h"
3a9410
+#include "virerror.h"
3a9410
 #include "virstring.h"
3a9410
 
3a9410
+#define VIR_FROM_THIS VIR_FROM_NONE
3a9410
+
3a9410
 
3a9410
 bool
3a9410
 virCCWDeviceAddressIsValid(virCCWDeviceAddress *addr)
3a9410
@@ -49,6 +52,26 @@ virCCWDeviceAddressAsString(virCCWDeviceAddress *addr)
3a9410
     return g_strdup_printf(VIR_CCW_DEVICE_ADDRESS_FMT, addr->cssid, addr->ssid, addr->devno);
3a9410
 }
3a9410
 
3a9410
+virCCWDeviceAddress *
3a9410
+virCCWDeviceAddressFromString(const char *address)
3a9410
+{
3a9410
+    g_autofree virCCWDeviceAddress *ccw = NULL;
3a9410
+
3a9410
+    ccw = g_new0(virCCWDeviceAddress, 1);
3a9410
+
3a9410
+    if (virCCWDeviceAddressParseFromString(address,
3a9410
+                                           &ccw->cssid,
3a9410
+                                           &ccw->ssid,
3a9410
+                                           &ccw->devno) < 0) {
3a9410
+        virReportError(VIR_ERR_INTERNAL_ERROR,
3a9410
+                       _("Failed to parse CCW address '%s'"),
3a9410
+                       address);
3a9410
+        return NULL;
3a9410
+    }
3a9410
+
3a9410
+    return g_steal_pointer(&ccw;;
3a9410
+}
3a9410
+
3a9410
 int
3a9410
 virCCWDeviceAddressIncrement(virCCWDeviceAddress *addr)
3a9410
 {
3a9410
diff --git a/src/util/virccw.h b/src/util/virccw.h
3a9410
index df0273bcac..80cc716811 100644
3a9410
--- a/src/util/virccw.h
3a9410
+++ b/src/util/virccw.h
3a9410
@@ -41,6 +41,9 @@ bool virCCWDeviceAddressEqual(virCCWDeviceAddress *addr1,
3a9410
 
3a9410
 char* virCCWDeviceAddressAsString(virCCWDeviceAddress *addr)
3a9410
     ATTRIBUTE_NONNULL(1);
3a9410
+virCCWDeviceAddress *virCCWDeviceAddressFromString(const char *address)
3a9410
+    ATTRIBUTE_NONNULL(1);
3a9410
+
3a9410
 int virCCWDeviceAddressIncrement(virCCWDeviceAddress *addr);
3a9410
 
3a9410
 int virCCWDeviceAddressParseFromString(const char *address,
3a9410
-- 
3a9410
2.39.1
3a9410