|
|
1b5f1d |
From 5b96a8773d33af9822f6b6ccddc8f372841895a6 Mon Sep 17 00:00:00 2001
|
|
|
1b5f1d |
Message-Id: <5b96a8773d33af9822f6b6ccddc8f372841895a6@dist-git>
|
|
|
d76c62 |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
d76c62 |
Date: Fri, 6 Mar 2020 15:52:22 +0100
|
|
|
d76c62 |
Subject: [PATCH] RHEL: virscsi: Support TAPEs in virSCSIDeviceGetDevName()
|
|
|
d76c62 |
|
|
|
d76c62 |
If the SCSI device we want to get /dev node name for is TAPE
|
|
|
d76c62 |
device we need to look at 'tape' symlink in the sysfs dir
|
|
|
d76c62 |
corresponding to the device.
|
|
|
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-3-abologna@redhat.com>
|
|
|
d76c62 |
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
d76c62 |
---
|
|
|
9de337 |
src/util/virscsi.c | 27 +++++++++++++++
|
|
|
d76c62 |
tests/virscsidata/2-0-0-0/model | 1 +
|
|
|
d76c62 |
tests/virscsidata/2-0-0-0/scsi_tape/st0/dev | 1 +
|
|
|
d76c62 |
tests/virscsidata/2-0-0-0/sg3/dev | 1 +
|
|
|
d76c62 |
tests/virscsidata/2-0-0-0/tape | 1 +
|
|
|
d76c62 |
tests/virscsidata/2-0-0-0/type | 1 +
|
|
|
d76c62 |
tests/virscsidata/2-0-0-0/vendor | 1 +
|
|
|
d76c62 |
tests/virscsidata/sg3 | 0
|
|
|
d76c62 |
tests/virscsitest.c | 38 ++++++++++++++++++---
|
|
|
9de337 |
9 files changed, 66 insertions(+), 5 deletions(-)
|
|
|
d76c62 |
create mode 100644 tests/virscsidata/2-0-0-0/model
|
|
|
d76c62 |
create mode 100644 tests/virscsidata/2-0-0-0/scsi_tape/st0/dev
|
|
|
d76c62 |
create mode 100644 tests/virscsidata/2-0-0-0/sg3/dev
|
|
|
d76c62 |
create mode 120000 tests/virscsidata/2-0-0-0/tape
|
|
|
d76c62 |
create mode 100644 tests/virscsidata/2-0-0-0/type
|
|
|
d76c62 |
create mode 100644 tests/virscsidata/2-0-0-0/vendor
|
|
|
d76c62 |
create mode 100644 tests/virscsidata/sg3
|
|
|
d76c62 |
|
|
|
d76c62 |
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
|
|
|
aa5bf2 |
index 770f727cac..6165196423 100644
|
|
|
d76c62 |
--- a/src/util/virscsi.c
|
|
|
d76c62 |
+++ b/src/util/virscsi.c
|
|
|
9de337 |
@@ -224,6 +224,31 @@ virSCSIDeviceGetDevNameBlock(const char *prefix,
|
|
|
d76c62 |
}
|
|
|
d76c62 |
|
|
|
d76c62 |
|
|
|
d76c62 |
+static char *
|
|
|
d76c62 |
+virSCSIDeviceGetDevNameTape(const char *prefix,
|
|
|
d76c62 |
+ unsigned int adapter,
|
|
|
d76c62 |
+ unsigned int bus,
|
|
|
d76c62 |
+ unsigned int target,
|
|
|
d76c62 |
+ unsigned long long unit)
|
|
|
d76c62 |
+{
|
|
|
d76c62 |
+ g_autofree char *path = NULL;
|
|
|
d76c62 |
+ g_autofree char *resolvedPath = NULL;
|
|
|
d76c62 |
+ g_autoptr(GError) err = NULL;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ path = g_strdup_printf("%s/%d:%u:%u:%llu/tape",
|
|
|
d76c62 |
+ prefix, adapter, bus, target, unit);
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ if (!(resolvedPath = g_file_read_link(path, &err))) {
|
|
|
d76c62 |
+ virReportError(VIR_ERR_SYSTEM_ERROR,
|
|
|
d76c62 |
+ _("Unable to read link: %s"),
|
|
|
d76c62 |
+ err->message);
|
|
|
d76c62 |
+ return NULL;
|
|
|
d76c62 |
+ }
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ return g_path_get_basename(resolvedPath);
|
|
|
d76c62 |
+}
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+
|
|
|
d76c62 |
/* Returns device name (e.g. "sdc") on success, or NULL
|
|
|
d76c62 |
* on failure.
|
|
|
d76c62 |
*/
|
|
|
9de337 |
@@ -250,6 +275,8 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
|
|
|
9de337 |
return virSCSIDeviceGetDevNameBlock(prefix, adapter_id, bus, target, unit);
|
|
|
d76c62 |
|
|
|
d76c62 |
case VIR_SCSI_DEVICE_TYPE_TAPE:
|
|
|
9de337 |
+ return virSCSIDeviceGetDevNameTape(prefix, adapter_id, bus, target, unit);
|
|
|
d76c62 |
+
|
|
|
d76c62 |
case VIR_SCSI_DEVICE_TYPE_PRINTER:
|
|
|
d76c62 |
case VIR_SCSI_DEVICE_TYPE_PROCESSOR:
|
|
|
d76c62 |
case VIR_SCSI_DEVICE_TYPE_WORM:
|
|
|
d76c62 |
diff --git a/tests/virscsidata/2-0-0-0/model b/tests/virscsidata/2-0-0-0/model
|
|
|
d76c62 |
new file mode 100644
|
|
|
d76c62 |
index 0000000000..d2ab4715c3
|
|
|
d76c62 |
--- /dev/null
|
|
|
d76c62 |
+++ b/tests/virscsidata/2-0-0-0/model
|
|
|
d76c62 |
@@ -0,0 +1 @@
|
|
|
d76c62 |
+scsi_debug
|
|
|
d76c62 |
diff --git a/tests/virscsidata/2-0-0-0/scsi_tape/st0/dev b/tests/virscsidata/2-0-0-0/scsi_tape/st0/dev
|
|
|
d76c62 |
new file mode 100644
|
|
|
d76c62 |
index 0000000000..3dd777e840
|
|
|
d76c62 |
--- /dev/null
|
|
|
d76c62 |
+++ b/tests/virscsidata/2-0-0-0/scsi_tape/st0/dev
|
|
|
d76c62 |
@@ -0,0 +1 @@
|
|
|
d76c62 |
+9:0
|
|
|
d76c62 |
diff --git a/tests/virscsidata/2-0-0-0/sg3/dev b/tests/virscsidata/2-0-0-0/sg3/dev
|
|
|
d76c62 |
new file mode 100644
|
|
|
d76c62 |
index 0000000000..b369a59b3e
|
|
|
d76c62 |
--- /dev/null
|
|
|
d76c62 |
+++ b/tests/virscsidata/2-0-0-0/sg3/dev
|
|
|
d76c62 |
@@ -0,0 +1 @@
|
|
|
d76c62 |
+21:3
|
|
|
d76c62 |
diff --git a/tests/virscsidata/2-0-0-0/tape b/tests/virscsidata/2-0-0-0/tape
|
|
|
d76c62 |
new file mode 120000
|
|
|
d76c62 |
index 0000000000..6ca7f77539
|
|
|
d76c62 |
--- /dev/null
|
|
|
d76c62 |
+++ b/tests/virscsidata/2-0-0-0/tape
|
|
|
d76c62 |
@@ -0,0 +1 @@
|
|
|
d76c62 |
+scsi_tape/st0
|
|
|
d76c62 |
\ No newline at end of file
|
|
|
d76c62 |
diff --git a/tests/virscsidata/2-0-0-0/type b/tests/virscsidata/2-0-0-0/type
|
|
|
d76c62 |
new file mode 100644
|
|
|
d76c62 |
index 0000000000..d00491fd7e
|
|
|
d76c62 |
--- /dev/null
|
|
|
d76c62 |
+++ b/tests/virscsidata/2-0-0-0/type
|
|
|
d76c62 |
@@ -0,0 +1 @@
|
|
|
d76c62 |
+1
|
|
|
d76c62 |
diff --git a/tests/virscsidata/2-0-0-0/vendor b/tests/virscsidata/2-0-0-0/vendor
|
|
|
d76c62 |
new file mode 100644
|
|
|
d76c62 |
index 0000000000..9b075671ea
|
|
|
d76c62 |
--- /dev/null
|
|
|
d76c62 |
+++ b/tests/virscsidata/2-0-0-0/vendor
|
|
|
d76c62 |
@@ -0,0 +1 @@
|
|
|
d76c62 |
+Linux
|
|
|
d76c62 |
diff --git a/tests/virscsidata/sg3 b/tests/virscsidata/sg3
|
|
|
d76c62 |
new file mode 100644
|
|
|
d76c62 |
index 0000000000..e69de29bb2
|
|
|
d76c62 |
diff --git a/tests/virscsitest.c b/tests/virscsitest.c
|
|
|
aa5bf2 |
index c96699e157..924b77af08 100644
|
|
|
d76c62 |
--- a/tests/virscsitest.c
|
|
|
d76c62 |
+++ b/tests/virscsitest.c
|
|
|
aa5bf2 |
@@ -33,17 +33,33 @@ VIR_LOG_INIT("tests.scsitest");
|
|
|
d76c62 |
|
|
|
d76c62 |
static char *virscsi_prefix;
|
|
|
d76c62 |
|
|
|
d76c62 |
+typedef struct {
|
|
|
d76c62 |
+ const char *adapter;
|
|
|
d76c62 |
+ unsigned int bus;
|
|
|
d76c62 |
+ unsigned int target;
|
|
|
d76c62 |
+ unsigned int unit;
|
|
|
d76c62 |
+ const char *expectedName;
|
|
|
d76c62 |
+} testGetDevNameData;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
static int
|
|
|
d76c62 |
-test1(const void *data G_GNUC_UNUSED)
|
|
|
d76c62 |
+testGetDevName(const void *opaque)
|
|
|
d76c62 |
{
|
|
|
d76c62 |
+ const testGetDevNameData *data = opaque;
|
|
|
aa5bf2 |
g_autofree char *name = NULL;
|
|
|
d76c62 |
|
|
|
d76c62 |
if (!(name = virSCSIDeviceGetDevName(virscsi_prefix,
|
|
|
d76c62 |
- "scsi_host1", 0, 0, 0)))
|
|
|
d76c62 |
+ data->adapter,
|
|
|
d76c62 |
+ data->bus,
|
|
|
d76c62 |
+ data->target,
|
|
|
d76c62 |
+ data->unit)))
|
|
|
d76c62 |
return -1;
|
|
|
d76c62 |
|
|
|
d76c62 |
- if (STRNEQ(name, "sdh"))
|
|
|
d76c62 |
+ if (STRNEQ(name, data->expectedName)) {
|
|
|
d76c62 |
+ fprintf(stderr,
|
|
|
d76c62 |
+ "SCSI dev name mismatch, expected %s got %s",
|
|
|
d76c62 |
+ data->expectedName, name);
|
|
|
aa5bf2 |
return -1;
|
|
|
d76c62 |
+ }
|
|
|
d76c62 |
|
|
|
aa5bf2 |
return 0;
|
|
|
aa5bf2 |
}
|
|
|
aa5bf2 |
@@ -200,15 +216,27 @@ mymain(void)
|
|
|
d76c62 |
|
|
|
d76c62 |
CREATE_SYMLINK("0-0-0-0", "0:0:0:0");
|
|
|
d76c62 |
CREATE_SYMLINK("1-0-0-0", "1:0:0:0");
|
|
|
d76c62 |
+ CREATE_SYMLINK("2-0-0-0", "2:0:0:0");
|
|
|
d76c62 |
CREATE_SYMLINK("sg0", "sg0");
|
|
|
d76c62 |
+ CREATE_SYMLINK("sg3", "sg3");
|
|
|
d76c62 |
CREATE_SYMLINK("sg8", "sg8");
|
|
|
d76c62 |
|
|
|
d76c62 |
VIR_FREE(virscsi_prefix);
|
|
|
d76c62 |
|
|
|
d76c62 |
virscsi_prefix = g_strdup(tmpdir);
|
|
|
d76c62 |
|
|
|
d76c62 |
- if (virTestRun("test1", test1, NULL) < 0)
|
|
|
d76c62 |
- ret = -1;
|
|
|
d76c62 |
+#define TEST_GET_DEV_NAME(adapter, bus, target, unit, expectedName) \
|
|
|
d76c62 |
+ do { \
|
|
|
d76c62 |
+ testGetDevNameData data = {adapter, bus, target, unit, expectedName}; \
|
|
|
d76c62 |
+ if (virTestRun("test getDevname " expectedName, \
|
|
|
d76c62 |
+ testGetDevName, &data) < 0) \
|
|
|
d76c62 |
+ ret = -1; \
|
|
|
d76c62 |
+ } while (0)
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ TEST_GET_DEV_NAME("scsi_host0", 0, 0, 0, "sda");
|
|
|
d76c62 |
+ TEST_GET_DEV_NAME("scsi_host1", 0, 0, 0, "sdh");
|
|
|
d76c62 |
+ TEST_GET_DEV_NAME("scsi_host2", 0, 0, 0, "st0");
|
|
|
d76c62 |
+
|
|
|
d76c62 |
if (virTestRun("test2", test2, NULL) < 0)
|
|
|
d76c62 |
ret = -1;
|
|
|
d76c62 |
|
|
|
d76c62 |
--
|
|
|
1e07ec |
2.34.1
|
|
|
d76c62 |
|