diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index f58b9d0074297598b6913f88706fca0d70fe48b5..d69f94fadf144f25fe7fee09198059e332ee9d66 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -32,6 +32,119 @@ #define VIR_FROM_THIS VIR_FROM_DEVICE +int +virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, + virDomainDeviceInfoPtr src) +{ + /* Assume that dst is already cleared */ + + /* first a shallow copy of *everything* */ + *dst = *src; + + /* then copy whatever's left */ + dst->alias = NULL; + dst->romfile = NULL; + dst->loadparm = NULL; + + if (VIR_STRDUP(dst->alias, src->alias) < 0 || + VIR_STRDUP(dst->romfile, src->romfile) < 0 || + VIR_STRDUP(dst->loadparm, src->loadparm) < 0) + return -1; + return 0; +} + +void +virDomainDeviceInfoClear(virDomainDeviceInfoPtr info) +{ + VIR_FREE(info->alias); + memset(&info->addr, 0, sizeof(info->addr)); + info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE; + VIR_FREE(info->romfile); + VIR_FREE(info->loadparm); + info->isolationGroup = 0; + info->isolationGroupLocked = false; +} + +void +virDomainDeviceInfoFree(virDomainDeviceInfoPtr info) +{ + if (info) { + virDomainDeviceInfoClear(info); + VIR_FREE(info); + } +} + +bool +virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a, + const virDomainDeviceInfo *b) +{ + if (a->type != b->type) + return false; + + switch ((virDomainDeviceAddressType) a->type) { + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST: + /* address types below don't have any specific data */ + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: + /* the 'multi' field shouldn't be checked */ + if (a->addr.pci.domain != b->addr.pci.domain || + a->addr.pci.bus != b->addr.pci.bus || + a->addr.pci.slot != b->addr.pci.slot || + a->addr.pci.function != b->addr.pci.function) + return false; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: + if (memcmp(&a->addr.drive, &b->addr.drive, sizeof(a->addr.drive))) + return false; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL: + if (memcmp(&a->addr.vioserial, &b->addr.vioserial, sizeof(a->addr.vioserial))) + return false; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID: + if (memcmp(&a->addr.ccid, &b->addr.ccid, sizeof(a->addr.ccid))) + return false; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: + if (memcmp(&a->addr.usb, &b->addr.usb, sizeof(a->addr.usb))) + return false; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: + if (memcmp(&a->addr.spaprvio, &b->addr.spaprvio, sizeof(a->addr.spaprvio))) + return false; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: + /* the 'assigned' field denotes that the address was generated */ + if (a->addr.ccw.cssid != b->addr.ccw.cssid || + a->addr.ccw.ssid != b->addr.ccw.ssid || + a->addr.ccw.devno != b->addr.ccw.devno) + return false; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: + if (memcmp(&a->addr.isa, &b->addr.isa, sizeof(a->addr.isa))) + return false; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM: + if (memcmp(&a->addr.dimm, &b->addr.dimm, sizeof(a->addr.dimm))) + return false; + break; + } + + return true; +} + int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, bool report) { diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index 68615f6dc8607631a2f4f75ecfd1fb82f676502e..f87d6f1fc6ee8db0370d5cbadf09e5c5b0133faa 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -176,6 +176,14 @@ struct _virDomainDeviceInfo { bool isolationGroupLocked; }; +int virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, + virDomainDeviceInfoPtr src); +void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info); +void virDomainDeviceInfoFree(virDomainDeviceInfoPtr info); + +bool virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a, + const virDomainDeviceInfo *b) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, bool report); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9276cd90bbda206c66230b6f18f640d09f784dd4..d88a88e469d88f90af95febfc46cfaea1050591f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1323,15 +1323,6 @@ bool virDomainObjTaint(virDomainObjPtr obj, return true; } -static void -virDomainDeviceInfoFree(virDomainDeviceInfoPtr info) -{ - if (info) { - virDomainDeviceInfoClear(info); - VIR_FREE(info); - } -} - static void virDomainGraphicsAuthDefClear(virDomainGraphicsAuthDefPtr def) @@ -3554,77 +3545,6 @@ virDomainDeviceInfoNeedsFormat(virDomainDeviceInfoPtr info, unsigned int flags) return false; } -bool -virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a, - const virDomainDeviceInfo *b) -{ - if (a->type != b->type) - return false; - - switch ((virDomainDeviceAddressType) a->type) { - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST: - /* address types below don't have any specific data */ - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: - /* the 'multi' field shouldn't be checked */ - if (a->addr.pci.domain != b->addr.pci.domain || - a->addr.pci.bus != b->addr.pci.bus || - a->addr.pci.slot != b->addr.pci.slot || - a->addr.pci.function != b->addr.pci.function) - return false; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: - if (memcmp(&a->addr.drive, &b->addr.drive, sizeof(a->addr.drive))) - return false; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL: - if (memcmp(&a->addr.vioserial, &b->addr.vioserial, sizeof(a->addr.vioserial))) - return false; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID: - if (memcmp(&a->addr.ccid, &b->addr.ccid, sizeof(a->addr.ccid))) - return false; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: - if (memcmp(&a->addr.usb, &b->addr.usb, sizeof(a->addr.usb))) - return false; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: - if (memcmp(&a->addr.spaprvio, &b->addr.spaprvio, sizeof(a->addr.spaprvio))) - return false; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: - /* the 'assigned' field denotes that the address was generated */ - if (a->addr.ccw.cssid != b->addr.ccw.cssid || - a->addr.ccw.ssid != b->addr.ccw.ssid || - a->addr.ccw.devno != b->addr.ccw.devno) - return false; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: - if (memcmp(&a->addr.isa, &b->addr.isa, sizeof(a->addr.isa))) - return false; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM: - if (memcmp(&a->addr.dimm, &b->addr.dimm, sizeof(a->addr.dimm))) - return false; - break; - } - - return true; -} - static int virDomainDefHasDeviceAddressIterator(virDomainDefPtr def ATTRIBUTE_UNUSED, @@ -3642,39 +3562,6 @@ virDomainDefHasDeviceAddressIterator(virDomainDefPtr def ATTRIBUTE_UNUSED, } -int -virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, - virDomainDeviceInfoPtr src) -{ - /* Assume that dst is already cleared */ - - /* first a shallow copy of *everything* */ - *dst = *src; - - /* then copy whatever's left */ - dst->alias = NULL; - dst->romfile = NULL; - dst->loadparm = NULL; - - if (VIR_STRDUP(dst->alias, src->alias) < 0 || - VIR_STRDUP(dst->romfile, src->romfile) < 0 || - VIR_STRDUP(dst->loadparm, src->loadparm) < 0) - return -1; - return 0; -} - -void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info) -{ - VIR_FREE(info->alias); - memset(&info->addr, 0, sizeof(info->addr)); - info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE; - VIR_FREE(info->romfile); - VIR_FREE(info->loadparm); - info->isolationGroup = 0; - info->isolationGroupLocked = false; -} - - static bool virDomainSkipBackcompatConsole(virDomainDefPtr def, size_t idx, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index b337804597794c02d9206f4cbbbf727e81d50d34..4fef773efd930cc3d2462414cd31b95c4a4de89a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2714,9 +2714,6 @@ virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src, int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, int type); virDomainDeviceInfoPtr virDomainDeviceGetInfo(virDomainDeviceDefPtr device); -int virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, - virDomainDeviceInfoPtr src); -void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info); void virDomainTPMDefFree(virDomainTPMDefPtr def); typedef int (*virDomainDeviceInfoCallback)(virDomainDefPtr def, @@ -3341,11 +3338,6 @@ virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def, int *nparams, int maxparams); -bool -virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a, - const virDomainDeviceInfo *b) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; - int virDomainDiskSetBlockIOTune(virDomainDiskDefPtr disk, virDomainBlockIoTuneInfo *info); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c7a54d84e3d51ce040253d5636baf56e0e2fc1d4..eda4269b70e72fcd8d5ee587682cf7e89b2167db 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -89,6 +89,8 @@ virCPUModeTypeToString; # conf/device_conf.h +virDomainDeviceInfoAddressIsEqual; +virDomainDeviceInfoCopy; virInterfaceLinkFormat; virInterfaceLinkParseXML; virPCIDeviceAddressEqual; @@ -286,8 +288,6 @@ virDomainDeviceDefFree; virDomainDeviceDefParse; virDomainDeviceFindControllerModel; virDomainDeviceGetInfo; -virDomainDeviceInfoAddressIsEqual; -virDomainDeviceInfoCopy; virDomainDeviceInfoIterate; virDomainDeviceTypeToString; virDomainDiskBusTypeToString;