util: refactor virDomainDeviceCCWAddress into virccw.h

Refactor ccw data structure virDomainDeviceCCWAddress into util virccw.h
and rename it as virCCWDeviceAddress.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Boris Fiuczynski 2022-05-13 12:31:01 +02:00 committed by Michal Privoznik
parent 78094a4bd1
commit 45a8e3988f
10 changed files with 56 additions and 32 deletions

View File

@ -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 &&

View File

@ -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,

View File

@ -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)

View File

@ -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 *

View File

@ -15491,7 +15491,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)
{
@ -15535,7 +15535,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)
@ -16134,7 +16134,7 @@ virDomainControllerFindByType(virDomainDef *def,
int
virDomainControllerFindByCCWAddress(virDomainDef *def,
virDomainDeviceCCWAddress *addr)
virCCWDeviceAddress *addr)
{
size_t i;

View File

@ -3674,12 +3674,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);
@ -3764,7 +3764,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);

View File

@ -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

View File

@ -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 */

View File

@ -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);

31
src/util/virccw.h Normal file
View File

@ -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;
};