2cf05b
From a259f2fc77dac6fa2fd7910d4c96d231b0ea3182 Mon Sep 17 00:00:00 2001
2cf05b
Message-Id: <a259f2fc77dac6fa2fd7910d4c96d231b0ea3182@dist-git>
2cf05b
From: Boris Fiuczynski <fiuczy@linux.ibm.com>
2cf05b
Date: Fri, 13 May 2022 12:31:01 +0200
2cf05b
Subject: [PATCH] util: refactor virDomainDeviceCCWAddress into virccw.h
2cf05b
2cf05b
Refactor ccw data structure virDomainDeviceCCWAddress into util virccw.h
2cf05b
and rename it as virCCWDeviceAddress.
2cf05b
2cf05b
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
2cf05b
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2cf05b
(cherry picked from commit 45a8e3988f7b087b3b721e74ce5e6b5658b2b424)
2cf05b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2165011
2cf05b
Signed-off-by: Thomas Huth <thuth@redhat.com>
2cf05b
---
2cf05b
 src/conf/device_conf.c               |  8 +++----
2cf05b
 src/conf/device_conf.h               | 19 ++++++-----------
2cf05b
 src/conf/domain_addr.c               |  6 +++---
2cf05b
 src/conf/domain_addr.h               |  4 ++--
2cf05b
 src/conf/domain_conf.c               |  6 +++---
2cf05b
 src/conf/domain_conf.h               |  6 +++---
2cf05b
 src/node_device/node_device_driver.c |  2 +-
2cf05b
 src/qemu/qemu_agent.c                |  4 ++--
2cf05b
 src/qemu/qemu_agent.h                |  2 +-
2cf05b
 src/util/virccw.h                    | 31 ++++++++++++++++++++++++++++
2cf05b
 10 files changed, 56 insertions(+), 32 deletions(-)
2cf05b
 create mode 100644 src/util/virccw.h
2cf05b
2cf05b
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
2cf05b
index cb523d3a0d..92b908b2e6 100644
2cf05b
--- a/src/conf/device_conf.c
2cf05b
+++ b/src/conf/device_conf.c
2cf05b
@@ -259,7 +259,7 @@ virPCIDeviceAddressFormat(virBuffer *buf,
2cf05b
 }
2cf05b
 
2cf05b
 bool
2cf05b
-virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddress *addr)
2cf05b
+virDomainDeviceCCWAddressIsValid(virCCWDeviceAddress *addr)
2cf05b
 {
2cf05b
     return addr->cssid <= VIR_DOMAIN_DEVICE_CCW_MAX_CSSID &&
2cf05b
            addr->ssid <= VIR_DOMAIN_DEVICE_CCW_MAX_SSID &&
2cf05b
@@ -268,7 +268,7 @@ virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddress *addr)
2cf05b
 
2cf05b
 int
2cf05b
 virDomainDeviceCCWAddressParseXML(xmlNodePtr node,
2cf05b
-                                  virDomainDeviceCCWAddress *addr)
2cf05b
+                                  virCCWDeviceAddress *addr)
2cf05b
 {
2cf05b
     int cssid;
2cf05b
     int ssid;
2cf05b
@@ -307,8 +307,8 @@ virDomainDeviceCCWAddressParseXML(xmlNodePtr node,
2cf05b
 }
2cf05b
 
2cf05b
 bool
2cf05b
-virDomainDeviceCCWAddressEqual(virDomainDeviceCCWAddress *addr1,
2cf05b
-                               virDomainDeviceCCWAddress *addr2)
2cf05b
+virDomainDeviceCCWAddressEqual(virCCWDeviceAddress *addr1,
2cf05b
+                               virCCWDeviceAddress *addr2)
2cf05b
 {
2cf05b
     if (addr1->cssid == addr2->cssid &&
2cf05b
         addr1->ssid == addr2->ssid &&
2cf05b
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
2cf05b
index b6b710d313..60d90bbf19 100644
2cf05b
--- a/src/conf/device_conf.h
2cf05b
+++ b/src/conf/device_conf.h
2cf05b
@@ -27,6 +27,7 @@
2cf05b
 #include "internal.h"
2cf05b
 #include "virthread.h"
2cf05b
 #include "virbuffer.h"
2cf05b
+#include "virccw.h"
2cf05b
 #include "virpci.h"
2cf05b
 #include "virnetdev.h"
2cf05b
 #include "virenum.h"
2cf05b
@@ -73,14 +74,6 @@ struct _virDomainDeviceVirtioSerialAddress {
2cf05b
 #define VIR_DOMAIN_DEVICE_CCW_MAX_SSID       3
2cf05b
 #define VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO  65535
2cf05b
 
2cf05b
-typedef struct _virDomainDeviceCCWAddress virDomainDeviceCCWAddress;
2cf05b
-struct _virDomainDeviceCCWAddress {
2cf05b
-    unsigned int cssid;
2cf05b
-    unsigned int ssid;
2cf05b
-    unsigned int devno;
2cf05b
-    bool         assigned;
2cf05b
-};
2cf05b
-
2cf05b
 typedef struct _virDomainDeviceCcidAddress virDomainDeviceCcidAddress;
2cf05b
 struct _virDomainDeviceCcidAddress {
2cf05b
     unsigned int controller;
2cf05b
@@ -136,7 +129,7 @@ struct _virDomainDeviceInfo {
2cf05b
         virDomainDeviceCcidAddress ccid;
2cf05b
         virDomainDeviceUSBAddress usb;
2cf05b
         virDomainDeviceSpaprVioAddress spaprvio;
2cf05b
-        virDomainDeviceCCWAddress ccw;
2cf05b
+        virCCWDeviceAddress ccw;
2cf05b
         virDomainDeviceISAAddress isa;
2cf05b
         virDomainDeviceDimmAddress dimm;
2cf05b
     } addr;
2cf05b
@@ -204,11 +197,11 @@ void virPCIDeviceAddressFormat(virBuffer *buf,
2cf05b
                                virPCIDeviceAddress addr,
2cf05b
                                bool includeTypeInAddr);
2cf05b
 
2cf05b
-bool virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddress *addr);
2cf05b
+bool virDomainDeviceCCWAddressIsValid(virCCWDeviceAddress *addr);
2cf05b
 int virDomainDeviceCCWAddressParseXML(xmlNodePtr node,
2cf05b
-                                      virDomainDeviceCCWAddress *addr);
2cf05b
-bool virDomainDeviceCCWAddressEqual(virDomainDeviceCCWAddress *addr1,
2cf05b
-                                    virDomainDeviceCCWAddress *addr2);
2cf05b
+                                      virCCWDeviceAddress *addr);
2cf05b
+bool virDomainDeviceCCWAddressEqual(virCCWDeviceAddress *addr1,
2cf05b
+                                    virCCWDeviceAddress *addr2);
2cf05b
 #define VIR_CCW_DEVICE_ADDRESS_FMT "%x.%x.%04x"
2cf05b
 
2cf05b
 int virDomainDeviceDriveAddressParseXML(xmlNodePtr node,
2cf05b
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
2cf05b
index 49745ba881..d584d3b8a8 100644
2cf05b
--- a/src/conf/domain_addr.c
2cf05b
+++ b/src/conf/domain_addr.c
2cf05b
@@ -1287,15 +1287,15 @@ virDomainPCIAddressSetAllMulti(virDomainDef *def)
2cf05b
 
2cf05b
 
2cf05b
 char*
2cf05b
-virDomainCCWAddressAsString(virDomainDeviceCCWAddress *addr)
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(virDomainDeviceCCWAddress *addr)
2cf05b
+virDomainCCWAddressIncrement(virCCWDeviceAddress *addr)
2cf05b
 {
2cf05b
-    virDomainDeviceCCWAddress ccwaddr = *addr;
2cf05b
+    virCCWDeviceAddress ccwaddr = *addr;
2cf05b
 
2cf05b
     /* We are not touching subchannel sets and channel subsystems */
2cf05b
     if (++ccwaddr.devno > VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO)
2cf05b
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
2cf05b
index 814b556024..c8d069e07e 100644
2cf05b
--- a/src/conf/domain_addr.h
2cf05b
+++ b/src/conf/domain_addr.h
2cf05b
@@ -195,7 +195,7 @@ void virDomainPCIAddressSetAllMulti(virDomainDef *def)
2cf05b
 
2cf05b
 struct _virDomainCCWAddressSet {
2cf05b
     GHashTable *defined;
2cf05b
-    virDomainDeviceCCWAddress next;
2cf05b
+    virCCWDeviceAddress next;
2cf05b
 };
2cf05b
 typedef struct _virDomainCCWAddressSet virDomainCCWAddressSet;
2cf05b
 
2cf05b
@@ -205,7 +205,7 @@ int virDomainCCWAddressAssign(virDomainDeviceInfo *dev,
2cf05b
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
2cf05b
 void virDomainCCWAddressSetFree(virDomainCCWAddressSet *addrs);
2cf05b
 
2cf05b
-char* virDomainCCWAddressAsString(virDomainDeviceCCWAddress *addr)
2cf05b
+char* virDomainCCWAddressAsString(virCCWDeviceAddress *addr)
2cf05b
     ATTRIBUTE_NONNULL(1);
2cf05b
 
2cf05b
 virDomainCCWAddressSet *
2cf05b
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
2cf05b
index 95afd9226e..ad3bd56da0 100644
2cf05b
--- a/src/conf/domain_conf.c
2cf05b
+++ b/src/conf/domain_conf.c
2cf05b
@@ -15541,7 +15541,7 @@ virDomainDiskControllerMatch(int controller_type, int disk_bus)
2cf05b
 int
2cf05b
 virDomainDiskIndexByAddress(virDomainDef *def,
2cf05b
                             virPCIDeviceAddress *pci_address,
2cf05b
-                            virDomainDeviceCCWAddress *ccw_addr,
2cf05b
+                            virCCWDeviceAddress *ccw_addr,
2cf05b
                             unsigned int bus, unsigned int target,
2cf05b
                             unsigned int unit)
2cf05b
 {
2cf05b
@@ -15585,7 +15585,7 @@ virDomainDiskIndexByAddress(virDomainDef *def,
2cf05b
 virDomainDiskDef *
2cf05b
 virDomainDiskByAddress(virDomainDef *def,
2cf05b
                        virPCIDeviceAddress *pci_address,
2cf05b
-                       virDomainDeviceCCWAddress *ccw_addr,
2cf05b
+                       virCCWDeviceAddress *ccw_addr,
2cf05b
                        unsigned int bus,
2cf05b
                        unsigned int target,
2cf05b
                        unsigned int unit)
2cf05b
@@ -16184,7 +16184,7 @@ virDomainControllerFindByType(virDomainDef *def,
2cf05b
 
2cf05b
 int
2cf05b
 virDomainControllerFindByCCWAddress(virDomainDef *def,
2cf05b
-                                    virDomainDeviceCCWAddress *addr)
2cf05b
+                                    virCCWDeviceAddress *addr)
2cf05b
 {
2cf05b
     size_t i;
2cf05b
 
2cf05b
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
2cf05b
index 45976beb2b..930af36868 100644
2cf05b
--- a/src/conf/domain_conf.h
2cf05b
+++ b/src/conf/domain_conf.h
2cf05b
@@ -3622,12 +3622,12 @@ void virDomainRNGDefFree(virDomainRNGDef *def);
2cf05b
 
2cf05b
 int virDomainDiskIndexByAddress(virDomainDef *def,
2cf05b
                                 virPCIDeviceAddress *pci_controller,
2cf05b
-                                virDomainDeviceCCWAddress *ccw_addr,
2cf05b
+                                virCCWDeviceAddress *ccw_addr,
2cf05b
                                 unsigned int bus, unsigned int target,
2cf05b
                                 unsigned int unit);
2cf05b
 virDomainDiskDef *virDomainDiskByAddress(virDomainDef *def,
2cf05b
                                          virPCIDeviceAddress *pci_controller,
2cf05b
-                                         virDomainDeviceCCWAddress *ccw_addr,
2cf05b
+                                         virCCWDeviceAddress *ccw_addr,
2cf05b
                                          unsigned int bus,
2cf05b
                                          unsigned int target,
2cf05b
                                          unsigned int unit);
2cf05b
@@ -3712,7 +3712,7 @@ void virDomainControllerInsertPreAlloced(virDomainDef *def,
2cf05b
 int virDomainControllerFind(const virDomainDef *def, int type, int idx);
2cf05b
 int virDomainControllerFindByType(virDomainDef *def, int type);
2cf05b
 int virDomainControllerFindByCCWAddress(virDomainDef *def,
2cf05b
-                                        virDomainDeviceCCWAddress *addr);
2cf05b
+                                        virCCWDeviceAddress *addr);
2cf05b
 int virDomainControllerFindByPCIAddress(virDomainDef *def,
2cf05b
                                         virPCIDeviceAddress *addr);
2cf05b
 int virDomainControllerFindUnusedIndex(virDomainDef const *def, int type);
2cf05b
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
2cf05b
index d19ed7d948..b0abf59618 100644
2cf05b
--- a/src/node_device/node_device_driver.c
2cf05b
+++ b/src/node_device/node_device_driver.c
2cf05b
@@ -676,7 +676,7 @@ nodeDeviceObjFormatAddress(virNodeDeviceObj *obj)
2cf05b
             }
2cf05b
 
2cf05b
         case VIR_NODE_DEV_CAP_CSS_DEV: {
2cf05b
-            virDomainDeviceCCWAddress ccw_addr = {
2cf05b
+            virCCWDeviceAddress ccw_addr = {
2cf05b
                 .cssid = caps->data.ccw_dev.cssid,
2cf05b
                 .ssid = caps->data.ccw_dev.ssid,
2cf05b
                 .devno = caps->data.ccw_dev.devno
2cf05b
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
2cf05b
index 8a55044c9e..db844148a6 100644
2cf05b
--- a/src/qemu/qemu_agent.c
2cf05b
+++ b/src/qemu/qemu_agent.c
2cf05b
@@ -1769,9 +1769,9 @@ qemuAgentGetDiskAddress(virJSONValue *json)
2cf05b
     GET_DISK_ADDR(pci, &addr->pci_controller.function, "function");
2cf05b
 
2cf05b
     if ((ccw = virJSONValueObjectGet(json, "ccw-address"))) {
2cf05b
-        g_autofree virDomainDeviceCCWAddress *ccw_addr = NULL;
2cf05b
+        g_autofree virCCWDeviceAddress *ccw_addr = NULL;
2cf05b
 
2cf05b
-        ccw_addr = g_new0(virDomainDeviceCCWAddress, 1);
2cf05b
+        ccw_addr = g_new0(virCCWDeviceAddress, 1);
2cf05b
 
2cf05b
         GET_DISK_ADDR(ccw, &ccw_addr->cssid, "cssid");
2cf05b
         if (ccw_addr->cssid == 0)  /* Guest CSSID 0 is 0xfe on host */
2cf05b
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
2cf05b
index 862f6b0a95..c07d8507ba 100644
2cf05b
--- a/src/qemu/qemu_agent.h
2cf05b
+++ b/src/qemu/qemu_agent.h
2cf05b
@@ -72,7 +72,7 @@ struct _qemuAgentDiskAddress {
2cf05b
     unsigned int target;
2cf05b
     unsigned int unit;
2cf05b
     char *devnode;
2cf05b
-    virDomainDeviceCCWAddress *ccw_addr;
2cf05b
+    virCCWDeviceAddress *ccw_addr;
2cf05b
 };
2cf05b
 void qemuAgentDiskAddressFree(qemuAgentDiskAddress *addr);
2cf05b
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuAgentDiskAddress, qemuAgentDiskAddressFree);
2cf05b
diff --git a/src/util/virccw.h b/src/util/virccw.h
2cf05b
new file mode 100644
2cf05b
index 0000000000..701e13284b
2cf05b
--- /dev/null
2cf05b
+++ b/src/util/virccw.h
2cf05b
@@ -0,0 +1,31 @@
2cf05b
+/*
2cf05b
+ * virccw.h: 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
+#pragma once
2cf05b
+
2cf05b
+#include "internal.h"
2cf05b
+
2cf05b
+typedef struct _virCCWDeviceAddress virCCWDeviceAddress;
2cf05b
+struct _virCCWDeviceAddress {
2cf05b
+    unsigned int cssid;
2cf05b
+    unsigned int ssid;
2cf05b
+    unsigned int devno;
2cf05b
+    bool         assigned;
2cf05b
+};
2cf05b
-- 
2cf05b
2.39.1
2cf05b