]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lib: Format PCI address differently
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 30 Jul 2019 14:24:39 +0000 (16:24 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 5 Aug 2019 17:42:15 +0000 (19:42 +0200)
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 <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/device_conf.c
src/conf/domain_addr.c
src/conf/domain_conf.c
src/conf/node_device_conf.c
src/util/virpci.h
tools/virsh-domain.c

index b28f30dfc5be23b87ba35a625bb11594d985878f..4c57f0995fa6913a9539b73af7210a388e178f83 100644 (file)
@@ -293,8 +293,8 @@ virPCIDeviceAddressFormat(virBufferPtr buf,
                           virPCIDeviceAddress addr,
                           bool includeTypeInAddr)
 {
-    virBufferAsprintf(buf, "<address %sdomain='0x%.4x' bus='0x%.2x' "
-                      "slot='0x%.2x' function='0x%.1x'/>\n",
+    virBufferAsprintf(buf, "<address %sdomain='0x%04x' bus='0x%02x' "
+                      "slot='0x%02x' function='0x%d'/>\n",
                       includeTypeInAddr ? "type='pci' " : "",
                       addr.domain,
                       addr.bus,
index 04c4e6d7e1c9c0bece4ab015e7ebf71820df3ff7..4e02c433758e70936d84d45d12276fe67419de0c 100644 (file)
@@ -868,7 +868,7 @@ virDomainPCIAddressReserveAddrInternal(virDomainPCIAddressSetPtr addrs,
         /* The first device decides the isolation group for the
          * entire bus */
         bus->isolationGroup = isolationGroup;
-        VIR_DEBUG("PCI bus %.4x:%.2x assigned isolation group %u because of "
+        VIR_DEBUG("PCI bus %04x:%02x assigned isolation group %u because of "
                   "first device %s",
                   addr->domain, addr->bus, isolationGroup, addrStr);
     } else if (bus->isolationGroup != isolationGroup && fromConfig) {
@@ -879,7 +879,7 @@ virDomainPCIAddressReserveAddrInternal(virDomainPCIAddressSetPtr addrs,
          * back to the default (because at that point isolation can't
          * be guaranteed anymore) */
         bus->isolationGroup = 0;
-        VIR_DEBUG("PCI bus %.4x:%.2x assigned isolation group %u because of "
+        VIR_DEBUG("PCI bus %04x:%02x assigned isolation group %u because of "
                   "user assigned address %s",
                   addr->domain, addr->bus, isolationGroup, addrStr);
     }
@@ -1114,7 +1114,7 @@ virDomainPCIAddressFindUnusedFunctionOnBus(virDomainPCIAddressBusPtr bus,
 
     if (!virDomainPCIAddressFlagsCompatible(searchAddr, addrStr, bus->flags,
                                             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 <= bus->maxSlot) {
@@ -1150,7 +1150,7 @@ virDomainPCIAddressFindUnusedFunctionOnBus(virDomainPCIAddressBusPtr bus,
                 }
             }
 
-            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->slot);
             searchAddr->slot++;
         }
@@ -1248,7 +1248,7 @@ virDomainPCIAddressGetNextAddr(virDomainPCIAddressSetPtr addrs,
     return -1;
 
  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 = a;
     return 0;
index d744524b584ae7baf42e3258d1e86711781147f7..5cd9939031562490dc1c72f6191f9e6e20632282 100644 (file)
@@ -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='0x%.4x' bus='0x%.2x' "
-                              "slot='0x%.2x' function='0x%.1x'",
+            virBufferAsprintf(&attrBuf, " domain='0x%04x' bus='0x%02x' "
+                              "slot='0x%02x' function='0x%d'",
                               info->addr.pci.domain,
                               info->addr.pci.bus,
                               info->addr.pci.slot,
index 4ef92d5129ade39c97039e168bcd410827d548c7..e51371de89e366cbdc6f37a6e73abfd6b9c21885 100644 (file)
@@ -239,8 +239,8 @@ virNodeDeviceCapPCIDefFormat(virBufferPtr buf,
         virBufferAddLit(buf, "<capability type='phys_function'>\n");
         virBufferAdjustIndent(buf, 2);
         virBufferAsprintf(buf,
-                          "<address domain='0x%.4x' bus='0x%.2x' "
-                          "slot='0x%.2x' function='0x%.1x'/>\n",
+                          "<address domain='0x%04x' bus='0x%02x' "
+                          "slot='0x%02x' function='0x%d'/>\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 = 0; i < data->pci_dev.num_virtual_functions; i++) {
                 virBufferAsprintf(buf,
-                                  "<address domain='0x%.4x' bus='0x%.2x' "
-                                  "slot='0x%.2x' function='0x%.1x'/>\n",
+                                  "<address domain='0x%04x' bus='0x%02x' "
+                                  "slot='0x%02x' function='0x%d'/>\n",
                                   data->pci_dev.virtual_functions[i]->domain,
                                   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 = 0; i < data->pci_dev.nIommuGroupDevices; i++) {
             virBufferAsprintf(buf,
-                              "<address domain='0x%.4x' bus='0x%.2x' "
-                              "slot='0x%.2x' function='0x%.1x'/>\n",
+                              "<address domain='0x%04x' bus='0x%02x' "
+                              "slot='0x%02x' function='0x%d'/>\n",
                               data->pci_dev.iommuGroupDevices[i]->domain,
                               data->pci_dev.iommuGroupDevices[i]->bus,
                               data->pci_dev.iommuGroupDevices[i]->slot,
index c13e7cd40715b6a9df9f3147248938ae9bbd1e78..e333146ac05b6e4a10f428b67f224fd27b41e5da 100644 (file)
@@ -44,7 +44,7 @@ struct _virZPCIDeviceAddress {
     unsigned int fid;
 };
 
-#define VIR_PCI_DEVICE_ADDRESS_FMT "%.4x:%.2x:%.2x.%.1x"
+#define VIR_PCI_DEVICE_ADDRESS_FMT "%04x:%02x:%02x.%d"
 
 struct _virPCIDeviceAddress {
     unsigned int domain;
index e79dc753427b373262688e90947b5e9b16ad9339..ccda71d7e004ad664eda14870b7d5e4371db68f7 100644 (file)
@@ -1006,8 +1006,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
 
         virBufferAddLit(&buf, "<source>\n");
         virBufferAdjustIndent(&buf, 2);
-        virBufferAsprintf(&buf, "<address type='pci' domain='0x%.4x'"
-                          " bus='0x%.2x' slot='0x%.2x' function='0x%.1x'/>\n",
+        virBufferAsprintf(&buf, "<address type='pci' domain='0x%04x'"
+                          " bus='0x%02x' slot='0x%02x' function='0x%d'/>\n",
                           pciAddr.domain, pciAddr.bus,
                           pciAddr.slot, pciAddr.function);
         virBufferAdjustIndent(&buf, -2);