|
|
9119d9 |
From f7b6a5ed06a39ce3fa366fa8e02431c14899300f Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <f7b6a5ed06a39ce3fa366fa8e02431c14899300f@dist-git>
|
|
|
9119d9 |
From: John Ferlan <jferlan@redhat.com>
|
|
|
9119d9 |
Date: Tue, 28 Oct 2014 22:13:31 -0400
|
|
|
9119d9 |
Subject: [PATCH] virutil: Introduce virGetSCSIHostNumber
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1146837
|
|
|
9119d9 |
|
|
|
9119d9 |
Create/use virGetSCSIHostNumber to replace the static getHostNumber
|
|
|
9119d9 |
|
|
|
9119d9 |
Removed the "if (result &&" since result is now required to be non NULL
|
|
|
9119d9 |
on input.
|
|
|
9119d9 |
|
|
|
9119d9 |
(cherry picked from commit 55f439599c46ee9694fbf933e561b55a9a827c61)
|
|
|
9119d9 |
Signed-off-by: John Ferlan <jferlan@redhat.com>
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
src/libvirt_private.syms | 1 +
|
|
|
9119d9 |
src/storage/storage_backend_scsi.c | 40 +++-------------------------
|
|
|
9119d9 |
src/util/virutil.c | 54 ++++++++++++++++++++++++++++++++++++++
|
|
|
9119d9 |
src/util/virutil.h | 4 +++
|
|
|
9119d9 |
4 files changed, 63 insertions(+), 36 deletions(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
9119d9 |
index f569417..d14023e 100644
|
|
|
9119d9 |
--- a/src/libvirt_private.syms
|
|
|
9119d9 |
+++ b/src/libvirt_private.syms
|
|
|
9119d9 |
@@ -2120,6 +2120,7 @@ virGetGroupList;
|
|
|
9119d9 |
virGetGroupName;
|
|
|
9119d9 |
virGetHostname;
|
|
|
9119d9 |
virGetListenFDs;
|
|
|
9119d9 |
+virGetSCSIHostNumber;
|
|
|
9119d9 |
virGetSelfLastChanged;
|
|
|
9119d9 |
virGetUnprivSGIOSysfsPath;
|
|
|
9119d9 |
virGetUserCacheDirectory;
|
|
|
9119d9 |
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
|
|
|
9119d9 |
index 16ed328..d9f3ff2 100644
|
|
|
9119d9 |
--- a/src/storage/storage_backend_scsi.c
|
|
|
9119d9 |
+++ b/src/storage/storage_backend_scsi.c
|
|
|
9119d9 |
@@ -511,38 +511,6 @@ virStorageBackendSCSITriggerRescan(uint32_t host)
|
|
|
9119d9 |
return retval;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
-static int
|
|
|
9119d9 |
-getHostNumber(const char *adapter_name,
|
|
|
9119d9 |
- unsigned int *result)
|
|
|
9119d9 |
-{
|
|
|
9119d9 |
- char *host = (char *)adapter_name;
|
|
|
9119d9 |
-
|
|
|
9119d9 |
- /* Specifying adapter like 'host5' is still supported for
|
|
|
9119d9 |
- * back-compat reason.
|
|
|
9119d9 |
- */
|
|
|
9119d9 |
- if (STRPREFIX(host, "scsi_host")) {
|
|
|
9119d9 |
- host += strlen("scsi_host");
|
|
|
9119d9 |
- } else if (STRPREFIX(host, "fc_host")) {
|
|
|
9119d9 |
- host += strlen("fc_host");
|
|
|
9119d9 |
- } else if (STRPREFIX(host, "host")) {
|
|
|
9119d9 |
- host += strlen("host");
|
|
|
9119d9 |
- } else {
|
|
|
9119d9 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
9119d9 |
- _("Invalid adapter name '%s' for SCSI pool"),
|
|
|
9119d9 |
- adapter_name);
|
|
|
9119d9 |
- return -1;
|
|
|
9119d9 |
- }
|
|
|
9119d9 |
-
|
|
|
9119d9 |
- if (result && virStrToLong_ui(host, NULL, 10, result) == -1) {
|
|
|
9119d9 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
9119d9 |
- _("Invalid adapter name '%s' for SCSI pool"),
|
|
|
9119d9 |
- adapter_name);
|
|
|
9119d9 |
- return -1;
|
|
|
9119d9 |
- }
|
|
|
9119d9 |
-
|
|
|
9119d9 |
- return 0;
|
|
|
9119d9 |
-}
|
|
|
9119d9 |
-
|
|
|
9119d9 |
static char *
|
|
|
9119d9 |
getAdapterName(virStoragePoolSourceAdapter adapter)
|
|
|
9119d9 |
{
|
|
|
9119d9 |
@@ -610,7 +578,7 @@ createVport(virStoragePoolSourceAdapter adapter)
|
|
|
9119d9 |
return -1;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (getHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
|
|
9119d9 |
+ if (virGetSCSIHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
|
|
9119d9 |
return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virManageVport(parent_host, adapter.data.fchost.wwpn,
|
|
|
9119d9 |
@@ -643,7 +611,7 @@ deleteVport(virStoragePoolSourceAdapter adapter)
|
|
|
9119d9 |
adapter.data.fchost.wwpn)))
|
|
|
9119d9 |
return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (getHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
|
|
9119d9 |
+ if (virGetSCSIHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virManageVport(parent_host, adapter.data.fchost.wwpn,
|
|
|
9119d9 |
@@ -683,7 +651,7 @@ virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
}
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (getHostNumber(name, &host) < 0)
|
|
|
9119d9 |
+ if (virGetSCSIHostNumber(name, &host) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virAsprintf(&path, "%s/host%d",
|
|
|
9119d9 |
@@ -712,7 +680,7 @@ virStorageBackendSCSIRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
if (!(name = getAdapterName(pool->def->source.adapter)))
|
|
|
9119d9 |
return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (getHostNumber(name, &host) < 0)
|
|
|
9119d9 |
+ if (virGetSCSIHostNumber(name, &host) < 0)
|
|
|
9119d9 |
goto out;
|
|
|
9119d9 |
|
|
|
9119d9 |
VIR_DEBUG("Scanning host%u", host);
|
|
|
9119d9 |
diff --git a/src/util/virutil.c b/src/util/virutil.c
|
|
|
9119d9 |
index 2edbec5..0a69912 100644
|
|
|
9119d9 |
--- a/src/util/virutil.c
|
|
|
9119d9 |
+++ b/src/util/virutil.c
|
|
|
9119d9 |
@@ -1832,6 +1832,52 @@ virFindSCSIHostByPCI(const char *sysfs_prefix,
|
|
|
9119d9 |
return ret;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
+/* virGetSCSIHostNumber:
|
|
|
9119d9 |
+ * @adapter_name: Name of the host adapter
|
|
|
9119d9 |
+ * @result: Return the entry value as unsigned int
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
+ * Convert the various forms of scsi_host names into the numeric
|
|
|
9119d9 |
+ * host# value that can be used in order to scan sysfs looking for
|
|
|
9119d9 |
+ * the specific host.
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
+ * Names can be either "scsi_host#" or just "host#", where
|
|
|
9119d9 |
+ * "host#" is the back-compat format, but both equate to
|
|
|
9119d9 |
+ * the same source adapter. First check if both pool and def
|
|
|
9119d9 |
+ * are using same format (easier) - if so, then compare
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
+ * Returns 0 on success, and @result has the host number.
|
|
|
9119d9 |
+ * Otherwise returns -1.
|
|
|
9119d9 |
+ */
|
|
|
9119d9 |
+int
|
|
|
9119d9 |
+virGetSCSIHostNumber(const char *adapter_name,
|
|
|
9119d9 |
+ unsigned int *result)
|
|
|
9119d9 |
+{
|
|
|
9119d9 |
+ /* Specifying adapter like 'host5' is still supported for
|
|
|
9119d9 |
+ * back-compat reason.
|
|
|
9119d9 |
+ */
|
|
|
9119d9 |
+ if (STRPREFIX(adapter_name, "scsi_host")) {
|
|
|
9119d9 |
+ adapter_name += strlen("scsi_host");
|
|
|
9119d9 |
+ } else if (STRPREFIX(adapter_name, "fc_host")) {
|
|
|
9119d9 |
+ adapter_name += strlen("fc_host");
|
|
|
9119d9 |
+ } else if (STRPREFIX(adapter_name, "host")) {
|
|
|
9119d9 |
+ adapter_name += strlen("host");
|
|
|
9119d9 |
+ } else {
|
|
|
9119d9 |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
9119d9 |
+ _("Invalid adapter name '%s' for SCSI pool"),
|
|
|
9119d9 |
+ adapter_name);
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ if (virStrToLong_ui(adapter_name, NULL, 10, result) == -1) {
|
|
|
9119d9 |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
9119d9 |
+ _("Invalid adapter name '%s' for SCSI pool"),
|
|
|
9119d9 |
+ adapter_name);
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ return 0;
|
|
|
9119d9 |
+}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
/* virReadFCHost:
|
|
|
9119d9 |
* @sysfs_prefix: "fc_host" sysfs path, defaults to SYSFS_FC_HOST_PATH
|
|
|
9119d9 |
* @host: Host number, E.g. 5 of "fc_host/host5"
|
|
|
9119d9 |
@@ -2203,6 +2249,14 @@ virFindSCSIHostByPCI(const char *sysfs_prefix ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
int
|
|
|
9119d9 |
+virGetSCSIHostNumber(const char *adapter_name ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
+ unsigned int *result ATTRIBUTE_UNUSED)
|
|
|
9119d9 |
+{
|
|
|
9119d9 |
+ virReportSystemError(ENOSYS, "%s", _("Not supported on this platform"));
|
|
|
9119d9 |
+ return NULL;
|
|
|
9119d9 |
+}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+int
|
|
|
9119d9 |
virReadFCHost(const char *sysfs_prefix ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
int host ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
const char *entry ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
diff --git a/src/util/virutil.h b/src/util/virutil.h
|
|
|
9119d9 |
index 89b7923..8b41063 100644
|
|
|
9119d9 |
--- a/src/util/virutil.h
|
|
|
9119d9 |
+++ b/src/util/virutil.h
|
|
|
9119d9 |
@@ -173,6 +173,10 @@ char *
|
|
|
9119d9 |
virFindSCSIHostByPCI(const char *sysfs_prefix,
|
|
|
9119d9 |
const char *parentaddr,
|
|
|
9119d9 |
unsigned int unique_id);
|
|
|
9119d9 |
+int
|
|
|
9119d9 |
+virGetSCSIHostNumber(const char *adapter_name,
|
|
|
9119d9 |
+ unsigned int *result)
|
|
|
9119d9 |
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
9119d9 |
int virReadFCHost(const char *sysfs_prefix,
|
|
|
9119d9 |
int host,
|
|
|
9119d9 |
const char *entry,
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.3
|
|
|
9119d9 |
|