render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
2cf05b
From 531244b8147f8972e56b6ba2c7ecf04c072f296a Mon Sep 17 00:00:00 2001
2cf05b
Message-Id: <531244b8147f8972e56b6ba2c7ecf04c072f296a@dist-git>
2cf05b
From: Boris Fiuczynski <fiuczy@linux.ibm.com>
2cf05b
Date: Fri, 13 May 2022 12:31:02 +0200
2cf05b
Subject: [PATCH] util: refactor virDomainCCWAddressAsString into virccw
2cf05b
2cf05b
Move virDomainCCWAddressAsString into virccw and rename method as
2cf05b
virCCWDeviceAddressAsString.
2cf05b
2cf05b
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
2cf05b
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2cf05b
(cherry picked from commit 1df0a1986978dcb7d1fc139f14adbc4f85b1851f)
2cf05b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2165011
2cf05b
Signed-off-by: Thomas Huth <thuth@redhat.com>
2cf05b
---
2cf05b
 src/conf/domain_addr.c               | 12 +++---------
2cf05b
 src/conf/domain_addr.h               |  3 ---
2cf05b
 src/conf/domain_conf.c               |  2 +-
2cf05b
 src/libvirt_private.syms             |  5 ++++-
2cf05b
 src/node_device/node_device_driver.c |  2 +-
2cf05b
 src/util/meson.build                 |  1 +
2cf05b
 src/util/virccw.c                    | 29 ++++++++++++++++++++++++++++
2cf05b
 src/util/virccw.h                    |  3 +++
2cf05b
 8 files changed, 42 insertions(+), 15 deletions(-)
2cf05b
 create mode 100644 src/util/virccw.c
2cf05b
2cf05b
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
2cf05b
index d584d3b8a8..bf51ef5e5a 100644
2cf05b
--- a/src/conf/domain_addr.c
2cf05b
+++ b/src/conf/domain_addr.c
2cf05b
@@ -1286,12 +1286,6 @@ virDomainPCIAddressSetAllMulti(virDomainDef *def)
2cf05b
 }
2cf05b
 
2cf05b
 
2cf05b
-char*
2cf05b
-virDomainCCWAddressAsString(virCCWDeviceAddress *addr)
2cf05b
-{
2cf05b
-    return g_strdup_printf("%x.%x.%04x", addr->cssid, addr->ssid, addr->devno);
2cf05b
-}
2cf05b
-
2cf05b
 static int
2cf05b
 virDomainCCWAddressIncrement(virCCWDeviceAddress *addr)
2cf05b
 {
2cf05b
@@ -1317,7 +1311,7 @@ virDomainCCWAddressAssign(virDomainDeviceInfo *dev,
2cf05b
         return 0;
2cf05b
 
2cf05b
     if (!autoassign && dev->addr.ccw.assigned) {
2cf05b
-        if (!(addr = virDomainCCWAddressAsString(&dev->addr.ccw)))
2cf05b
+        if (!(addr = virCCWDeviceAddressAsString(&dev->addr.ccw)))
2cf05b
             return -1;
2cf05b
 
2cf05b
         if (virHashLookup(addrs->defined, addr)) {
2cf05b
@@ -1327,7 +1321,7 @@ virDomainCCWAddressAssign(virDomainDeviceInfo *dev,
2cf05b
             return -1;
2cf05b
         }
2cf05b
     } else if (autoassign && !dev->addr.ccw.assigned) {
2cf05b
-        if (!(addr = virDomainCCWAddressAsString(&addrs->next)))
2cf05b
+        if (!(addr = virCCWDeviceAddressAsString(&addrs->next)))
2cf05b
             return -1;
2cf05b
 
2cf05b
         while (virHashLookup(addrs->defined, addr)) {
2cf05b
@@ -1337,7 +1331,7 @@ virDomainCCWAddressAssign(virDomainDeviceInfo *dev,
2cf05b
                 return -1;
2cf05b
             }
2cf05b
             VIR_FREE(addr);
2cf05b
-            if (!(addr = virDomainCCWAddressAsString(&addrs->next)))
2cf05b
+            if (!(addr = virCCWDeviceAddressAsString(&addrs->next)))
2cf05b
                 return -1;
2cf05b
         }
2cf05b
         dev->addr.ccw = addrs->next;
2cf05b
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
2cf05b
index c8d069e07e..a67851c327 100644
2cf05b
--- a/src/conf/domain_addr.h
2cf05b
+++ b/src/conf/domain_addr.h
2cf05b
@@ -205,9 +205,6 @@ int virDomainCCWAddressAssign(virDomainDeviceInfo *dev,
2cf05b
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
2cf05b
 void virDomainCCWAddressSetFree(virDomainCCWAddressSet *addrs);
2cf05b
 
2cf05b
-char* virDomainCCWAddressAsString(virCCWDeviceAddress *addr)
2cf05b
-    ATTRIBUTE_NONNULL(1);
2cf05b
-
2cf05b
 virDomainCCWAddressSet *
2cf05b
 virDomainCCWAddressSetCreateFromDomain(virDomainDef *def)
2cf05b
     ATTRIBUTE_NONNULL(1);
2cf05b
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
2cf05b
index ad3bd56da0..17383fc878 100644
2cf05b
--- a/src/conf/domain_conf.c
2cf05b
+++ b/src/conf/domain_conf.c
2cf05b
@@ -15793,7 +15793,7 @@ virDomainNetFindIdx(virDomainDef *def, virDomainNetDef *net)
2cf05b
         alias = net->info.alias;
2cf05b
 
2cf05b
     if (CCWAddrSpecified)
2cf05b
-        addr = virDomainCCWAddressAsString(&net->info.addr.ccw);
2cf05b
+        addr = virCCWDeviceAddressAsString(&net->info.addr.ccw);
2cf05b
     else if (PCIAddrSpecified)
2cf05b
         addr = virPCIDeviceAddressAsString(&net->info.addr.pci);
2cf05b
     else
2cf05b
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
2cf05b
index 568b0f34a1..e8d3edb0fe 100644
2cf05b
--- a/src/libvirt_private.syms
2cf05b
+++ b/src/libvirt_private.syms
2cf05b
@@ -147,7 +147,6 @@ virPCIDeviceAddressParseXML;
2cf05b
 
2cf05b
 # conf/domain_addr.h
2cf05b
 virDomainCCWAddressAssign;
2cf05b
-virDomainCCWAddressAsString;
2cf05b
 virDomainCCWAddressSetCreateFromDomain;
2cf05b
 virDomainCCWAddressSetFree;
2cf05b
 virDomainPCIAddressBusIsFullyReserved;
2cf05b
@@ -1902,6 +1901,10 @@ virBufferUse;
2cf05b
 virBufferVasprintf;
2cf05b
 
2cf05b
 
2cf05b
+# util/virccw.h
2cf05b
+virCCWDeviceAddressAsString;
2cf05b
+
2cf05b
+
2cf05b
 # util/vircgroup.h
2cf05b
 virCgroupAddMachineProcess;
2cf05b
 virCgroupAddProcess;
2cf05b
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
2cf05b
index b0abf59618..e6ab4bb94c 100644
2cf05b
--- a/src/node_device/node_device_driver.c
2cf05b
+++ b/src/node_device/node_device_driver.c
2cf05b
@@ -682,7 +682,7 @@ nodeDeviceObjFormatAddress(virNodeDeviceObj *obj)
2cf05b
                 .devno = caps->data.ccw_dev.devno
2cf05b
             };
2cf05b
 
2cf05b
-            addr = virDomainCCWAddressAsString(&ccw_addr);
2cf05b
+            addr = virCCWDeviceAddressAsString(&ccw_addr);
2cf05b
             break;
2cf05b
             }
2cf05b
 
2cf05b
diff --git a/src/util/meson.build b/src/util/meson.build
2cf05b
index 24350a3e67..13ed105798 100644
2cf05b
--- a/src/util/meson.build
2cf05b
+++ b/src/util/meson.build
2cf05b
@@ -9,6 +9,7 @@ util_sources = [
2cf05b
   'virbitmap.c',
2cf05b
   'virbpf.c',
2cf05b
   'virbuffer.c',
2cf05b
+  'virccw.c',
2cf05b
   'vircgroup.c',
2cf05b
   'vircgroupbackend.c',
2cf05b
   'vircgroupv1.c',
2cf05b
diff --git a/src/util/virccw.c b/src/util/virccw.c
2cf05b
new file mode 100644
2cf05b
index 0000000000..409287b380
2cf05b
--- /dev/null
2cf05b
+++ b/src/util/virccw.c
2cf05b
@@ -0,0 +1,29 @@
2cf05b
+/*
2cf05b
+ * virccw.c: helper APIs for managing host CCW devices
2cf05b
+ *
2cf05b
+ * Copyright (C) 2022 IBM Corporation
2cf05b
+ *
2cf05b
+ * This library is free software; you can redistribute it and/or
2cf05b
+ * modify it under the terms of the GNU Lesser General Public
2cf05b
+ * License as published by the Free Software Foundation; either
2cf05b
+ * version 2.1 of the License, or (at your option) any later version.
2cf05b
+ *
2cf05b
+ * This library is distributed in the hope that it will be useful,
2cf05b
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2cf05b
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2cf05b
+ * Lesser General Public License for more details.
2cf05b
+ *
2cf05b
+ * You should have received a copy of the GNU Lesser General Public
2cf05b
+ * License along with this library.  If not, see
2cf05b
+ * <http://www.gnu.org/licenses/>.
2cf05b
+ */
2cf05b
+
2cf05b
+#include <config.h>
2cf05b
+#include "virccw.h"
2cf05b
+
2cf05b
+
2cf05b
+char*
2cf05b
+virCCWDeviceAddressAsString(virCCWDeviceAddress *addr)
2cf05b
+{
2cf05b
+    return g_strdup_printf("%x.%x.%04x", addr->cssid, addr->ssid, addr->devno);
2cf05b
+}
2cf05b
diff --git a/src/util/virccw.h b/src/util/virccw.h
2cf05b
index 701e13284b..21a03406fa 100644
2cf05b
--- a/src/util/virccw.h
2cf05b
+++ b/src/util/virccw.h
2cf05b
@@ -29,3 +29,6 @@ struct _virCCWDeviceAddress {
2cf05b
     unsigned int devno;
2cf05b
     bool         assigned;
2cf05b
 };
2cf05b
+
2cf05b
+char* virCCWDeviceAddressAsString(virCCWDeviceAddress *addr)
2cf05b
+    ATTRIBUTE_NONNULL(1);
2cf05b
-- 
2cf05b
2.39.1
2cf05b