Blame SOURCES/libvirt-RHEL-virscsi-Introduce-and-use-virSCSIDeviceGetUnprivSGIOSysfsPath.patch

073345
From 6dfdc50564c3d2147f36c4cf6c252cad7a0e9381 Mon Sep 17 00:00:00 2001
073345
Message-Id: <6dfdc50564c3d2147f36c4cf6c252cad7a0e9381@dist-git>
073345
From: Michal Privoznik <mprivozn@redhat.com>
073345
Date: Fri, 6 Mar 2020 15:51:46 +0100
073345
Subject: [PATCH] RHEL: virscsi: Introduce and use
073345
 virSCSIDeviceGetUnprivSGIOSysfsPath()
073345
073345
When constructing a path to the 'unpriv_sgio' file of given SCSI
073345
device we don't need to go through /dev/* and major() + minor()
073345
path. The generated path points to
073345
/sys/dev/block/MAJ:MIN/queue/unpriv_sgio which is wrong if the
073345
SCSI device in question is not a block device. We can generate a
073345
different path: /sys/bus/scsi/devices/X:X:X:X/unpriv_sgio where
073345
the file is directly accessible regardless of the SCSI device
073345
type.
073345
073345
https://bugzilla.redhat.com/show_bug.cgi?id=1808388
073345
073345
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
073345
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
073345
Message-Id: <20200306145149.1610286-4-abologna@redhat.com>
073345
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
073345
---
073345
 src/libvirt_private.syms |  1 +
073345
 src/qemu/qemu_conf.c     | 19 +++++++++++--------
073345
 src/util/virscsi.c       | 21 +++++++++++++++++++++
073345
 src/util/virscsi.h       |  5 +++++
073345
 4 files changed, 38 insertions(+), 8 deletions(-)
073345
073345
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
073345
index 2ad21a68bc..5e1d73c148 100644
073345
--- a/src/libvirt_private.syms
073345
+++ b/src/libvirt_private.syms
073345
@@ -2727,6 +2727,7 @@ virSCSIDeviceGetSgName;
073345
 virSCSIDeviceGetShareable;
073345
 virSCSIDeviceGetTarget;
073345
 virSCSIDeviceGetUnit;
073345
+virSCSIDeviceGetUnprivSGIOSysfsPath;
073345
 virSCSIDeviceIsAvailable;
073345
 virSCSIDeviceListAdd;
073345
 virSCSIDeviceListCount;
073345
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
073345
index a81298326f..5636277888 100644
073345
--- a/src/qemu/qemu_conf.c
073345
+++ b/src/qemu/qemu_conf.c
073345
@@ -1648,7 +1648,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
073345
     virDomainDiskDefPtr disk = NULL;
073345
     virDomainHostdevDefPtr hostdev = NULL;
073345
     char *sysfs_path = NULL;
073345
-    char *hostdev_path = NULL;
073345
     const char *path = NULL;
073345
     int val = 0;
073345
     int ret = -1;
073345
@@ -1664,24 +1663,29 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
073345
             return 0;
073345
 
073345
         path = virDomainDiskGetSource(disk);
073345
+
073345
+        if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
073345
+            goto cleanup;
073345
+
073345
     } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
073345
         hostdev = dev->data.hostdev;
073345
+        virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
073345
+        virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
073345
 
073345
         if (hostdev->source.subsys.u.scsi.protocol ==
073345
             VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)
073345
             return 0;
073345
 
073345
-        if (!(hostdev_path = qemuGetHostdevPath(hostdev)))
073345
+        if (!(sysfs_path = virSCSIDeviceGetUnprivSGIOSysfsPath(NULL,
073345
+                                                               scsihostsrc->adapter,
073345
+                                                               scsihostsrc->bus,
073345
+                                                               scsihostsrc->target,
073345
+                                                               scsihostsrc->unit)))
073345
             goto cleanup;
073345
-
073345
-        path = hostdev_path;
073345
     } else {
073345
         return 0;
073345
     }
073345
 
073345
-    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
073345
-        goto cleanup;
073345
-
073345
     /* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0.  */
073345
     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
073345
         if (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED)
073345
@@ -1705,7 +1709,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
073345
     ret = 0;
073345
 
073345
  cleanup:
073345
-    VIR_FREE(hostdev_path);
073345
     VIR_FREE(sysfs_path);
073345
     return ret;
073345
 }
073345
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
073345
index 6c3fd8a562..5aab43fc88 100644
073345
--- a/src/util/virscsi.c
073345
+++ b/src/util/virscsi.c
073345
@@ -342,6 +342,27 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
073345
 }
073345
 
073345
 
073345
+char *
073345
+virSCSIDeviceGetUnprivSGIOSysfsPath(const char *sysfs_prefix,
073345
+                                    const char *adapter,
073345
+                                    unsigned int bus,
073345
+                                    unsigned int target,
073345
+                                    unsigned long long unit)
073345
+{
073345
+    char *path = NULL;
073345
+    unsigned int adapter_id;
073345
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
073345
+
073345
+    if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
073345
+        return NULL;
073345
+
073345
+    ignore_value(virAsprintf(&path,
073345
+                             "%s/%d:%u:%u:%llu/unpriv_sgio",
073345
+                             prefix, adapter_id, bus, target, unit));
073345
+    return path;
073345
+}
073345
+
073345
+
073345
 virSCSIDevicePtr
073345
 virSCSIDeviceNew(const char *sysfs_prefix,
073345
                  const char *adapter,
073345
diff --git a/src/util/virscsi.h b/src/util/virscsi.h
073345
index 9f8b3ecf1e..5dea2a9f5d 100644
073345
--- a/src/util/virscsi.h
073345
+++ b/src/util/virscsi.h
073345
@@ -43,6 +43,11 @@ char *virSCSIDeviceGetDevName(const char *sysfs_prefix,
073345
                               unsigned int bus,
073345
                               unsigned int target,
073345
                               unsigned long long unit);
073345
+char *virSCSIDeviceGetUnprivSGIOSysfsPath(const char *sysfs_prefix,
073345
+                                          const char *adapter,
073345
+                                          unsigned int bus,
073345
+                                          unsigned int target,
073345
+                                          unsigned long long unit);
073345
 
073345
 virSCSIDevicePtr virSCSIDeviceNew(const char *sysfs_prefix,
073345
                                   const char *adapter,
073345
-- 
073345
2.25.1
073345