mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-18 05:31:14 +00:00
virutil: Introduce virGetSCSIHostNumber
Create/use virGetSCSIHostNumber to replace the static getHostNumber Removed the "if (result &&" since result is now required to be non NULL on input.
This commit is contained in:
parent
e3a52afcfc
commit
55f439599c
@ -2160,6 +2160,7 @@ virGetGroupList;
|
|||||||
virGetGroupName;
|
virGetGroupName;
|
||||||
virGetHostname;
|
virGetHostname;
|
||||||
virGetListenFDs;
|
virGetListenFDs;
|
||||||
|
virGetSCSIHostNumber;
|
||||||
virGetSelfLastChanged;
|
virGetSelfLastChanged;
|
||||||
virGetUnprivSGIOSysfsPath;
|
virGetUnprivSGIOSysfsPath;
|
||||||
virGetUserCacheDirectory;
|
virGetUserCacheDirectory;
|
||||||
|
@ -511,38 +511,6 @@ virStorageBackendSCSITriggerRescan(uint32_t host)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
getHostNumber(const char *adapter_name,
|
|
||||||
unsigned int *result)
|
|
||||||
{
|
|
||||||
char *host = (char *)adapter_name;
|
|
||||||
|
|
||||||
/* Specifying adapter like 'host5' is still supported for
|
|
||||||
* back-compat reason.
|
|
||||||
*/
|
|
||||||
if (STRPREFIX(host, "scsi_host")) {
|
|
||||||
host += strlen("scsi_host");
|
|
||||||
} else if (STRPREFIX(host, "fc_host")) {
|
|
||||||
host += strlen("fc_host");
|
|
||||||
} else if (STRPREFIX(host, "host")) {
|
|
||||||
host += strlen("host");
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Invalid adapter name '%s' for SCSI pool"),
|
|
||||||
adapter_name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result && virStrToLong_ui(host, NULL, 10, result) == -1) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Invalid adapter name '%s' for SCSI pool"),
|
|
||||||
adapter_name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
getAdapterName(virStoragePoolSourceAdapter adapter)
|
getAdapterName(virStoragePoolSourceAdapter adapter)
|
||||||
{
|
{
|
||||||
@ -610,7 +578,7 @@ createVport(virStoragePoolSourceAdapter adapter)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
if (virGetSCSIHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virManageVport(parent_host, adapter.data.fchost.wwpn,
|
if (virManageVport(parent_host, adapter.data.fchost.wwpn,
|
||||||
@ -643,7 +611,7 @@ deleteVport(virStoragePoolSourceAdapter adapter)
|
|||||||
adapter.data.fchost.wwpn)))
|
adapter.data.fchost.wwpn)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (getHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
if (virGetSCSIHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virManageVport(parent_host, adapter.data.fchost.wwpn,
|
if (virManageVport(parent_host, adapter.data.fchost.wwpn,
|
||||||
@ -683,7 +651,7 @@ virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getHostNumber(name, &host) < 0)
|
if (virGetSCSIHostNumber(name, &host) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virAsprintf(&path, "%s/host%d",
|
if (virAsprintf(&path, "%s/host%d",
|
||||||
@ -712,7 +680,7 @@ virStorageBackendSCSIRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
if (!(name = getAdapterName(pool->def->source.adapter)))
|
if (!(name = getAdapterName(pool->def->source.adapter)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (getHostNumber(name, &host) < 0)
|
if (virGetSCSIHostNumber(name, &host) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
VIR_DEBUG("Scanning host%u", host);
|
VIR_DEBUG("Scanning host%u", host);
|
||||||
|
@ -1838,6 +1838,52 @@ virFindSCSIHostByPCI(const char *sysfs_prefix,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* virGetSCSIHostNumber:
|
||||||
|
* @adapter_name: Name of the host adapter
|
||||||
|
* @result: Return the entry value as unsigned int
|
||||||
|
*
|
||||||
|
* Convert the various forms of scsi_host names into the numeric
|
||||||
|
* host# value that can be used in order to scan sysfs looking for
|
||||||
|
* the specific host.
|
||||||
|
*
|
||||||
|
* Names can be either "scsi_host#" or just "host#", where
|
||||||
|
* "host#" is the back-compat format, but both equate to
|
||||||
|
* the same source adapter. First check if both pool and def
|
||||||
|
* are using same format (easier) - if so, then compare
|
||||||
|
*
|
||||||
|
* Returns 0 on success, and @result has the host number.
|
||||||
|
* Otherwise returns -1.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virGetSCSIHostNumber(const char *adapter_name,
|
||||||
|
unsigned int *result)
|
||||||
|
{
|
||||||
|
/* Specifying adapter like 'host5' is still supported for
|
||||||
|
* back-compat reason.
|
||||||
|
*/
|
||||||
|
if (STRPREFIX(adapter_name, "scsi_host")) {
|
||||||
|
adapter_name += strlen("scsi_host");
|
||||||
|
} else if (STRPREFIX(adapter_name, "fc_host")) {
|
||||||
|
adapter_name += strlen("fc_host");
|
||||||
|
} else if (STRPREFIX(adapter_name, "host")) {
|
||||||
|
adapter_name += strlen("host");
|
||||||
|
} else {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Invalid adapter name '%s' for SCSI pool"),
|
||||||
|
adapter_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virStrToLong_ui(adapter_name, NULL, 10, result) == -1) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Invalid adapter name '%s' for SCSI pool"),
|
||||||
|
adapter_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* virReadFCHost:
|
/* virReadFCHost:
|
||||||
* @sysfs_prefix: "fc_host" sysfs path, defaults to SYSFS_FC_HOST_PATH
|
* @sysfs_prefix: "fc_host" sysfs path, defaults to SYSFS_FC_HOST_PATH
|
||||||
* @host: Host number, E.g. 5 of "fc_host/host5"
|
* @host: Host number, E.g. 5 of "fc_host/host5"
|
||||||
@ -2208,6 +2254,14 @@ virFindSCSIHostByPCI(const char *sysfs_prefix ATTRIBUTE_UNUSED,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
virGetSCSIHostNumber(const char *adapter_name ATTRIBUTE_UNUSED,
|
||||||
|
unsigned int *result ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
virReportSystemError(ENOSYS, "%s", _("Not supported on this platform"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
virReadFCHost(const char *sysfs_prefix ATTRIBUTE_UNUSED,
|
virReadFCHost(const char *sysfs_prefix ATTRIBUTE_UNUSED,
|
||||||
int host ATTRIBUTE_UNUSED,
|
int host ATTRIBUTE_UNUSED,
|
||||||
|
@ -173,6 +173,10 @@ char *
|
|||||||
virFindSCSIHostByPCI(const char *sysfs_prefix,
|
virFindSCSIHostByPCI(const char *sysfs_prefix,
|
||||||
const char *parentaddr,
|
const char *parentaddr,
|
||||||
unsigned int unique_id);
|
unsigned int unique_id);
|
||||||
|
int
|
||||||
|
virGetSCSIHostNumber(const char *adapter_name,
|
||||||
|
unsigned int *result)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
int virReadFCHost(const char *sysfs_prefix,
|
int virReadFCHost(const char *sysfs_prefix,
|
||||||
int host,
|
int host,
|
||||||
const char *entry,
|
const char *entry,
|
||||||
|
Loading…
Reference in New Issue
Block a user