Refactor ccw data structure virDomainDeviceCCWAddress into util virccw.h and rename it as virCCWDeviceAddress. Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> --- src/conf/device_conf.c | 8 +++---- src/conf/device_conf.h | 19 ++++++----------- src/conf/domain_addr.c | 6 +++--- src/conf/domain_addr.h | 4 ++-- src/conf/domain_conf.c | 6 +++--- src/conf/domain_conf.h | 6 +++--- src/node_device/node_device_driver.c | 2 +- src/qemu/qemu_agent.c | 4 ++-- src/qemu/qemu_agent.h | 2 +- src/util/virccw.h | 31 ++++++++++++++++++++++++++++ 10 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 src/util/virccw.h diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index cb523d3a0d..92b908b2e6 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -259,7 +259,7 @@ virPCIDeviceAddressFormat(virBuffer *buf, } bool -virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddress *addr) +virDomainDeviceCCWAddressIsValid(virCCWDeviceAddress *addr) { return addr->cssid <= VIR_DOMAIN_DEVICE_CCW_MAX_CSSID && addr->ssid <= VIR_DOMAIN_DEVICE_CCW_MAX_SSID && @@ -268,7 +268,7 @@ virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddress *addr) int virDomainDeviceCCWAddressParseXML(xmlNodePtr node, - virDomainDeviceCCWAddress *addr) + virCCWDeviceAddress *addr) { int cssid; int ssid; @@ -307,8 +307,8 @@ virDomainDeviceCCWAddressParseXML(xmlNodePtr node, } bool -virDomainDeviceCCWAddressEqual(virDomainDeviceCCWAddress *addr1, - virDomainDeviceCCWAddress *addr2) +virDomainDeviceCCWAddressEqual(virCCWDeviceAddress *addr1, + virCCWDeviceAddress *addr2) { if (addr1->cssid == addr2->cssid && addr1->ssid == addr2->ssid && diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index b6b710d313..60d90bbf19 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -27,6 +27,7 @@ #include "internal.h" #include "virthread.h" #include "virbuffer.h" +#include "virccw.h" #include "virpci.h" #include "virnetdev.h" #include "virenum.h" @@ -73,14 +74,6 @@ struct _virDomainDeviceVirtioSerialAddress { #define VIR_DOMAIN_DEVICE_CCW_MAX_SSID 3 #define VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO 65535 -typedef struct _virDomainDeviceCCWAddress virDomainDeviceCCWAddress; -struct _virDomainDeviceCCWAddress { - unsigned int cssid; - unsigned int ssid; - unsigned int devno; - bool assigned; -}; - typedef struct _virDomainDeviceCcidAddress virDomainDeviceCcidAddress; struct _virDomainDeviceCcidAddress { unsigned int controller; @@ -136,7 +129,7 @@ struct _virDomainDeviceInfo { virDomainDeviceCcidAddress ccid; virDomainDeviceUSBAddress usb; virDomainDeviceSpaprVioAddress spaprvio; - virDomainDeviceCCWAddress ccw; + virCCWDeviceAddress ccw; virDomainDeviceISAAddress isa; virDomainDeviceDimmAddress dimm; } addr; @@ -204,11 +197,11 @@ void virPCIDeviceAddressFormat(virBuffer *buf, virPCIDeviceAddress addr, bool includeTypeInAddr); -bool virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddress *addr); +bool virDomainDeviceCCWAddressIsValid(virCCWDeviceAddress *addr); int virDomainDeviceCCWAddressParseXML(xmlNodePtr node, - virDomainDeviceCCWAddress *addr); -bool virDomainDeviceCCWAddressEqual(virDomainDeviceCCWAddress *addr1, - virDomainDeviceCCWAddress *addr2); + virCCWDeviceAddress *addr); +bool virDomainDeviceCCWAddressEqual(virCCWDeviceAddress *addr1, + virCCWDeviceAddress *addr2); #define VIR_CCW_DEVICE_ADDRESS_FMT "%x.%x.%04x" int virDomainDeviceDriveAddressParseXML(xmlNodePtr node, diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 1173143635..e51056b0a9 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1304,15 +1304,15 @@ virDomainPCIAddressSetAllMulti(virDomainDef *def) char* -virDomainCCWAddressAsString(virDomainDeviceCCWAddress *addr) +virDomainCCWAddressAsString(virCCWDeviceAddress *addr) { return g_strdup_printf("%x.%x.%04x", addr->cssid, addr->ssid, addr->devno); } static int -virDomainCCWAddressIncrement(virDomainDeviceCCWAddress *addr) +virDomainCCWAddressIncrement(virCCWDeviceAddress *addr) { - virDomainDeviceCCWAddress ccwaddr = *addr; + virCCWDeviceAddress ccwaddr = *addr; /* We are not touching subchannel sets and channel subsystems */ if (++ccwaddr.devno > VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO) diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 1772ea7088..8a6e80a84d 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -199,7 +199,7 @@ void virDomainPCIAddressSetAllMulti(virDomainDef *def) struct _virDomainCCWAddressSet { GHashTable *defined; - virDomainDeviceCCWAddress next; + virCCWDeviceAddress next; }; typedef struct _virDomainCCWAddressSet virDomainCCWAddressSet; @@ -209,7 +209,7 @@ int virDomainCCWAddressAssign(virDomainDeviceInfo *dev, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); void virDomainCCWAddressSetFree(virDomainCCWAddressSet *addrs); -char* virDomainCCWAddressAsString(virDomainDeviceCCWAddress *addr) +char* virDomainCCWAddressAsString(virCCWDeviceAddress *addr) ATTRIBUTE_NONNULL(1); virDomainCCWAddressSet * diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bd2884088c..7ef65ebed5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15368,7 +15368,7 @@ virDomainDiskControllerMatch(int controller_type, int disk_bus) int virDomainDiskIndexByAddress(virDomainDef *def, virPCIDeviceAddress *pci_address, - virDomainDeviceCCWAddress *ccw_addr, + virCCWDeviceAddress *ccw_addr, unsigned int bus, unsigned int target, unsigned int unit) { @@ -15412,7 +15412,7 @@ virDomainDiskIndexByAddress(virDomainDef *def, virDomainDiskDef * virDomainDiskByAddress(virDomainDef *def, virPCIDeviceAddress *pci_address, - virDomainDeviceCCWAddress *ccw_addr, + virCCWDeviceAddress *ccw_addr, unsigned int bus, unsigned int target, unsigned int unit) @@ -16011,7 +16011,7 @@ virDomainControllerFindByType(virDomainDef *def, int virDomainControllerFindByCCWAddress(virDomainDef *def, - virDomainDeviceCCWAddress *addr) + virCCWDeviceAddress *addr) { size_t i; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 88a411d00c..5f782a7bf9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3655,12 +3655,12 @@ void virDomainRNGDefFree(virDomainRNGDef *def); int virDomainDiskIndexByAddress(virDomainDef *def, virPCIDeviceAddress *pci_controller, - virDomainDeviceCCWAddress *ccw_addr, + virCCWDeviceAddress *ccw_addr, unsigned int bus, unsigned int target, unsigned int unit); virDomainDiskDef *virDomainDiskByAddress(virDomainDef *def, virPCIDeviceAddress *pci_controller, - virDomainDeviceCCWAddress *ccw_addr, + virCCWDeviceAddress *ccw_addr, unsigned int bus, unsigned int target, unsigned int unit); @@ -3745,7 +3745,7 @@ void virDomainControllerInsertPreAlloced(virDomainDef *def, int virDomainControllerFind(const virDomainDef *def, int type, int idx); int virDomainControllerFindByType(virDomainDef *def, int type); int virDomainControllerFindByCCWAddress(virDomainDef *def, - virDomainDeviceCCWAddress *addr); + virCCWDeviceAddress *addr); int virDomainControllerFindByPCIAddress(virDomainDef *def, virPCIDeviceAddress *addr); int virDomainControllerFindUnusedIndex(virDomainDef const *def, int type); diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 1eb452b989..b9c46376f5 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -661,7 +661,7 @@ nodeDeviceObjFormatAddress(virNodeDeviceObj *obj) } case VIR_NODE_DEV_CAP_CSS_DEV: { - virDomainDeviceCCWAddress ccw_addr = { + virCCWDeviceAddress ccw_addr = { .cssid = caps->data.ccw_dev.cssid, .ssid = caps->data.ccw_dev.ssid, .devno = caps->data.ccw_dev.devno diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 4156cb0dca..f57a8d5f25 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1764,9 +1764,9 @@ qemuAgentGetDiskAddress(virJSONValue *json) GET_DISK_ADDR(pci, &addr->pci_controller.function, "function"); if ((ccw = virJSONValueObjectGet(json, "ccw-address"))) { - g_autofree virDomainDeviceCCWAddress *ccw_addr = NULL; + g_autofree virCCWDeviceAddress *ccw_addr = NULL; - ccw_addr = g_new0(virDomainDeviceCCWAddress, 1); + ccw_addr = g_new0(virCCWDeviceAddress, 1); GET_DISK_ADDR(ccw, &ccw_addr->cssid, "cssid"); if (ccw_addr->cssid == 0) /* Guest CSSID 0 is 0xfe on host */ diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h index 862f6b0a95..c07d8507ba 100644 --- a/src/qemu/qemu_agent.h +++ b/src/qemu/qemu_agent.h @@ -72,7 +72,7 @@ struct _qemuAgentDiskAddress { unsigned int target; unsigned int unit; char *devnode; - virDomainDeviceCCWAddress *ccw_addr; + virCCWDeviceAddress *ccw_addr; }; void qemuAgentDiskAddressFree(qemuAgentDiskAddress *addr); G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuAgentDiskAddress, qemuAgentDiskAddressFree); diff --git a/src/util/virccw.h b/src/util/virccw.h new file mode 100644 index 0000000000..701e13284b --- /dev/null +++ b/src/util/virccw.h @@ -0,0 +1,31 @@ +/* + * virccw.h: helper APIs for managing host CCW devices + * + * Copyright (C) 2022 IBM Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include "internal.h" + +typedef struct _virCCWDeviceAddress virCCWDeviceAddress; +struct _virCCWDeviceAddress { + unsigned int cssid; + unsigned int ssid; + unsigned int devno; + bool assigned; +}; -- 2.33.1