mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
lib: Unify PCI address formatting
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@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
a0a341e82a
commit
f0c50bc1ce
@ -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,
|
||||
|
@ -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,
|
||||
@ -21625,8 +21625,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,
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user