yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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