mirror of https://gitee.com/openkylin/libvirt.git
util: Replace virStoragePoolGetVhbaSCSIHostParent
Use the new virNodeDeviceGetParentName instead. Modify the callers to build the node device scsi_host# name string in order to call the new function so that proper lookup occurs.
This commit is contained in:
parent
aa6aa624ad
commit
d2d74a986d
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
#include "virerror.h"
|
#include "virerror.h"
|
||||||
#include "datatypes.h"
|
#include "datatypes.h"
|
||||||
|
#include "node_device_conf.h"
|
||||||
#include "storage_conf.h"
|
#include "storage_conf.h"
|
||||||
#include "virstoragefile.h"
|
#include "virstoragefile.h"
|
||||||
|
|
||||||
|
@ -2275,64 +2276,6 @@ virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* virStoragePoolGetVhbaSCSIHostParent:
|
|
||||||
*
|
|
||||||
* Using the Node Device Driver, find the host# name found via wwnn/wwpn
|
|
||||||
* lookup in the fc_host sysfs tree (e.g. virGetFCHostNameByWWN) to get
|
|
||||||
* the parent 'scsi_host#'.
|
|
||||||
*
|
|
||||||
* @conn: Connection pointer (must be non-NULL on entry)
|
|
||||||
* @name: Pointer a string from a virGetFCHostNameByWWN (e.g., "host#")
|
|
||||||
*
|
|
||||||
* Returns a "scsi_host#" string of the parent of the vHBA
|
|
||||||
*/
|
|
||||||
char *
|
|
||||||
virStoragePoolGetVhbaSCSIHostParent(virConnectPtr conn,
|
|
||||||
const char *name)
|
|
||||||
{
|
|
||||||
char *nodedev_name = NULL;
|
|
||||||
virNodeDevicePtr device = NULL;
|
|
||||||
char *xml = NULL;
|
|
||||||
virNodeDeviceDefPtr def = NULL;
|
|
||||||
char *vhba_parent = NULL;
|
|
||||||
|
|
||||||
VIR_DEBUG("conn=%p, name=%s", conn, name);
|
|
||||||
|
|
||||||
/* We get passed "host#" from the return from virGetFCHostNameByWWN,
|
|
||||||
* so we need to adjust that to what the nodedev lookup expects
|
|
||||||
*/
|
|
||||||
if (virAsprintf(&nodedev_name, "scsi_%s", name) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
/* Compare the scsi_host for the name with the provided parent
|
|
||||||
* if not the same, then fail
|
|
||||||
*/
|
|
||||||
if (!(device = virNodeDeviceLookupByName(conn, nodedev_name))) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("Cannot find '%s' in node device database"),
|
|
||||||
nodedev_name);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(xml = virNodeDeviceGetXMLDesc(device, 0)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
/* The caller checks whether the returned value is NULL or not
|
|
||||||
* before continuing
|
|
||||||
*/
|
|
||||||
ignore_value(VIR_STRDUP(vhba_parent, def->parent));
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(nodedev_name);
|
|
||||||
virNodeDeviceDefFree(def);
|
|
||||||
VIR_FREE(xml);
|
|
||||||
virObjectUnref(device);
|
|
||||||
return vhba_parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
getSCSIHostNumber(virStoragePoolSourceAdapter adapter,
|
getSCSIHostNumber(virStoragePoolSourceAdapter adapter,
|
||||||
|
@ -2383,6 +2326,7 @@ matchFCHostToSCSIHost(virConnectPtr conn,
|
||||||
unsigned int scsi_hostnum)
|
unsigned int scsi_hostnum)
|
||||||
{
|
{
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
char *scsi_host_name = NULL;
|
||||||
char *parent_name = NULL;
|
char *parent_name = NULL;
|
||||||
unsigned int fc_hostnum;
|
unsigned int fc_hostnum;
|
||||||
|
|
||||||
|
@ -2415,8 +2359,13 @@ matchFCHostToSCSIHost(virConnectPtr conn,
|
||||||
* have a match.
|
* have a match.
|
||||||
*/
|
*/
|
||||||
if (conn && !fc_adapter.data.fchost.parent) {
|
if (conn && !fc_adapter.data.fchost.parent) {
|
||||||
parent_name = virStoragePoolGetVhbaSCSIHostParent(conn, name);
|
if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0) {
|
||||||
if (parent_name) {
|
VIR_FREE(name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((parent_name = virNodeDeviceGetParentName(conn,
|
||||||
|
scsi_host_name))) {
|
||||||
|
VIR_FREE(scsi_host_name);
|
||||||
if (virGetSCSIHostNumber(parent_name, &fc_hostnum) == 0 &&
|
if (virGetSCSIHostNumber(parent_name, &fc_hostnum) == 0 &&
|
||||||
scsi_hostnum == fc_hostnum) {
|
scsi_hostnum == fc_hostnum) {
|
||||||
VIR_FREE(parent_name);
|
VIR_FREE(parent_name);
|
||||||
|
@ -2428,6 +2377,7 @@ matchFCHostToSCSIHost(virConnectPtr conn,
|
||||||
/* Throw away the error and fall through */
|
/* Throw away the error and fall through */
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
VIR_DEBUG("Could not determine parent vHBA");
|
VIR_DEBUG("Could not determine parent vHBA");
|
||||||
|
VIR_FREE(scsi_host_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VIR_FREE(name);
|
VIR_FREE(name);
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
# include "virbitmap.h"
|
# include "virbitmap.h"
|
||||||
# include "virthread.h"
|
# include "virthread.h"
|
||||||
# include "device_conf.h"
|
# include "device_conf.h"
|
||||||
# include "node_device_conf.h"
|
|
||||||
# include "object_event.h"
|
# include "object_event.h"
|
||||||
|
|
||||||
# include <libxml/tree.h>
|
# include <libxml/tree.h>
|
||||||
|
@ -418,10 +417,6 @@ int virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
|
||||||
virStoragePoolDefPtr def,
|
virStoragePoolDefPtr def,
|
||||||
unsigned int check_active);
|
unsigned int check_active);
|
||||||
|
|
||||||
char *virStoragePoolGetVhbaSCSIHostParent(virConnectPtr conn,
|
|
||||||
const char *name)
|
|
||||||
ATTRIBUTE_NONNULL(1);
|
|
||||||
|
|
||||||
int virStoragePoolSourceFindDuplicate(virConnectPtr conn,
|
int virStoragePoolSourceFindDuplicate(virConnectPtr conn,
|
||||||
virStoragePoolObjListPtr pools,
|
virStoragePoolObjListPtr pools,
|
||||||
virStoragePoolDefPtr def);
|
virStoragePoolDefPtr def);
|
||||||
|
|
|
@ -889,7 +889,6 @@ virStoragePoolFormatDiskTypeToString;
|
||||||
virStoragePoolFormatFileSystemNetTypeToString;
|
virStoragePoolFormatFileSystemNetTypeToString;
|
||||||
virStoragePoolFormatFileSystemTypeToString;
|
virStoragePoolFormatFileSystemTypeToString;
|
||||||
virStoragePoolFormatLogicalTypeToString;
|
virStoragePoolFormatLogicalTypeToString;
|
||||||
virStoragePoolGetVhbaSCSIHostParent;
|
|
||||||
virStoragePoolLoadAllConfigs;
|
virStoragePoolLoadAllConfigs;
|
||||||
virStoragePoolLoadAllState;
|
virStoragePoolLoadAllState;
|
||||||
virStoragePoolObjAssignDef;
|
virStoragePoolObjAssignDef;
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "virvhba.h"
|
#include "virvhba.h"
|
||||||
#include "storage_util.h"
|
#include "storage_util.h"
|
||||||
|
#include "node_device_conf.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
|
@ -214,10 +215,11 @@ getAdapterName(virStoragePoolSourceAdapter adapter)
|
||||||
* sysfs tree to get the parent 'scsi_host#' to ensure it matches.
|
* sysfs tree to get the parent 'scsi_host#' to ensure it matches.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
checkVhbaSCSIHostParent(virConnectPtr conn,
|
checkParent(virConnectPtr conn,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *parent_name)
|
const char *parent_name)
|
||||||
{
|
{
|
||||||
|
char *scsi_host_name = NULL;
|
||||||
char *vhba_parent = NULL;
|
char *vhba_parent = NULL;
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
|
@ -227,7 +229,10 @@ checkVhbaSCSIHostParent(virConnectPtr conn,
|
||||||
if (!conn)
|
if (!conn)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!(vhba_parent = virStoragePoolGetVhbaSCSIHostParent(conn, name)))
|
if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(vhba_parent = virNodeDeviceGetParentName(conn, scsi_host_name)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (STRNEQ(parent_name, vhba_parent)) {
|
if (STRNEQ(parent_name, vhba_parent)) {
|
||||||
|
@ -242,6 +247,7 @@ checkVhbaSCSIHostParent(virConnectPtr conn,
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(vhba_parent);
|
VIR_FREE(vhba_parent);
|
||||||
|
VIR_FREE(scsi_host_name);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +282,7 @@ createVport(virConnectPtr conn,
|
||||||
* retrieved has the same parent
|
* retrieved has the same parent
|
||||||
*/
|
*/
|
||||||
if (adapter->data.fchost.parent &&
|
if (adapter->data.fchost.parent &&
|
||||||
checkVhbaSCSIHostParent(conn, name, adapter->data.fchost.parent))
|
checkParent(conn, name, adapter->data.fchost.parent))
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -383,6 +389,7 @@ deleteVport(virConnectPtr conn,
|
||||||
{
|
{
|
||||||
unsigned int parent_host;
|
unsigned int parent_host;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
char *scsi_host_name = NULL;
|
||||||
char *vhba_parent = NULL;
|
char *vhba_parent = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
@ -416,7 +423,10 @@ deleteVport(virConnectPtr conn,
|
||||||
if (virGetSCSIHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
if (virGetSCSIHostNumber(adapter.data.fchost.parent, &parent_host) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
if (!(vhba_parent = virStoragePoolGetVhbaSCSIHostParent(conn, name)))
|
if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(vhba_parent = virNodeDeviceGetParentName(conn, scsi_host_name)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virGetSCSIHostNumber(vhba_parent, &parent_host) < 0)
|
if (virGetSCSIHostNumber(vhba_parent, &parent_host) < 0)
|
||||||
|
@ -431,6 +441,7 @@ deleteVport(virConnectPtr conn,
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(name);
|
VIR_FREE(name);
|
||||||
VIR_FREE(vhba_parent);
|
VIR_FREE(vhba_parent);
|
||||||
|
VIR_FREE(scsi_host_name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue