2020-11-03 12:01:38 +00:00
|
|
|
From f66beef45382be2aed6d021a409e90f8114c8671 Mon Sep 17 00:00:00 2001
|
|
|
|
Message-Id: <f66beef45382be2aed6d021a409e90f8114c8671@dist-git>
|
2020-04-28 09:33:33 +00:00
|
|
|
From: Michal Privoznik <mprivozn@redhat.com>
|
2020-11-03 12:01:38 +00:00
|
|
|
Date: Fri, 6 Mar 2020 15:52:21 +0100
|
2020-04-28 09:33:33 +00:00
|
|
|
Subject: [PATCH] RHEL: virscsi: Check device type before getting it's /dev
|
|
|
|
node name
|
|
|
|
|
|
|
|
Not all SCSI devices are block devices, therefore
|
|
|
|
/sys/bus/scsi/devices/X:X:X:X/block/ directory does not always
|
|
|
|
exist. Check if the SCSI device is a block device beforehand.
|
|
|
|
|
2020-11-03 12:01:38 +00:00
|
|
|
https://bugzilla.redhat.com/show_bug.cgi?id=1808390
|
2020-04-28 09:33:33 +00:00
|
|
|
|
|
|
|
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
|
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
|
2020-11-03 12:01:38 +00:00
|
|
|
Message-Id: <20200306145226.1610708-2-abologna@redhat.com>
|
2020-04-28 09:33:33 +00:00
|
|
|
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
|
---
|
2020-11-03 12:01:38 +00:00
|
|
|
src/util/virscsi.c | 146 ++++++++++++++++++++++++++++++---
|
2020-04-28 09:33:33 +00:00
|
|
|
tests/virscsidata/0-0-0-0/type | 1 +
|
|
|
|
tests/virscsidata/1-0-0-0/type | 1 +
|
2020-11-03 12:01:38 +00:00
|
|
|
3 files changed, 137 insertions(+), 11 deletions(-)
|
2020-04-28 09:33:33 +00:00
|
|
|
create mode 100644 tests/virscsidata/0-0-0-0/type
|
|
|
|
create mode 100644 tests/virscsidata/1-0-0-0/type
|
|
|
|
|
|
|
|
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
|
2020-11-03 12:01:38 +00:00
|
|
|
index 06659c45c7..c40857977f 100644
|
2020-04-28 09:33:33 +00:00
|
|
|
--- a/src/util/virscsi.c
|
|
|
|
+++ b/src/util/virscsi.c
|
2020-11-03 12:01:38 +00:00
|
|
|
@@ -50,6 +50,32 @@ struct _virUsedByInfo {
|
|
|
|
typedef struct _virUsedByInfo virUsedByInfo;
|
|
|
|
typedef virUsedByInfo *virUsedByInfoPtr;
|
2020-04-28 09:33:33 +00:00
|
|
|
|
|
|
|
+
|
|
|
|
+/* Keep in sync with scsi/scsi_proto.h */
|
|
|
|
+typedef enum {
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_NONE = -1,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_DISK = 0x00,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_TAPE = 0x01,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_PRINTER = 0x02,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_PROCESSOR = 0x03,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_WORM = 0x04,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_ROM = 0x05,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_SCANNER = 0x06,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_MOD = 0x07,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_MEDIUM_CHANGER = 0x08,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_COMM = 0x09,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_RAID = 0x0c,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_ENCLOSURE = 0x0d,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_RBC = 0x0e,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_OSD = 0x11,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_ZBC = 0x14,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_WLUN = 0x1e,
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_NO_LUN = 0x7f,
|
|
|
|
+
|
|
|
|
+ VIR_SCSI_DEVICE_TYPE_LAST,
|
|
|
|
+} virSCSIDeviceType;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
struct _virSCSIDevice {
|
|
|
|
unsigned int adapter;
|
|
|
|
unsigned int bus;
|
2020-11-03 12:01:38 +00:00
|
|
|
@@ -134,6 +160,84 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
|
2020-04-28 09:33:33 +00:00
|
|
|
return sg;
|
|
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+static int
|
|
|
|
+virSCSIDeviceGetType(const char *prefix,
|
|
|
|
+ unsigned int adapter,
|
|
|
|
+ unsigned int bus,
|
|
|
|
+ unsigned int target,
|
|
|
|
+ unsigned long long unit,
|
|
|
|
+ virSCSIDeviceType *type)
|
|
|
|
+{
|
|
|
|
+ int intType;
|
|
|
|
+
|
|
|
|
+ if (virFileReadValueInt(&intType,
|
|
|
|
+ "%s/%d:%u:%u:%llu/type",
|
|
|
|
+ prefix, adapter, bus, target, unit) < 0)
|
|
|
|
+ return -1;
|
|
|
|
+
|
|
|
|
+ switch (intType) {
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_DISK:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_TAPE:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_PRINTER:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_PROCESSOR:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_WORM:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_ROM:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_SCANNER:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_MOD:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_MEDIUM_CHANGER:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_COMM:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_RAID:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_ENCLOSURE:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_RBC:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_OSD:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_ZBC:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_WLUN:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_NO_LUN:
|
|
|
|
+ *type = intType;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
+ _("unknown SCSI device type: %x"),
|
|
|
|
+ intType);
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+static char *
|
|
|
|
+virSCSIDeviceGetDevNameBlock(const char *prefix,
|
|
|
|
+ unsigned int adapter,
|
|
|
|
+ unsigned int bus,
|
|
|
|
+ unsigned int target,
|
|
|
|
+ unsigned long long unit)
|
|
|
|
+{
|
|
|
|
+ DIR *dir = NULL;
|
|
|
|
+ struct dirent *entry;
|
2020-11-03 12:01:38 +00:00
|
|
|
+ g_autofree char *path = NULL;
|
2020-04-28 09:33:33 +00:00
|
|
|
+ char *name = NULL;
|
|
|
|
+
|
2020-11-03 12:01:38 +00:00
|
|
|
+ path = g_strdup_printf("%s/%d:%u:%u:%llu/block",
|
|
|
|
+ prefix, adapter, bus, target, unit);
|
2020-04-28 09:33:33 +00:00
|
|
|
+
|
|
|
|
+ if (virDirOpen(&dir, path) < 0)
|
|
|
|
+ goto cleanup;
|
|
|
|
+
|
|
|
|
+ while (virDirRead(dir, &entry, path) > 0) {
|
2020-11-03 12:01:38 +00:00
|
|
|
+ name = g_strdup(entry->d_name);
|
2020-04-28 09:33:33 +00:00
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cleanup:
|
|
|
|
+ VIR_DIR_CLOSE(dir);
|
2020-11-03 12:01:38 +00:00
|
|
|
+
|
2020-04-28 09:33:33 +00:00
|
|
|
+ return name;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
/* Returns device name (e.g. "sdc") on success, or NULL
|
|
|
|
* on failure.
|
|
|
|
*/
|
2020-11-03 12:01:38 +00:00
|
|
|
@@ -144,32 +248,52 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
|
2020-04-28 09:33:33 +00:00
|
|
|
unsigned int target,
|
|
|
|
unsigned long long unit)
|
|
|
|
{
|
|
|
|
- DIR *dir = NULL;
|
|
|
|
- struct dirent *entry;
|
2020-11-03 12:01:38 +00:00
|
|
|
- g_autofree char *path = NULL;
|
2020-04-28 09:33:33 +00:00
|
|
|
char *name = NULL;
|
|
|
|
unsigned int adapter_id;
|
|
|
|
+ virSCSIDeviceType type;
|
|
|
|
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
|
|
|
|
|
|
|
|
if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2020-11-03 12:01:38 +00:00
|
|
|
- path = g_strdup_printf("%s/%d:%u:%u:%llu/block", prefix, adapter_id, bus,
|
|
|
|
- target, unit);
|
2020-04-28 09:33:33 +00:00
|
|
|
+ if (virSCSIDeviceGetType(prefix, adapter_id,
|
|
|
|
+ bus, target, unit, &type) < 0)
|
2020-11-03 12:01:38 +00:00
|
|
|
+ return NULL;
|
2020-04-28 09:33:33 +00:00
|
|
|
|
|
|
|
- if (virDirOpen(&dir, path) < 0)
|
|
|
|
- goto cleanup;
|
|
|
|
+ switch (type) {
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_DISK:
|
|
|
|
+ name = virSCSIDeviceGetDevNameBlock(prefix, adapter_id, bus, target, unit);
|
|
|
|
+ break;
|
|
|
|
|
|
|
|
- while (virDirRead(dir, &entry, path) > 0) {
|
2020-11-03 12:01:38 +00:00
|
|
|
- name = g_strdup(entry->d_name);
|
2020-04-28 09:33:33 +00:00
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_TAPE:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_PRINTER:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_PROCESSOR:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_WORM:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_ROM:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_SCANNER:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_MOD:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_MEDIUM_CHANGER:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_COMM:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_RAID:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_ENCLOSURE:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_RBC:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_OSD:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_ZBC:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_WLUN:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_NO_LUN:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_NONE:
|
|
|
|
+ case VIR_SCSI_DEVICE_TYPE_LAST:
|
|
|
|
+ default:
|
|
|
|
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
+ _("unsupported SCSI device type: %x"),
|
|
|
|
+ type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
- cleanup:
|
|
|
|
- VIR_DIR_CLOSE(dir);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
virSCSIDevicePtr
|
|
|
|
virSCSIDeviceNew(const char *sysfs_prefix,
|
|
|
|
const char *adapter,
|
|
|
|
diff --git a/tests/virscsidata/0-0-0-0/type b/tests/virscsidata/0-0-0-0/type
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000..573541ac97
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/tests/virscsidata/0-0-0-0/type
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+0
|
|
|
|
diff --git a/tests/virscsidata/1-0-0-0/type b/tests/virscsidata/1-0-0-0/type
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000..573541ac97
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/tests/virscsidata/1-0-0-0/type
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+0
|
|
|
|
--
|
|
|
|
2.25.1
|
|
|
|
|