thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-qga-commands-posix-Move-the-udev-code-from-the-pci-t.patch

8fced6
From 3a63e2d29bb2fd92577d42aeb8fa956ae18df22e Mon Sep 17 00:00:00 2001
8fced6
From: Thomas Huth <thuth@redhat.com>
8fced6
Date: Fri, 2 Oct 2020 10:17:41 -0400
8fced6
Subject: [PATCH 02/14] qga/commands-posix: Move the udev code from the pci to
8fced6
 the generic function
8fced6
MIME-Version: 1.0
8fced6
Content-Type: text/plain; charset=UTF-8
8fced6
Content-Transfer-Encoding: 8bit
8fced6
8fced6
RH-Author: Thomas Huth <thuth@redhat.com>
8fced6
Message-id: <20201002101742.249169-3-thuth@redhat.com>
8fced6
Patchwork-id: 98526
8fced6
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 2/3] qga/commands-posix: Move the udev code from the pci to the generic 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
The libudev-related code is independent from the other pci-related code
8fced6
and can be re-used for non-pci devices (like ccw devices on s390x). Thus
8fced6
move this part to the generic function.
8fced6
8fced6
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1755075
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 43dadc431bacbc5a5baee7e256288a98a3e95ce3)
8fced6
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
8fced6
---
8fced6
 qga/commands-posix.c | 62 +++++++++++++++++++++++---------------------
8fced6
 1 file changed, 33 insertions(+), 29 deletions(-)
8fced6
8fced6
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
8fced6
index 99d6b1c8c1..6db76aadd1 100644
8fced6
--- a/qga/commands-posix.c
8fced6
+++ b/qga/commands-posix.c
8fced6
@@ -878,10 +878,6 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
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
@@ -940,26 +936,6 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
8fced6
     pciaddr->slot = pci[2];
8fced6
     pciaddr->function = pci[3];
8fced6
 
8fced6
-#ifdef CONFIG_LIBUDEV
8fced6
-    udev = udev_new();
8fced6
-    udevice = udev_device_new_from_syspath(udev, syspath);
8fced6
-    if (udev == NULL || udevice == NULL) {
8fced6
-        g_debug("failed to query udev");
8fced6
-    } else {
8fced6
-        const char *devnode, *serial;
8fced6
-        devnode = udev_device_get_devnode(udevice);
8fced6
-        if (devnode != NULL) {
8fced6
-            disk->dev = g_strdup(devnode);
8fced6
-            disk->has_dev = true;
8fced6
-        }
8fced6
-        serial = udev_device_get_property_value(udevice, "ID_SERIAL");
8fced6
-        if (serial != NULL && *serial != 0) {
8fced6
-            disk->serial = g_strdup(serial);
8fced6
-            disk->has_serial = true;
8fced6
-        }
8fced6
-    }
8fced6
-#endif
8fced6
-
8fced6
     if (strcmp(driver, "ata_piix") == 0) {
8fced6
         /* a host per ide bus, target*:0:<unit>:0 */
8fced6
         if (!has_host || !has_tgt) {
8fced6
@@ -1021,10 +997,6 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
8fced6
 
8fced6
 cleanup:
8fced6
     g_free(driver);
8fced6
-#ifdef CONFIG_LIBUDEV
8fced6
-    udev_unref(udev);
8fced6
-    udev_device_unref(udevice);
8fced6
-#endif
8fced6
     return ret;
8fced6
 }
8fced6
 
8fced6
@@ -1037,18 +1009,50 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
8fced6
     GuestPCIAddress *pciaddr;
8fced6
     GuestDiskAddressList *list = NULL;
8fced6
     bool has_hwinf;
8fced6
+#ifdef CONFIG_LIBUDEV
8fced6
+    struct udev *udev = NULL;
8fced6
+    struct udev_device *udevice = NULL;
8fced6
+#endif
8fced6
 
8fced6
     pciaddr = g_new0(GuestPCIAddress, 1);
8fced6
+    pciaddr->domain = -1;                       /* -1 means field is invalid */
8fced6
+    pciaddr->bus = -1;
8fced6
+    pciaddr->slot = -1;
8fced6
+    pciaddr->function = -1;
8fced6
 
8fced6
     disk = g_new0(GuestDiskAddress, 1);
8fced6
     disk->pci_controller = pciaddr;
8fced6
+    disk->bus_type = GUEST_DISK_BUS_TYPE_UNKNOWN;
8fced6
 
8fced6
     list = g_new0(GuestDiskAddressList, 1);
8fced6
     list->value = disk;
8fced6
 
8fced6
+#ifdef CONFIG_LIBUDEV
8fced6
+    udev = udev_new();
8fced6
+    udevice = udev_device_new_from_syspath(udev, syspath);
8fced6
+    if (udev == NULL || udevice == NULL) {
8fced6
+        g_debug("failed to query udev");
8fced6
+    } else {
8fced6
+        const char *devnode, *serial;
8fced6
+        devnode = udev_device_get_devnode(udevice);
8fced6
+        if (devnode != NULL) {
8fced6
+            disk->dev = g_strdup(devnode);
8fced6
+            disk->has_dev = true;
8fced6
+        }
8fced6
+        serial = udev_device_get_property_value(udevice, "ID_SERIAL");
8fced6
+        if (serial != NULL && *serial != 0) {
8fced6
+            disk->serial = g_strdup(serial);
8fced6
+            disk->has_serial = true;
8fced6
+        }
8fced6
+    }
8fced6
+
8fced6
+    udev_unref(udev);
8fced6
+    udev_device_unref(udevice);
8fced6
+#endif
8fced6
+
8fced6
     has_hwinf = build_guest_fsinfo_for_pci_dev(syspath, disk, errp);
8fced6
 
8fced6
-    if (has_hwinf) {
8fced6
+    if (has_hwinf || disk->has_dev || disk->has_serial) {
8fced6
         list->next = fs->disk;
8fced6
         fs->disk = list;
8fced6
     } else {
8fced6
-- 
8fced6
2.27.0
8fced6