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

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