Blame SOURCES/qemuga-qemu-ga-make-get-fsinfo-work-over-pci-bridges.patch

afde2c
From 6ae51b4e290e2c6043d028987a8c27651c6c08fa Mon Sep 17 00:00:00 2001
afde2c
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
afde2c
Date: Wed, 18 Jul 2018 12:56:41 +0200
afde2c
Subject: [PATCH 1/2] qemu-ga: make get-fsinfo work over pci bridges
afde2c
MIME-Version: 1.0
afde2c
Content-Type: text/plain; charset=UTF-8
afde2c
Content-Transfer-Encoding: 8bit
afde2c
afde2c
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
afde2c
Message-id: <20180718125642.11815-2-marcandre.lureau@redhat.com>
afde2c
Patchwork-id: 81391
afde2c
O-Subject: [RHEL-7.6 qemu-guest-agent PATCH 1/2] qemu-ga: make get-fsinfo work over pci bridges
afde2c
Bugzilla: 1567041
afde2c
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
afde2c
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
afde2c
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
afde2c
afde2c
Iterate over the PCI bridges to lookup the PCI device associated with
afde2c
the block device.
afde2c
afde2c
This allows to lookup the driver under the following syspath:
afde2c
/sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/virtio2/block/vda/vda3
afde2c
afde2c
It also works with an "old-style" Q35 libvirt hierarchy: root complex
afde2c
-> DMI-PCI bridge -> PCI-PCI bridge -> virtio controller, ex:
afde2c
/sys/devices/pci0000:00/0000:00:03.0/0000:01:01.0/0000:02:01.0/virtio1/block/vda/vda3
afde2c
afde2c
The setup can be reproduced with the following qemu command line
afde2c
(Thanks Marcel for help):
afde2c
afde2c
qemu-system-x86_64 -M q35 \
afde2c
  -device i82801b11-bridge,id=dmi2pci_bridge,bus=pcie.0
afde2c
  -device pci-bridge,id=pci_bridge,bus=dmi2pci_bridge,addr=0x1,chassis_nr=1
afde2c
  -device virtio-blk-pci,scsi=off,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1,bus=pci_bridge,addr=0x1
afde2c
afde2c
For consistency with other syspath-related debug messages, replace a
afde2c
\"%s\" in the message with '%s'.
afde2c
afde2c
Fixes:
afde2c
https://bugzilla.redhat.com/show_bug.cgi?id=1567041
afde2c
afde2c
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
afde2c
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
afde2c
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
afde2c
afde2c
(cherry picked from commit 743c71d03c20d64f2bae5fba6f26cdf5e4b1bda6)
afde2c
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
afde2c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
afde2c
---
afde2c
 qga/commands-posix.c | 23 +++++++++++++++++++----
afde2c
 1 file changed, 19 insertions(+), 4 deletions(-)
afde2c
afde2c
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
afde2c
index 0dc219d..624b0dc 100644
afde2c
--- a/qga/commands-posix.c
afde2c
+++ b/qga/commands-posix.c
afde2c
@@ -875,13 +875,28 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
afde2c
     p = strstr(syspath, "/devices/pci");
afde2c
     if (!p || sscanf(p + 12, "%*x:%*x/%x:%x:%x.%x%n",
afde2c
                      pci, pci + 1, pci + 2, pci + 3, &pcilen) < 4) {
afde2c
-        g_debug("only pci device is supported: sysfs path \"%s\"", syspath);
afde2c
+        g_debug("only pci device is supported: sysfs path '%s'", syspath);
afde2c
         return;
afde2c
     }
afde2c
 
afde2c
-    driver = get_pci_driver(syspath, (p + 12 + pcilen) - syspath, errp);
afde2c
-    if (!driver) {
afde2c
-        goto cleanup;
afde2c
+    p += 12 + pcilen;
afde2c
+    while (true) {
afde2c
+        driver = get_pci_driver(syspath, p - syspath, errp);
afde2c
+        if (driver && (g_str_equal(driver, "ata_piix") ||
afde2c
+                       g_str_equal(driver, "sym53c8xx") ||
afde2c
+                       g_str_equal(driver, "virtio-pci") ||
afde2c
+                       g_str_equal(driver, "ahci"))) {
afde2c
+            break;
afde2c
+        }
afde2c
+
afde2c
+        if (sscanf(p, "/%x:%x:%x.%x%n",
afde2c
+                          pci, pci + 1, pci + 2, pci + 3, &pcilen) == 4) {
afde2c
+            p += pcilen;
afde2c
+            continue;
afde2c
+        }
afde2c
+
afde2c
+        g_debug("unsupported driver or sysfs path '%s'", syspath);
afde2c
+        return;
afde2c
     }
afde2c
 
afde2c
     p = strstr(syspath, "/target");
afde2c
-- 
afde2c
1.8.3.1
afde2c