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

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