Blame SOURCES/kvm-qga-commands-posix-Support-fsinfo-for-non-PCI-virtio.patch

8fced6
From 250227a53c1d43d2bd8346922edb3452f3534be6 Mon Sep 17 00:00:00 2001
8fced6
From: Thomas Huth <thuth@redhat.com>
8fced6
Date: Fri, 2 Oct 2020 10:17:42 -0400
8fced6
Subject: [PATCH 03/14] qga/commands-posix: Support fsinfo for non-PCI virtio
8fced6
 devices, too
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-4-thuth@redhat.com>
8fced6
Patchwork-id: 98528
8fced6
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 3/3] qga/commands-posix: Support fsinfo for non-PCI virtio devices, too
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
QEMU on s390x uses virtio via channel I/O instead of PCI by default.
8fced6
Add a function to detect and provide information for virtio-scsi and
8fced6
virtio-block devices here, too.
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 23843c129d5e1ca360605e511a43a34faebb47c4)
8fced6
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
8fced6
---
8fced6
 qga/commands-posix.c | 42 +++++++++++++++++++++++++++++++++++++++++-
8fced6
 1 file changed, 41 insertions(+), 1 deletion(-)
8fced6
8fced6
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
8fced6
index 6db76aadd1..c86c87ed52 100644
8fced6
--- a/qga/commands-posix.c
8fced6
+++ b/qga/commands-posix.c
8fced6
@@ -1000,6 +1000,39 @@ cleanup:
8fced6
     return ret;
8fced6
 }
8fced6
 
8fced6
+/*
8fced6
+ * Store disk device info for non-PCI virtio devices (for example s390x
8fced6
+ * channel I/O devices). Returns true if information has been stored, or
8fced6
+ * false for failure.
8fced6
+ */
8fced6
+static bool build_guest_fsinfo_for_nonpci_virtio(char const *syspath,
8fced6
+                                                 GuestDiskAddress *disk,
8fced6
+                                                 Error **errp)
8fced6
+{
8fced6
+    unsigned int tgt[3];
8fced6
+    char *p;
8fced6
+
8fced6
+    if (!strstr(syspath, "/virtio") || !strstr(syspath, "/block")) {
8fced6
+        g_debug("Unsupported virtio device '%s'", syspath);
8fced6
+        return false;
8fced6
+    }
8fced6
+
8fced6
+    p = strstr(syspath, "/target");
8fced6
+    if (p && sscanf(p + 7, "%*u:%*u:%*u/%*u:%u:%u:%u",
8fced6
+                    &tgt[0], &tgt[1], &tgt[2]) == 3) {
8fced6
+        /* virtio-scsi: target*:0:<target>:<unit> */
8fced6
+        disk->bus_type = GUEST_DISK_BUS_TYPE_SCSI;
8fced6
+        disk->bus = tgt[0];
8fced6
+        disk->target = tgt[1];
8fced6
+        disk->unit = tgt[2];
8fced6
+    } else {
8fced6
+        /* virtio-blk: 1 disk per 1 device */
8fced6
+        disk->bus_type = GUEST_DISK_BUS_TYPE_VIRTIO;
8fced6
+    }
8fced6
+
8fced6
+    return true;
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
@@ -1050,7 +1083,14 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
8fced6
     udev_device_unref(udevice);
8fced6
 #endif
8fced6
 
8fced6
-    has_hwinf = build_guest_fsinfo_for_pci_dev(syspath, disk, errp);
8fced6
+    if (strstr(syspath, "/devices/pci")) {
8fced6
+        has_hwinf = build_guest_fsinfo_for_pci_dev(syspath, disk, errp);
8fced6
+    } else if (strstr(syspath, "/virtio")) {
8fced6
+        has_hwinf = build_guest_fsinfo_for_nonpci_virtio(syspath, disk, errp);
8fced6
+    } else {
8fced6
+        g_debug("Unsupported device type for '%s'", syspath);
8fced6
+        has_hwinf = false;
8fced6
+    }
8fced6
 
8fced6
     if (has_hwinf || disk->has_dev || disk->has_serial) {
8fced6
         list->next = fs->disk;
8fced6
-- 
8fced6
2.27.0
8fced6