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

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