From nobody Mon Feb 9 00:06:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564561958; cv=none; d=zoho.com; s=zohoarc; b=SVsHi9vBJ3eCiR7dAoteYem+VorHDtxI794XqFRWQPSHlM8S/C5F2cw7mLvv3T+spdi0rWJR1KmwftIbGdhrTthAQrv2WFNbOTyTBUJn7JEjmcOLJGpcM3oMI8RBhBDG5RNy9ybERfRwdG0kOYz29kgH7xqs2FfnuMUcIm0Ymfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564561958; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6KNPLq/Zlez50LDYsdq+CVqxq76BgV6dLOs0ZyHSgL8=; b=Bwyy4mn5WbEOPSKy+lltq/S+Z+XTtCSvtocU8+4icMTGS8PVqAWEdeKdyW8oPgHSlwcrZZn80jJ4LSflPE4oBMR7OYoy6YwAZ3pzsq5QCkrILXemZpGC7sp2Zw86ApOoClEn3sgPSscPGBYy2Z2XDZJiOkIElSN7goxoms7N39c= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156456195853861.251142490404845; Wed, 31 Jul 2019 01:32:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 646D830860C6; Wed, 31 Jul 2019 08:32:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3739A60925; Wed, 31 Jul 2019 08:32:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ED1CF264CA; Wed, 31 Jul 2019 08:32:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6V8WWns027386 for ; Wed, 31 Jul 2019 04:32:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4210F5D70D; Wed, 31 Jul 2019 08:32:32 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0EE15D6B2 for ; Wed, 31 Jul 2019 08:32:31 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 31 Jul 2019 10:32:22 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/6] lib: Unify PCI address formatting X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 31 Jul 2019 08:32:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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 --- 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, virDomainHost= devDefPtr 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, virDomainN= etDefPtr 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, virDomainN= etDefPtr 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(virDomainDevic= eInfoPtr src, src->addr.pci.slot !=3D dst->addr.pci.slot || src->addr.pci.function !=3D dst->addr.pci.function) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target device PCI address %04x:%02x:%02x.%02= x " - "does not match source %04x:%02x:%02x.%02x"), + _("Target device PCI address " VIR_PCI_DEVICE_A= DDRESS_FMT + "does not match source " VIR_PCI_DEVICE_ADDRE= SS_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, =20 if (virDomainHostdevFind(vm->def, hostdev, &found) >=3D 0) { virReportError(VIR_ERR_OPERATION_FAILED, - _("target pci device %.4x:%.2x:%.2x.%.1x already ex= ists"), + _("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, =20 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:%.2= x:%.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 =3D 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, =20 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, } =20 virBufferAddLit(&buf, ",host=3D"); - 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 foun= d"), + _("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 P= CI 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 ad= dr) { char *str; =20 - 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 =3D function; =20 if (virAsprintf(&dev->name, - "%.4x:%.2x:%.2x.%.1x", + VIR_PCI_DEVICE_ADDRESS_FMT, domain, bus, slot, function) < 0) return NULL; =20 @@ -2120,7 +2121,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, struct dirent *ent; int direrr; =20 - if (virAsprintf(&pcidir, "/sys/bus/pci/devices/%04x:%02x:%02x.%x", + if (virAsprintf(&pcidir, "/sys/bus/pci/devices/" VIR_PCI_DEVICE_ADDRES= S_FMT, dev->address.domain, dev->address.bus, dev->address.slot, dev->address.function) < 0) goto cleanup; @@ -2174,7 +2175,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddr= essPtr orig, int direrr; =20 if (virAsprintf(&groupPath, - PCI_SYSFS "devices/%04x:%02x:%02x.%x/iommu_group/devic= es", + PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT "/iomm= u_group/devices", orig->domain, orig->bus, orig->slot, orig->function) <= 0) goto cleanup; =20 @@ -2323,8 +2324,9 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddre= ssPtr addr) const char *groupNumStr; unsigned int groupNum; =20 - 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; =20 if (!(devPath =3D virPCIFile(devName, "iommu_group"))) @@ -2648,7 +2650,8 @@ virPCIGetPhysicalFunction(const char *vf_sysfs_path, } =20 if ((*pf =3D virPCIGetDeviceAddressFromSysfsLink(device_link))) { - VIR_DEBUG("PF for VF device '%s': %.4x:%.2x:%.2x.%.1x", vf_sysfs_p= ath, + VIR_DEBUG("PF for VF device '%s': " VIR_PCI_DEVICE_ADDRESS_FMT, + vf_sysfs_path, (*pf)->domain, (*pf)->bus, (*pf)->slot, (*pf)->function); } =20 @@ -2806,7 +2809,7 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPt= r 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; }; =20 +#define VIR_PCI_DEVICE_ADDRESS_FMT "%.4x:%.2x:%.2x.%.1x" + struct _virPCIDeviceAddress { unsigned int domain; unsigned int bus; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list