|
Pablo Greco |
40546a |
From 41480c7a787cc776e64d2ab7b737c3e8d6a84bd2 Mon Sep 17 00:00:00 2001
|
|
Pablo Greco |
40546a |
Message-Id: <41480c7a787cc776e64d2ab7b737c3e8d6a84bd2@dist-git>
|
|
Pablo Greco |
40546a |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
Pablo Greco |
40546a |
Date: Fri, 6 Mar 2020 15:51:45 +0100
|
|
Pablo Greco |
40546a |
Subject: [PATCH] RHEL: virscsi: Support TAPEs in virSCSIDeviceGetDevName()
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
If the SCSI device we want to get /dev node name for is TAPE
|
|
Pablo Greco |
40546a |
device we need to look at 'tape' symlink in the sysfs dir
|
|
Pablo Greco |
40546a |
corresponding to the device.
|
|
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-3-abologna@redhat.com>
|
|
Pablo Greco |
40546a |
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
|
|
Pablo Greco |
40546a |
---
|
|
Pablo Greco |
40546a |
src/util/virscsi.c | 37 ++++++++++++++++++++
|
|
Pablo Greco |
40546a |
tests/virscsidata/2-0-0-0/model | 1 +
|
|
Pablo Greco |
40546a |
tests/virscsidata/2-0-0-0/scsi_tape/st0/dev | 1 +
|
|
Pablo Greco |
40546a |
tests/virscsidata/2-0-0-0/sg3/dev | 1 +
|
|
Pablo Greco |
40546a |
tests/virscsidata/2-0-0-0/tape | 1 +
|
|
Pablo Greco |
40546a |
tests/virscsidata/2-0-0-0/type | 1 +
|
|
Pablo Greco |
40546a |
tests/virscsidata/2-0-0-0/vendor | 1 +
|
|
Pablo Greco |
40546a |
tests/virscsidata/sg3 | 0
|
|
Pablo Greco |
40546a |
tests/virscsitest.c | 38 ++++++++++++++++++---
|
|
Pablo Greco |
40546a |
9 files changed, 76 insertions(+), 5 deletions(-)
|
|
Pablo Greco |
40546a |
create mode 100644 tests/virscsidata/2-0-0-0/model
|
|
Pablo Greco |
40546a |
create mode 100644 tests/virscsidata/2-0-0-0/scsi_tape/st0/dev
|
|
Pablo Greco |
40546a |
create mode 100644 tests/virscsidata/2-0-0-0/sg3/dev
|
|
Pablo Greco |
40546a |
create mode 120000 tests/virscsidata/2-0-0-0/tape
|
|
Pablo Greco |
40546a |
create mode 100644 tests/virscsidata/2-0-0-0/type
|
|
Pablo Greco |
40546a |
create mode 100644 tests/virscsidata/2-0-0-0/vendor
|
|
Pablo Greco |
40546a |
create mode 100644 tests/virscsidata/sg3
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
|
|
Pablo Greco |
40546a |
index af908107d9..6c3fd8a562 100644
|
|
Pablo Greco |
40546a |
--- a/src/util/virscsi.c
|
|
Pablo Greco |
40546a |
+++ b/src/util/virscsi.c
|
|
Pablo Greco |
40546a |
@@ -42,6 +42,7 @@
|
|
Pablo Greco |
40546a |
#include "virutil.h"
|
|
Pablo Greco |
40546a |
#include "virstring.h"
|
|
Pablo Greco |
40546a |
#include "virerror.h"
|
|
Pablo Greco |
40546a |
+#include "dirname.h"
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
#define SYSFS_SCSI_DEVICES "/sys/bus/scsi/devices"
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
@@ -249,6 +250,39 @@ virSCSIDeviceGetDevNameBlock(const char *prefix,
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+static char *
|
|
Pablo Greco |
40546a |
+virSCSIDeviceGetDevNameTape(const char *prefix,
|
|
Pablo Greco |
40546a |
+ unsigned int 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 |
+ char *resolvedPath = NULL;
|
|
Pablo Greco |
40546a |
+ char *name = NULL;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virAsprintf(&path,
|
|
Pablo Greco |
40546a |
+ "%s/%d:%u:%u:%llu/tape",
|
|
Pablo Greco |
40546a |
+ prefix, adapter, bus, target, unit) < 0)
|
|
Pablo Greco |
40546a |
+ return NULL;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virFileReadLink(path, &resolvedPath) < 0) {
|
|
Pablo Greco |
40546a |
+ virReportSystemError(errno,
|
|
Pablo Greco |
40546a |
+ _("Unable to read link: %s"),
|
|
Pablo Greco |
40546a |
+ path);
|
|
Pablo Greco |
40546a |
+ goto cleanup;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (VIR_STRDUP(name, last_component(resolvedPath)) < 0)
|
|
Pablo Greco |
40546a |
+ goto cleanup;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ cleanup:
|
|
Pablo Greco |
40546a |
+ VIR_FREE(resolvedPath);
|
|
Pablo Greco |
40546a |
+ VIR_FREE(path);
|
|
Pablo Greco |
40546a |
+ return name;
|
|
Pablo Greco |
40546a |
+}
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
/* Returns device name (e.g. "sdc") on success, or NULL
|
|
Pablo Greco |
40546a |
* on failure.
|
|
Pablo Greco |
40546a |
*/
|
|
Pablo Greco |
40546a |
@@ -277,6 +311,9 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
|
|
Pablo Greco |
40546a |
break;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
case VIR_SCSI_DEVICE_TYPE_TAPE:
|
|
Pablo Greco |
40546a |
+ name = virSCSIDeviceGetDevNameTape(prefix, adapter_id, bus, target, unit);
|
|
Pablo Greco |
40546a |
+ break;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
case VIR_SCSI_DEVICE_TYPE_PRINTER:
|
|
Pablo Greco |
40546a |
case VIR_SCSI_DEVICE_TYPE_PROCESSOR:
|
|
Pablo Greco |
40546a |
case VIR_SCSI_DEVICE_TYPE_WORM:
|
|
Pablo Greco |
40546a |
diff --git a/tests/virscsidata/2-0-0-0/model b/tests/virscsidata/2-0-0-0/model
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..d2ab4715c3
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/virscsidata/2-0-0-0/model
|
|
Pablo Greco |
40546a |
@@ -0,0 +1 @@
|
|
Pablo Greco |
40546a |
+scsi_debug
|
|
Pablo Greco |
40546a |
diff --git a/tests/virscsidata/2-0-0-0/scsi_tape/st0/dev b/tests/virscsidata/2-0-0-0/scsi_tape/st0/dev
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..3dd777e840
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/virscsidata/2-0-0-0/scsi_tape/st0/dev
|
|
Pablo Greco |
40546a |
@@ -0,0 +1 @@
|
|
Pablo Greco |
40546a |
+9:0
|
|
Pablo Greco |
40546a |
diff --git a/tests/virscsidata/2-0-0-0/sg3/dev b/tests/virscsidata/2-0-0-0/sg3/dev
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..b369a59b3e
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/virscsidata/2-0-0-0/sg3/dev
|
|
Pablo Greco |
40546a |
@@ -0,0 +1 @@
|
|
Pablo Greco |
40546a |
+21:3
|
|
Pablo Greco |
40546a |
diff --git a/tests/virscsidata/2-0-0-0/tape b/tests/virscsidata/2-0-0-0/tape
|
|
Pablo Greco |
40546a |
new file mode 120000
|
|
Pablo Greco |
40546a |
index 0000000000..6ca7f77539
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/virscsidata/2-0-0-0/tape
|
|
Pablo Greco |
40546a |
@@ -0,0 +1 @@
|
|
Pablo Greco |
40546a |
+scsi_tape/st0
|
|
Pablo Greco |
40546a |
\ No newline at end of file
|
|
Pablo Greco |
40546a |
diff --git a/tests/virscsidata/2-0-0-0/type b/tests/virscsidata/2-0-0-0/type
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..d00491fd7e
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/virscsidata/2-0-0-0/type
|
|
Pablo Greco |
40546a |
@@ -0,0 +1 @@
|
|
Pablo Greco |
40546a |
+1
|
|
Pablo Greco |
40546a |
diff --git a/tests/virscsidata/2-0-0-0/vendor b/tests/virscsidata/2-0-0-0/vendor
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..9b075671ea
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/virscsidata/2-0-0-0/vendor
|
|
Pablo Greco |
40546a |
@@ -0,0 +1 @@
|
|
Pablo Greco |
40546a |
+Linux
|
|
Pablo Greco |
40546a |
diff --git a/tests/virscsidata/sg3 b/tests/virscsidata/sg3
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..e69de29bb2
|
|
Pablo Greco |
40546a |
diff --git a/tests/virscsitest.c b/tests/virscsitest.c
|
|
Pablo Greco |
40546a |
index 1215adbfab..880fa22ca8 100644
|
|
Pablo Greco |
40546a |
--- a/tests/virscsitest.c
|
|
Pablo Greco |
40546a |
+++ b/tests/virscsitest.c
|
|
Pablo Greco |
40546a |
@@ -36,18 +36,34 @@ VIR_LOG_INIT("tests.scsitest");
|
|
Pablo Greco |
40546a |
static const char *abs_top_srcdir;
|
|
Pablo Greco |
40546a |
static char *virscsi_prefix;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+typedef struct {
|
|
Pablo Greco |
40546a |
+ const char *adapter;
|
|
Pablo Greco |
40546a |
+ unsigned int bus;
|
|
Pablo Greco |
40546a |
+ unsigned int target;
|
|
Pablo Greco |
40546a |
+ unsigned int unit;
|
|
Pablo Greco |
40546a |
+ const char *expectedName;
|
|
Pablo Greco |
40546a |
+} testGetDevNameData;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
static int
|
|
Pablo Greco |
40546a |
-test1(const void *data ATTRIBUTE_UNUSED)
|
|
Pablo Greco |
40546a |
+testGetDevName(const void *opaque)
|
|
Pablo Greco |
40546a |
{
|
|
Pablo Greco |
40546a |
+ const testGetDevNameData *data = opaque;
|
|
Pablo Greco |
40546a |
char *name = NULL;
|
|
Pablo Greco |
40546a |
int ret = -1;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
if (!(name = virSCSIDeviceGetDevName(virscsi_prefix,
|
|
Pablo Greco |
40546a |
- "scsi_host1", 0, 0, 0)))
|
|
Pablo Greco |
40546a |
+ data->adapter,
|
|
Pablo Greco |
40546a |
+ data->bus,
|
|
Pablo Greco |
40546a |
+ data->target,
|
|
Pablo Greco |
40546a |
+ data->unit)))
|
|
Pablo Greco |
40546a |
return -1;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- if (STRNEQ(name, "sdh"))
|
|
Pablo Greco |
40546a |
+ if (STRNEQ(name, data->expectedName)) {
|
|
Pablo Greco |
40546a |
+ fprintf(stderr,
|
|
Pablo Greco |
40546a |
+ "SCSI dev name mismatch, expected %s got %s",
|
|
Pablo Greco |
40546a |
+ data->expectedName, name);
|
|
Pablo Greco |
40546a |
goto cleanup;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
ret = 0;
|
|
Pablo Greco |
40546a |
cleanup:
|
|
Pablo Greco |
40546a |
@@ -225,7 +241,9 @@ mymain(void)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
CREATE_SYMLINK("0-0-0-0", "0:0:0:0");
|
|
Pablo Greco |
40546a |
CREATE_SYMLINK("1-0-0-0", "1:0:0:0");
|
|
Pablo Greco |
40546a |
+ CREATE_SYMLINK("2-0-0-0", "2:0:0:0");
|
|
Pablo Greco |
40546a |
CREATE_SYMLINK("sg0", "sg0");
|
|
Pablo Greco |
40546a |
+ CREATE_SYMLINK("sg3", "sg3");
|
|
Pablo Greco |
40546a |
CREATE_SYMLINK("sg8", "sg8");
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
VIR_FREE(virscsi_prefix);
|
|
Pablo Greco |
40546a |
@@ -235,8 +253,18 @@ mymain(void)
|
|
Pablo Greco |
40546a |
goto cleanup;
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- if (virTestRun("test1", test1, NULL) < 0)
|
|
Pablo Greco |
40546a |
- ret = -1;
|
|
Pablo Greco |
40546a |
+#define TEST_GET_DEV_NAME(adapter, bus, target, unit, expectedName) \
|
|
Pablo Greco |
40546a |
+ do { \
|
|
Pablo Greco |
40546a |
+ testGetDevNameData data = {adapter, bus, target, unit, expectedName}; \
|
|
Pablo Greco |
40546a |
+ if (virTestRun("test getDevname " expectedName, \
|
|
Pablo Greco |
40546a |
+ testGetDevName, &data) < 0) \
|
|
Pablo Greco |
40546a |
+ ret = -1; \
|
|
Pablo Greco |
40546a |
+ } while (0)
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ TEST_GET_DEV_NAME("scsi_host0", 0, 0, 0, "sda");
|
|
Pablo Greco |
40546a |
+ TEST_GET_DEV_NAME("scsi_host1", 0, 0, 0, "sdh");
|
|
Pablo Greco |
40546a |
+ TEST_GET_DEV_NAME("scsi_host2", 0, 0, 0, "st0");
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
if (virTestRun("test2", test2, NULL) < 0)
|
|
Pablo Greco |
40546a |
ret = -1;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
--
|
|
Pablo Greco |
40546a |
2.25.1
|
|
Pablo Greco |
40546a |
|