render / rpms / libvirt

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