The format string for a PCI address is copied over and over
again, often with slight adjustments. Introduce global
VIR_PCI_DEVICE_ADDRESS_FMT macro that holds the formatting string
and use it wherever possible.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_audit.c | 3 ++-
src/conf/domain_conf.c | 8 ++++----
src/libxl/libxl_driver.c | 14 +++++++++-----
src/qemu/qemu_command.c | 3 ++-
src/qemu/qemu_hotplug.c | 5 +++--
src/util/virpci.c | 19 +++++++++++--------
src/util/virpci.h | 2 ++
7 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index de7386d4c6..cc5a55a635 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -376,7 +376,8 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr
hostdev,
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
- if (virAsprintfQuiet(&address, "%.4x:%.2x:%.2x.%.1x",
+ if (virAsprintfQuiet(&address,
+ VIR_PCI_DEVICE_ADDRESS_FMT,
pcisrc->addr.domain,
pcisrc->addr.bus,
pcisrc->addr.slot,
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 441eb1a5a2..b5ab2bca93 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16992,7 +16992,7 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
if (MACAddrSpecified && PCIAddrSpecified) {
virReportError(VIR_ERR_DEVICE_MISSING,
_("no device matching MAC address %s found on "
- "%.4x:%.2x:%.2x.%.1x"),
+ VIR_PCI_DEVICE_ADDRESS_FMT),
virMacAddrFormat(&net->mac, mac),
net->info.addr.pci.domain,
net->info.addr.pci.bus,
@@ -17000,7 +17000,7 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
net->info.addr.pci.function);
} else if (PCIAddrSpecified) {
virReportError(VIR_ERR_DEVICE_MISSING,
- _("no device found on %.4x:%.2x:%.2x.%.1x"),
+ _("no device found on "
VIR_PCI_DEVICE_ADDRESS_FMT),
net->info.addr.pci.domain,
net->info.addr.pci.bus,
net->info.addr.pci.slot,
@@ -21620,8 +21620,8 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
src->addr.pci.slot != dst->addr.pci.slot ||
src->addr.pci.function != dst->addr.pci.function) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Target device PCI address %04x:%02x:%02x.%02x "
- "does not match source %04x:%02x:%02x.%02x"),
+ _("Target device PCI address "
VIR_PCI_DEVICE_ADDRESS_FMT
+ "does not match source "
VIR_PCI_DEVICE_ADDRESS_FMT),
dst->addr.pci.domain, dst->addr.pci.bus,
dst->addr.pci.slot, dst->addr.pci.function,
src->addr.pci.domain, src->addr.pci.bus,
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 492028c487..48c23b43eb 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3113,7 +3113,8 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
if (virDomainHostdevFind(vm->def, hostdev, &found) >= 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
- _("target pci device %.4x:%.2x:%.2x.%.1x already
exists"),
+ _("target pci device " VIR_PCI_DEVICE_ADDRESS_FMT
+ " already exists"),
pcisrc->addr.domain, pcisrc->addr.bus,
pcisrc->addr.slot, pcisrc->addr.function);
goto cleanup;
@@ -3132,7 +3133,8 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
if (libxl_device_pci_add(cfg->ctx, vm->def->id, &pcidev, 0) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("libxenlight failed to attach pci device
%.4x:%.2x:%.2x.%.1x"),
+ _("libxenlight failed to attach pci device "
+ VIR_PCI_DEVICE_ADDRESS_FMT),
pcisrc->addr.domain, pcisrc->addr.bus,
pcisrc->addr.slot, pcisrc->addr.function);
goto error;
@@ -3647,7 +3649,8 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
idx = virDomainHostdevFind(vm->def, hostdev, &detach);
if (idx < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
- _("host pci device %.4x:%.2x:%.2x.%.1x not found"),
+ _("host pci device " VIR_PCI_DEVICE_ADDRESS_FMT
+ " not found"),
pcisrc->addr.domain, pcisrc->addr.bus,
pcisrc->addr.slot, pcisrc->addr.function);
goto cleanup;
@@ -3655,7 +3658,8 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
if (libxlIsMultiFunctionDevice(vm->def, detach->info)) {
virReportError(VIR_ERR_OPERATION_FAILED,
- _("cannot hot unplug multifunction PCI device:
%.4x:%.2x:%.2x.%.1x"),
+ _("cannot hot unplug multifunction PCI device: "
+ VIR_PCI_DEVICE_ADDRESS_FMT),
pcisrc->addr.domain, pcisrc->addr.bus,
pcisrc->addr.slot, pcisrc->addr.function);
goto error;
@@ -3668,7 +3672,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
if (libxl_device_pci_remove(cfg->ctx, vm->def->id, &pcidev, 0) < 0)
{
virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to detach pci device "
- "%.4x:%.2x:%.2x.%.1x"),
+ VIR_PCI_DEVICE_ADDRESS_FMT),
pcisrc->addr.domain, pcisrc->addr.bus,
pcisrc->addr.slot, pcisrc->addr.function);
goto error;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1871c6ef81..c8494de785 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4933,7 +4933,8 @@ qemuBuildPCIHostdevDevStr(const virDomainDef *def,
}
virBufferAddLit(&buf, ",host=");
- virBufferAsprintf(&buf, "%.4x:%.2x:%.2x.%.1x",
+ virBufferAsprintf(&buf,
+ VIR_PCI_DEVICE_ADDRESS_FMT,
pcisrc->addr.domain,
pcisrc->addr.bus,
pcisrc->addr.slot,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7501ae5029..d8be63b71c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -5388,7 +5388,8 @@ qemuDomainDetachPrepHostdev(virDomainObjPtr vm,
switch (subsys->type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
virReportError(VIR_ERR_DEVICE_MISSING,
- _("host pci device %.4x:%.2x:%.2x.%.1x not found"),
+ _("host pci device " VIR_PCI_DEVICE_ADDRESS_FMT
+ " not found"),
pcisrc->addr.domain, pcisrc->addr.bus,
pcisrc->addr.slot, pcisrc->addr.function);
break;
@@ -5874,7 +5875,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
if (qemuIsMultiFunctionDevice(vm->def, info)) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("cannot hot unplug %s device with multifunction PCI guest
address: "
- "%.4x:%.2x:%.2x.%.1x"),
+ VIR_PCI_DEVICE_ADDRESS_FMT),
virDomainDeviceTypeToString(detach.type),
info->addr.pci.domain, info->addr.pci.bus,
info->addr.pci.slot, info->addr.pci.function);
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 6d8ddc3577..36b7f8b424 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1734,7 +1734,8 @@ virPCIDeviceAddressAsString(virPCIDeviceAddressPtr addr)
{
char *str;
- ignore_value(virAsprintf(&str, "%.4x:%.2x:%.2x.%.1x",
+ ignore_value(virAsprintf(&str,
+ VIR_PCI_DEVICE_ADDRESS_FMT,
addr->domain,
addr->bus,
addr->slot,
@@ -1761,7 +1762,7 @@ virPCIDeviceNew(unsigned int domain,
dev->address.function = function;
if (virAsprintf(&dev->name,
- "%.4x:%.2x:%.2x.%.1x",
+ VIR_PCI_DEVICE_ADDRESS_FMT,
domain, bus, slot, function) < 0)
return NULL;
@@ -2120,7 +2121,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
struct dirent *ent;
int direrr;
- if (virAsprintf(&pcidir, "/sys/bus/pci/devices/%04x:%02x:%02x.%x",
+ if (virAsprintf(&pcidir, "/sys/bus/pci/devices/"
VIR_PCI_DEVICE_ADDRESS_FMT,
dev->address.domain, dev->address.bus,
dev->address.slot, dev->address.function) < 0)
goto cleanup;
@@ -2174,7 +2175,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
int direrr;
if (virAsprintf(&groupPath,
- PCI_SYSFS "devices/%04x:%02x:%02x.%x/iommu_group/devices",
+ PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT
"/iommu_group/devices",
orig->domain, orig->bus, orig->slot, orig->function) <
0)
goto cleanup;
@@ -2323,8 +2324,9 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr)
const char *groupNumStr;
unsigned int groupNum;
- if (virAsprintf(&devName, "%.4x:%.2x:%.2x.%.1x", addr->domain,
- addr->bus, addr->slot, addr->function) < 0)
+ if (virAsprintf(&devName,
+ VIR_PCI_DEVICE_ADDRESS_FMT,
+ addr->domain, addr->bus, addr->slot, addr->function) <
0)
return -1;
if (!(devPath = virPCIFile(devName, "iommu_group")))
@@ -2648,7 +2650,8 @@ virPCIGetPhysicalFunction(const char *vf_sysfs_path,
}
if ((*pf = virPCIGetDeviceAddressFromSysfsLink(device_link))) {
- VIR_DEBUG("PF for VF device '%s': %.4x:%.2x:%.2x.%.1x",
vf_sysfs_path,
+ VIR_DEBUG("PF for VF device '%s': "
VIR_PCI_DEVICE_ADDRESS_FMT,
+ vf_sysfs_path,
(*pf)->domain, (*pf)->bus, (*pf)->slot, (*pf)->function);
}
@@ -2806,7 +2809,7 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr addr,
char **pci_sysfs_device_link)
{
if (virAsprintf(pci_sysfs_device_link,
- PCI_SYSFS "devices/%04x:%02x:%02x.%x",
+ PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT,
addr->domain, addr->bus,
addr->slot, addr->function) < 0)
return -1;
diff --git a/src/util/virpci.h b/src/util/virpci.h
index 457be3c929..c13e7cd407 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -44,6 +44,8 @@ struct _virZPCIDeviceAddress {
unsigned int fid;
};
+#define VIR_PCI_DEVICE_ADDRESS_FMT "%.4x:%.2x:%.2x.%.1x"
+
struct _virPCIDeviceAddress {
unsigned int domain;
unsigned int bus;
--
2.21.0