From nobody Sun Feb 8 23:26:52 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=1564561961; cv=none; d=zoho.com; s=zohoarc; b=EWB7OzGI0jK/TO7TDGkLgBKlYsuvQD27gJSBTNiJlASGwrO1oyUZ7ThREZGQB9gQyGFEuR5H1j+IrePGOaY3nt/NZTSOGG7T4stdb3sUZhD1FEqs0nrzOD/Lj5Xp0WMAq13ovM51a8nskxbxqvXZxe72QK53WML30VFauw8PZBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564561961; 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=wgzJJ7VvvKokHz689s+a2MILPlaeoRfeiOPVcfJmqf8=; b=OM5jJ8jQTSME9QufvpUlUchj3EkmHr13XOMWGjDkMI6G9J/IJzlFyCWffzpOudsl9IIvbwX8SvwrY2s5wMFMDT8TY8D+UH3VI/3/2EJezErqhnICVeZd7xuGAGoEfNbnk4R3xEH/xSbPunJlL1VEu7T/p/VauyVoBiomqo2UuEY= 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 1564561961789378.21327795694333; Wed, 31 Jul 2019 01:32:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EDF485542; Wed, 31 Jul 2019 08:32:40 +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 E487F1001959; Wed, 31 Jul 2019 08:32:39 +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 923BF3CBD; Wed, 31 Jul 2019 08:32:39 +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 x6V8WXsR027391 for ; Wed, 31 Jul 2019 04:32:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0DCCF5D70D; Wed, 31 Jul 2019 08:32:33 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D9095D6B2 for ; Wed, 31 Jul 2019 08:32:32 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 31 Jul 2019 10:32:23 +0200 Message-Id: <72478dc22c6b846abca995d5da2e2bc065ac61e3.1564561646.git.mprivozn@redhat.com> 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 5/6] lib: Format PCI address differently 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 31 Jul 2019 08:32:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Currently, the way we format PCI address is using printf-s precision, e.g. "%.4x". This works if we don't want to print any value outside of bounds (which is usually the case). However, turns out, PCI domain can be 0x10000 which doesn't work well with our format strings. However, if we change the format string to "%04x" then we still pad small values with zeroes but also we are able to print values that are larger than four digits. In fact, this format string used by kernel to print a PCI address: "%04x:%02x:%02x.%d" The other three format strings (for bus, device and function) are changed too, so that we use the same format string as kernel. Signed-off-by: Michal Privoznik --- src/conf/device_conf.c | 4 ++-- src/conf/domain_addr.c | 10 +++++----- src/conf/domain_conf.c | 4 ++-- src/conf/node_device_conf.c | 12 ++++++------ src/util/virpci.h | 2 +- tools/virsh-domain.c | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index b28f30dfc5..4c57f0995f 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -293,8 +293,8 @@ virPCIDeviceAddressFormat(virBufferPtr buf, virPCIDeviceAddress addr, bool includeTypeInAddr) { - virBufferAsprintf(buf, "
\n", + virBufferAsprintf(buf, "
\n", includeTypeInAddr ? "type=3D'pci' " : "", addr.domain, addr.bus, diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 04c4e6d7e1..4e02c43375 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -868,7 +868,7 @@ virDomainPCIAddressReserveAddrInternal(virDomainPCIAddr= essSetPtr addrs, /* The first device decides the isolation group for the * entire bus */ bus->isolationGroup =3D isolationGroup; - VIR_DEBUG("PCI bus %.4x:%.2x assigned isolation group %u because o= f " + VIR_DEBUG("PCI bus %04x:%02x assigned isolation group %u because o= f " "first device %s", addr->domain, addr->bus, isolationGroup, addrStr); } else if (bus->isolationGroup !=3D isolationGroup && fromConfig) { @@ -879,7 +879,7 @@ virDomainPCIAddressReserveAddrInternal(virDomainPCIAddr= essSetPtr addrs, * back to the default (because at that point isolation can't * be guaranteed anymore) */ bus->isolationGroup =3D 0; - VIR_DEBUG("PCI bus %.4x:%.2x assigned isolation group %u because o= f " + VIR_DEBUG("PCI bus %04x:%02x assigned isolation group %u because o= f " "user assigned address %s", addr->domain, addr->bus, isolationGroup, addrStr); } @@ -1114,7 +1114,7 @@ virDomainPCIAddressFindUnusedFunctionOnBus(virDomainP= CIAddressBusPtr bus, =20 if (!virDomainPCIAddressFlagsCompatible(searchAddr, addrStr, bus->flag= s, flags, false, false)) { - VIR_DEBUG("PCI bus %.4x:%.2x is not compatible with the device", + VIR_DEBUG("PCI bus %04x:%02x is not compatible with the device", searchAddr->domain, searchAddr->bus); } else { while (searchAddr->slot <=3D bus->maxSlot) { @@ -1150,7 +1150,7 @@ virDomainPCIAddressFindUnusedFunctionOnBus(virDomainP= CIAddressBusPtr bus, } } =20 - VIR_DEBUG("PCI slot %.4x:%.2x:%.2x already in use", + VIR_DEBUG("PCI slot %04x:%02x:%02x already in use", searchAddr->domain, searchAddr->bus, searchAddr->slo= t); searchAddr->slot++; } @@ -1248,7 +1248,7 @@ virDomainPCIAddressGetNextAddr(virDomainPCIAddressSet= Ptr addrs, return -1; =20 success: - VIR_DEBUG("Found free PCI slot %.4x:%.2x:%.2x", + VIR_DEBUG("Found free PCI slot %04x:%02x:%02x", a.domain, a.bus, a.slot); *next_addr =3D a; return 0; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b5ab2bca93..aadb8a9162 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7091,8 +7091,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf, switch ((virDomainDeviceAddressType) info->type) { case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: if (!virPCIDeviceAddressIsEmpty(&info->addr.pci)) { - virBufferAsprintf(&attrBuf, " domain=3D'0x%.4x' bus=3D'0x%.2x'= " - "slot=3D'0x%.2x' function=3D'0x%.1x'", + virBufferAsprintf(&attrBuf, " domain=3D'0x%04x' bus=3D'0x%02x'= " + "slot=3D'0x%02x' function=3D'0x%d'", info->addr.pci.domain, info->addr.pci.bus, info->addr.pci.slot, diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 4ef92d5129..e51371de89 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -239,8 +239,8 @@ virNodeDeviceCapPCIDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); virBufferAsprintf(buf, - "
\n", + "
\n", data->pci_dev.physical_function->domain, data->pci_dev.physical_function->bus, data->pci_dev.physical_function->slot, @@ -260,8 +260,8 @@ virNodeDeviceCapPCIDefFormat(virBufferPtr buf, virBufferAdjustIndent(buf, 2); for (i =3D 0; i < data->pci_dev.num_virtual_functions; i++) { virBufferAsprintf(buf, - "
\n= ", + "
\n", data->pci_dev.virtual_functions[i]->doma= in, data->pci_dev.virtual_functions[i]->bus, data->pci_dev.virtual_functions[i]->slot, @@ -302,8 +302,8 @@ virNodeDeviceCapPCIDefFormat(virBufferPtr buf, virBufferAdjustIndent(buf, 2); for (i =3D 0; i < data->pci_dev.nIommuGroupDevices; i++) { virBufferAsprintf(buf, - "
\n", + "
\n", data->pci_dev.iommuGroupDevices[i]->domain, data->pci_dev.iommuGroupDevices[i]->bus, data->pci_dev.iommuGroupDevices[i]->slot, diff --git a/src/util/virpci.h b/src/util/virpci.h index c13e7cd407..e333146ac0 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -44,7 +44,7 @@ struct _virZPCIDeviceAddress { unsigned int fid; }; =20 -#define VIR_PCI_DEVICE_ADDRESS_FMT "%.4x:%.2x:%.2x.%.1x" +#define VIR_PCI_DEVICE_ADDRESS_FMT "%04x:%02x:%02x.%d" =20 struct _virPCIDeviceAddress { unsigned int domain; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e79dc75342..ccda71d7e0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1006,8 +1006,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) =20 virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); - virBufferAsprintf(&buf, "
\n", + virBufferAsprintf(&buf, "
\n", pciAddr.domain, pciAddr.bus, pciAddr.slot, pciAddr.function); virBufferAdjustIndent(&buf, -2); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list