render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
d76c62
From c9fc757c867d197c17350b6a9cabc63cc08105d2 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <c9fc757c867d197c17350b6a9cabc63cc08105d2@dist-git>
d76c62
From: Michal Privoznik <mprivozn@redhat.com>
d76c62
Date: Fri, 6 Mar 2020 15:52:23 +0100
d76c62
Subject: [PATCH] RHEL: virscsi: Introduce and use
d76c62
 virSCSIDeviceGetUnprivSGIOSysfsPath()
d76c62
d76c62
When constructing a path to the 'unpriv_sgio' file of given SCSI
d76c62
device we don't need to go through /dev/* and major() + minor()
d76c62
path. The generated path points to
d76c62
/sys/dev/block/MAJ:MIN/queue/unpriv_sgio which is wrong if the
d76c62
SCSI device in question is not a block device. We can generate a
d76c62
different path: /sys/bus/scsi/devices/X:X:X:X/unpriv_sgio where
d76c62
the file is directly accessible regardless of the SCSI device
d76c62
type.
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1808390
d76c62
d76c62
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
d76c62
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
d76c62
Message-Id: <20200306145226.1610708-4-abologna@redhat.com>
d76c62
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
d76c62
---
d76c62
 src/libvirt_private.syms |  1 +
d76c62
 src/qemu/qemu_conf.c     | 18 +++++++++++-------
d76c62
 src/util/virscsi.c       | 18 ++++++++++++++++++
d76c62
 src/util/virscsi.h       |  5 +++++
d76c62
 4 files changed, 35 insertions(+), 7 deletions(-)
d76c62
d76c62
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
d76c62
index 5dc99e03cf..1f97879faa 100644
d76c62
--- a/src/libvirt_private.syms
d76c62
+++ b/src/libvirt_private.syms
d76c62
@@ -2959,6 +2959,7 @@ virSCSIDeviceGetSgName;
d76c62
 virSCSIDeviceGetShareable;
d76c62
 virSCSIDeviceGetTarget;
d76c62
 virSCSIDeviceGetUnit;
d76c62
+virSCSIDeviceGetUnprivSGIOSysfsPath;
d76c62
 virSCSIDeviceIsAvailable;
d76c62
 virSCSIDeviceListAdd;
d76c62
 virSCSIDeviceListCount;
d76c62
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
d76c62
index 7aaf2862a4..6d6feb97cd 100644
d76c62
--- a/src/qemu/qemu_conf.c
d76c62
+++ b/src/qemu/qemu_conf.c
d76c62
@@ -1789,7 +1789,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
d76c62
     virDomainDiskDefPtr disk = NULL;
d76c62
     virDomainHostdevDefPtr hostdev = NULL;
d76c62
     g_autofree char *sysfs_path = NULL;
d76c62
-    g_autofree char *hostdev_path = NULL;
d76c62
     const char *path = NULL;
d76c62
     int val = 0;
d76c62
 
d76c62
@@ -1804,24 +1803,29 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
d76c62
             return 0;
d76c62
 
d76c62
         path = virDomainDiskGetSource(disk);
d76c62
+
d76c62
+        if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
d76c62
+            return -1;
d76c62
+
d76c62
     } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
d76c62
         hostdev = dev->data.hostdev;
d76c62
+        virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
d76c62
+        virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
d76c62
 
d76c62
         if (hostdev->source.subsys.u.scsi.protocol ==
d76c62
             VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)
d76c62
             return 0;
d76c62
 
d76c62
-        if (!(hostdev_path = qemuGetHostdevPath(hostdev)))
d76c62
+        if (!(sysfs_path = virSCSIDeviceGetUnprivSGIOSysfsPath(NULL,
d76c62
+                                                               scsihostsrc->adapter,
d76c62
+                                                               scsihostsrc->bus,
d76c62
+                                                               scsihostsrc->target,
d76c62
+                                                               scsihostsrc->unit)))
d76c62
             return -1;
d76c62
-
d76c62
-        path = hostdev_path;
d76c62
     } else {
d76c62
         return 0;
d76c62
     }
d76c62
 
d76c62
-    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
d76c62
-        return -1;
d76c62
-
d76c62
     /* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0.  */
d76c62
     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
d76c62
         if (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED)
d76c62
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
d76c62
index 57958c06ea..1bba4051b6 100644
d76c62
--- a/src/util/virscsi.c
d76c62
+++ b/src/util/virscsi.c
d76c62
@@ -322,6 +322,24 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
d76c62
 }
d76c62
 
d76c62
 
d76c62
+char *
d76c62
+virSCSIDeviceGetUnprivSGIOSysfsPath(const char *sysfs_prefix,
d76c62
+                                    const char *adapter,
d76c62
+                                    unsigned int bus,
d76c62
+                                    unsigned int target,
d76c62
+                                    unsigned long long unit)
d76c62
+{
d76c62
+    unsigned int adapter_id;
d76c62
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
d76c62
+
d76c62
+    if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
d76c62
+        return NULL;
d76c62
+
d76c62
+    return g_strdup_printf("%s/%d:%u:%u:%llu/unpriv_sgio",
d76c62
+                           prefix, adapter_id, bus, target, unit);
d76c62
+}
d76c62
+
d76c62
+
d76c62
 virSCSIDevicePtr
d76c62
 virSCSIDeviceNew(const char *sysfs_prefix,
d76c62
                  const char *adapter,
d76c62
diff --git a/src/util/virscsi.h b/src/util/virscsi.h
d76c62
index 51627e0c05..c040d76716 100644
d76c62
--- a/src/util/virscsi.h
d76c62
+++ b/src/util/virscsi.h
d76c62
@@ -42,6 +42,11 @@ char *virSCSIDeviceGetDevName(const char *sysfs_prefix,
d76c62
                               unsigned int bus,
d76c62
                               unsigned int target,
d76c62
                               unsigned long long unit);
d76c62
+char *virSCSIDeviceGetUnprivSGIOSysfsPath(const char *sysfs_prefix,
d76c62
+                                          const char *adapter,
d76c62
+                                          unsigned int bus,
d76c62
+                                          unsigned int target,
d76c62
+                                          unsigned long long unit);
d76c62
 
d76c62
 virSCSIDevicePtr virSCSIDeviceNew(const char *sysfs_prefix,
d76c62
                                   const char *adapter,
d76c62
-- 
d76c62
2.25.1
d76c62