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