|
|
9de337 |
From 27dee7b5a4152ceea00662a6f112c994d7f2b818 Mon Sep 17 00:00:00 2001
|
|
|
9de337 |
Message-Id: <27dee7b5a4152ceea00662a6f112c994d7f2b818@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 +
|
|
|
9de337 |
src/qemu/qemu_conf.c | 29 ++++++++++++++++++-----------
|
|
|
9de337 |
src/util/virscsi.c | 19 +++++++++++++++++++
|
|
|
d76c62 |
src/util/virscsi.h | 5 +++++
|
|
|
9de337 |
src/util/virutil.c | 24 ++++++------------------
|
|
|
9de337 |
src/util/virutil.h | 2 --
|
|
|
9de337 |
6 files changed, 49 insertions(+), 31 deletions(-)
|
|
|
d76c62 |
|
|
|
d76c62 |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
9de337 |
index 43493ea76e..0f701ed1ae 100644
|
|
|
d76c62 |
--- a/src/libvirt_private.syms
|
|
|
d76c62 |
+++ b/src/libvirt_private.syms
|
|
|
9de337 |
@@ -3168,6 +3168,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
|
|
|
9de337 |
index 2beef89cd1..90ff7f56f0 100644
|
|
|
d76c62 |
--- a/src/qemu/qemu_conf.c
|
|
|
d76c62 |
+++ b/src/qemu/qemu_conf.c
|
|
|
9de337 |
@@ -1500,7 +1500,7 @@ qemuCheckUnprivSGIO(GHashTable *sharedDevices,
|
|
|
9de337 |
if (!(virHashLookup(sharedDevices, key)))
|
|
|
9de337 |
return 0;
|
|
|
9de337 |
|
|
|
9de337 |
- if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
|
|
|
9de337 |
+ if (virGetDeviceUnprivSGIO(sysfs_path, &val) < 0)
|
|
|
9de337 |
return -1;
|
|
|
9de337 |
|
|
|
9de337 |
/* Error message on failure needs to be handled in caller
|
|
|
9de337 |
@@ -1852,39 +1852,46 @@ qemuSetUnprivSGIO(virDomainDeviceDef *dev)
|
|
|
9de337 |
virDomainDiskDef *disk = NULL;
|
|
|
9de337 |
virDomainHostdevDef *hostdev = NULL;
|
|
|
d76c62 |
g_autofree char *sysfs_path = NULL;
|
|
|
d76c62 |
- g_autofree char *hostdev_path = NULL;
|
|
|
9de337 |
- const char *path = NULL;
|
|
|
d76c62 |
int val = 0;
|
|
|
d76c62 |
|
|
|
9de337 |
/* "sgio" is only valid for block disk; cdrom
|
|
|
9de337 |
* and floopy disk can have empty source.
|
|
|
9de337 |
*/
|
|
|
9de337 |
if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
|
|
|
9de337 |
+ const char *path;
|
|
|
9de337 |
+
|
|
|
9de337 |
disk = dev->data.disk;
|
|
|
9de337 |
+ path = virDomainDiskGetSource(disk);
|
|
|
9de337 |
|
|
|
9de337 |
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
|
|
|
9de337 |
!virStorageSourceIsBlockLocal(disk->src))
|
|
|
d76c62 |
return 0;
|
|
|
d76c62 |
|
|
|
9de337 |
- path = virDomainDiskGetSource(disk);
|
|
|
d76c62 |
+ if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
|
|
|
d76c62 |
+ return -1;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
} else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
|
|
|
9de337 |
+ virDomainHostdevSubsysSCSI *scsisrc;
|
|
|
9de337 |
+ virDomainHostdevSubsysSCSIHost *scsihostsrc;
|
|
|
9de337 |
+
|
|
|
d76c62 |
hostdev = dev->data.hostdev;
|
|
|
9de337 |
+ scsisrc = &hostdev->source.subsys.u.scsi;
|
|
|
9de337 |
+ 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)
|
|
|
9de337 |
@@ -1902,7 +1909,7 @@ qemuSetUnprivSGIO(virDomainDeviceDef *dev)
|
|
|
9de337 |
* virSetDeviceUnprivSGIO, to report an error for unsupported unpriv_sgio.
|
|
|
9de337 |
*/
|
|
|
9de337 |
if ((virFileExists(sysfs_path) || val == 1) &&
|
|
|
9de337 |
- virSetDeviceUnprivSGIO(path, NULL, val) < 0)
|
|
|
9de337 |
+ virSetDeviceUnprivSGIO(sysfs_path, val) < 0)
|
|
|
9de337 |
return -1;
|
|
|
9de337 |
|
|
|
9de337 |
return 0;
|
|
|
d76c62 |
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
|
|
|
9de337 |
index d6c10c0667..7a8e6b3b23 100644
|
|
|
d76c62 |
--- a/src/util/virscsi.c
|
|
|
d76c62 |
+++ b/src/util/virscsi.c
|
|
|
9de337 |
@@ -302,6 +302,25 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
|
|
|
9de337 |
}
|
|
|
d76c62 |
}
|
|
|
d76c62 |
|
|
|
9de337 |
+
|
|
|
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 |
+
|
|
|
9de337 |
virSCSIDevice *
|
|
|
d76c62 |
virSCSIDeviceNew(const char *sysfs_prefix,
|
|
|
d76c62 |
const char *adapter,
|
|
|
d76c62 |
diff --git a/src/util/virscsi.h b/src/util/virscsi.h
|
|
|
9de337 |
index 65ad15ed76..5721985939 100644
|
|
|
d76c62 |
--- a/src/util/virscsi.h
|
|
|
d76c62 |
+++ b/src/util/virscsi.h
|
|
|
9de337 |
@@ -40,6 +40,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 |
|
|
|
9de337 |
virSCSIDevice *virSCSIDeviceNew(const char *sysfs_prefix,
|
|
|
d76c62 |
const char *adapter,
|
|
|
9de337 |
diff --git a/src/util/virutil.c b/src/util/virutil.c
|
|
|
9de337 |
index 00cd56e2b2..d0fc49c39f 100644
|
|
|
9de337 |
--- a/src/util/virutil.c
|
|
|
9de337 |
+++ b/src/util/virutil.c
|
|
|
9de337 |
@@ -1382,18 +1382,13 @@ virGetUnprivSGIOSysfsPath(const char *path,
|
|
|
9de337 |
|
|
|
9de337 |
int
|
|
|
9de337 |
virSetDeviceUnprivSGIO(const char *path,
|
|
|
9de337 |
- const char *sysfs_dir,
|
|
|
9de337 |
int unpriv_sgio)
|
|
|
9de337 |
{
|
|
|
9de337 |
- char *sysfs_path = NULL;
|
|
|
9de337 |
char *val = NULL;
|
|
|
9de337 |
int ret = -1;
|
|
|
9de337 |
int rc;
|
|
|
9de337 |
|
|
|
9de337 |
- if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, sysfs_dir)))
|
|
|
9de337 |
- return -1;
|
|
|
9de337 |
-
|
|
|
9de337 |
- if (!virFileExists(sysfs_path)) {
|
|
|
9de337 |
+ if (!virFileExists(path)) {
|
|
|
9de337 |
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
9de337 |
_("unpriv_sgio is not supported by this kernel"));
|
|
|
9de337 |
goto cleanup;
|
|
|
9de337 |
@@ -1401,38 +1396,32 @@ virSetDeviceUnprivSGIO(const char *path,
|
|
|
9de337 |
|
|
|
9de337 |
val = g_strdup_printf("%d", unpriv_sgio);
|
|
|
9de337 |
|
|
|
9de337 |
- if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) {
|
|
|
9de337 |
- virReportSystemError(-rc, _("failed to set %s"), sysfs_path);
|
|
|
9de337 |
+ if ((rc = virFileWriteStr(path, val, 0)) < 0) {
|
|
|
9de337 |
+ virReportSystemError(-rc, _("failed to set %s"), path);
|
|
|
9de337 |
goto cleanup;
|
|
|
9de337 |
}
|
|
|
9de337 |
|
|
|
9de337 |
ret = 0;
|
|
|
9de337 |
cleanup:
|
|
|
9de337 |
- VIR_FREE(sysfs_path);
|
|
|
9de337 |
VIR_FREE(val);
|
|
|
9de337 |
return ret;
|
|
|
9de337 |
}
|
|
|
9de337 |
|
|
|
9de337 |
int
|
|
|
9de337 |
virGetDeviceUnprivSGIO(const char *path,
|
|
|
9de337 |
- const char *sysfs_dir,
|
|
|
9de337 |
int *unpriv_sgio)
|
|
|
9de337 |
{
|
|
|
9de337 |
- char *sysfs_path = NULL;
|
|
|
9de337 |
char *buf = NULL;
|
|
|
9de337 |
char *tmp = NULL;
|
|
|
9de337 |
int ret = -1;
|
|
|
9de337 |
|
|
|
9de337 |
- if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, sysfs_dir)))
|
|
|
9de337 |
- return -1;
|
|
|
9de337 |
-
|
|
|
9de337 |
- if (!virFileExists(sysfs_path)) {
|
|
|
9de337 |
+ if (!virFileExists(path)) {
|
|
|
9de337 |
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
9de337 |
_("unpriv_sgio is not supported by this kernel"));
|
|
|
9de337 |
goto cleanup;
|
|
|
9de337 |
}
|
|
|
9de337 |
|
|
|
9de337 |
- if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
|
|
|
9de337 |
+ if (virFileReadAll(path, 1024, &buf) < 0)
|
|
|
9de337 |
goto cleanup;
|
|
|
9de337 |
|
|
|
9de337 |
if ((tmp = strchr(buf, '\n')))
|
|
|
9de337 |
@@ -1440,13 +1429,12 @@ virGetDeviceUnprivSGIO(const char *path,
|
|
|
9de337 |
|
|
|
9de337 |
if (virStrToLong_i(buf, NULL, 10, unpriv_sgio) < 0) {
|
|
|
9de337 |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
9de337 |
- _("failed to parse value of %s"), sysfs_path);
|
|
|
9de337 |
+ _("failed to parse value of %s"), path);
|
|
|
9de337 |
goto cleanup;
|
|
|
9de337 |
}
|
|
|
9de337 |
|
|
|
9de337 |
ret = 0;
|
|
|
9de337 |
cleanup:
|
|
|
9de337 |
- VIR_FREE(sysfs_path);
|
|
|
9de337 |
VIR_FREE(buf);
|
|
|
9de337 |
return ret;
|
|
|
9de337 |
}
|
|
|
9de337 |
diff --git a/src/util/virutil.h b/src/util/virutil.h
|
|
|
9de337 |
index 854b494890..da267c6446 100644
|
|
|
9de337 |
--- a/src/util/virutil.h
|
|
|
9de337 |
+++ b/src/util/virutil.h
|
|
|
9de337 |
@@ -120,10 +120,8 @@ int virGetDeviceID(const char *path,
|
|
|
9de337 |
int *maj,
|
|
|
9de337 |
int *min) G_GNUC_NO_INLINE;
|
|
|
9de337 |
int virSetDeviceUnprivSGIO(const char *path,
|
|
|
9de337 |
- const char *sysfs_dir,
|
|
|
9de337 |
int unpriv_sgio);
|
|
|
9de337 |
int virGetDeviceUnprivSGIO(const char *path,
|
|
|
9de337 |
- const char *sysfs_dir,
|
|
|
9de337 |
int *unpriv_sgio);
|
|
|
9de337 |
char *virGetUnprivSGIOSysfsPath(const char *path,
|
|
|
9de337 |
const char *sysfs_dir);
|
|
|
d76c62 |
--
|
|
|
9de337 |
2.32.0
|
|
|
d76c62 |
|