render / rpms / libvirt

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