Blame SOURCES/kvm-qga-commands-posix-Rework-build_guest_fsinfo_for_rea.patch

f66865
From 84bc86fdf47729bca77957a04161862ffbedbf2f Mon Sep 17 00:00:00 2001
f66865
From: Thomas Huth <thuth@redhat.com>
f66865
Date: Fri, 2 Oct 2020 10:17:40 -0400
f66865
Subject: [PATCH 01/14] qga/commands-posix: Rework
f66865
 build_guest_fsinfo_for_real_device() function
f66865
MIME-Version: 1.0
f66865
Content-Type: text/plain; charset=UTF-8
f66865
Content-Transfer-Encoding: 8bit
f66865
f66865
Message-id: <20201002101742.249169-2-thuth@redhat.com>
f66865
Patchwork-id: 98527
f66865
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 1/3] qga/commands-posix: Rework build_guest_fsinfo_for_real_device() function
f66865
Bugzilla: 1755075
f66865
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
f66865
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
f66865
RH-Acked-by: David Hildenbrand <david@redhat.com>
f66865
f66865
We are going to support non-PCI devices soon. For this we need to split
f66865
the generic GuestDiskAddress and GuestDiskAddressList memory allocation
f66865
and list chaining into a separate function first.
f66865
f66865
Signed-off-by: Thomas Huth <thuth@redhat.com>
f66865
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
f66865
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
f66865
(cherry picked from commit d9fe4f0fea31f0560dc40d3576bc6c48ad97109f)
f66865
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
f66865
---
f66865
 qga/commands-posix.c | 65 ++++++++++++++++++++++++++++----------------
f66865
 1 file changed, 41 insertions(+), 24 deletions(-)
f66865
f66865
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
f66865
index 1c1a165dae..99d6b1c8c1 100644
f66865
--- a/qga/commands-posix.c
f66865
+++ b/qga/commands-posix.c
f66865
@@ -865,28 +865,30 @@ static int build_hosts(char const *syspath, char const *host, bool ata,
f66865
     return i;
f66865
 }
f66865
 
f66865
-/* Store disk device info specified by @sysfs into @fs */
f66865
-static void build_guest_fsinfo_for_real_device(char const *syspath,
f66865
-                                               GuestFilesystemInfo *fs,
f66865
-                                               Error **errp)
f66865
+/*
f66865
+ * Store disk device info for devices on the PCI bus.
f66865
+ * Returns true if information has been stored, or false for failure.
f66865
+ */
f66865
+static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
f66865
+                                           GuestDiskAddress *disk,
f66865
+                                           Error **errp)
f66865
 {
f66865
     unsigned int pci[4], host, hosts[8], tgt[3];
f66865
     int i, nhosts = 0, pcilen;
f66865
-    GuestDiskAddress *disk;
f66865
-    GuestPCIAddress *pciaddr;
f66865
-    GuestDiskAddressList *list = NULL;
f66865
+    GuestPCIAddress *pciaddr = disk->pci_controller;
f66865
     bool has_ata = false, has_host = false, has_tgt = false;
f66865
     char *p, *q, *driver = NULL;
f66865
 #ifdef CONFIG_LIBUDEV
f66865
     struct udev *udev = NULL;
f66865
     struct udev_device *udevice = NULL;
f66865
 #endif
f66865
+    bool ret = false;
f66865
 
f66865
     p = strstr(syspath, "/devices/pci");
f66865
     if (!p || sscanf(p + 12, "%*x:%*x/%x:%x:%x.%x%n",
f66865
                      pci, pci + 1, pci + 2, pci + 3, &pcilen) < 4) {
f66865
         g_debug("only pci device is supported: sysfs path '%s'", syspath);
f66865
-        return;
f66865
+        return false;
f66865
     }
f66865
 
f66865
     p += 12 + pcilen;
f66865
@@ -907,7 +909,7 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
f66865
         }
f66865
 
f66865
         g_debug("unsupported driver or sysfs path '%s'", syspath);
f66865
-        return;
f66865
+        return false;
f66865
     }
f66865
 
f66865
     p = strstr(syspath, "/target");
f66865
@@ -933,18 +935,11 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
f66865
         }
f66865
     }
f66865
 
f66865
-    pciaddr = g_malloc0(sizeof(*pciaddr));
f66865
     pciaddr->domain = pci[0];
f66865
     pciaddr->bus = pci[1];
f66865
     pciaddr->slot = pci[2];
f66865
     pciaddr->function = pci[3];
f66865
 
f66865
-    disk = g_malloc0(sizeof(*disk));
f66865
-    disk->pci_controller = pciaddr;
f66865
-
f66865
-    list = g_malloc0(sizeof(*list));
f66865
-    list->value = disk;
f66865
-
f66865
 #ifdef CONFIG_LIBUDEV
f66865
     udev = udev_new();
f66865
     udevice = udev_device_new_from_syspath(udev, syspath);
f66865
@@ -1022,21 +1017,43 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
f66865
         goto cleanup;
f66865
     }
f66865
 
f66865
-    list->next = fs->disk;
f66865
-    fs->disk = list;
f66865
-    goto out;
f66865
+    ret = true;
f66865
 
f66865
 cleanup:
f66865
-    if (list) {
f66865
-        qapi_free_GuestDiskAddressList(list);
f66865
-    }
f66865
-out:
f66865
     g_free(driver);
f66865
 #ifdef CONFIG_LIBUDEV
f66865
     udev_unref(udev);
f66865
     udev_device_unref(udevice);
f66865
 #endif
f66865
-    return;
f66865
+    return ret;
f66865
+}
f66865
+
f66865
+/* Store disk device info specified by @sysfs into @fs */
f66865
+static void build_guest_fsinfo_for_real_device(char const *syspath,
f66865
+                                               GuestFilesystemInfo *fs,
f66865
+                                               Error **errp)
f66865
+{
f66865
+    GuestDiskAddress *disk;
f66865
+    GuestPCIAddress *pciaddr;
f66865
+    GuestDiskAddressList *list = NULL;
f66865
+    bool has_hwinf;
f66865
+
f66865
+    pciaddr = g_new0(GuestPCIAddress, 1);
f66865
+
f66865
+    disk = g_new0(GuestDiskAddress, 1);
f66865
+    disk->pci_controller = pciaddr;
f66865
+
f66865
+    list = g_new0(GuestDiskAddressList, 1);
f66865
+    list->value = disk;
f66865
+
f66865
+    has_hwinf = build_guest_fsinfo_for_pci_dev(syspath, disk, errp);
f66865
+
f66865
+    if (has_hwinf) {
f66865
+        list->next = fs->disk;
f66865
+        fs->disk = list;
f66865
+    } else {
f66865
+        qapi_free_GuestDiskAddressList(list);
f66865
+    }
f66865
 }
f66865
 
f66865
 static void build_guest_fsinfo_for_device(char const *devpath,
f66865
-- 
f66865
2.27.0
f66865