mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
storage: Move and rename getVhbaSCSIHostParent
https://bugzilla.redhat.com/show_bug.cgi?id=1159180 Move the API from the backend to storage_conf and rename it to virStoragePoolGetVhbaSCSIHostParent. A future patch will need to use this functionality from storage_conf
This commit is contained in:
parent
934c388789
commit
7b4cdb6eaa
@ -2078,6 +2078,65 @@ 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,
|
||||||
unsigned int *hostnum)
|
unsigned int *hostnum)
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
# 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 <libxml/tree.h>
|
# include <libxml/tree.h>
|
||||||
|
|
||||||
@ -389,6 +390,10 @@ 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(virStoragePoolObjListPtr pools,
|
int virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools,
|
||||||
virStoragePoolDefPtr def);
|
virStoragePoolDefPtr def);
|
||||||
|
|
||||||
|
@ -744,6 +744,7 @@ virStoragePoolDefParseString;
|
|||||||
virStoragePoolFormatDiskTypeToString;
|
virStoragePoolFormatDiskTypeToString;
|
||||||
virStoragePoolFormatFileSystemNetTypeToString;
|
virStoragePoolFormatFileSystemNetTypeToString;
|
||||||
virStoragePoolFormatFileSystemTypeToString;
|
virStoragePoolFormatFileSystemTypeToString;
|
||||||
|
virStoragePoolGetVhbaSCSIHostParent;
|
||||||
virStoragePoolLoadAllConfigs;
|
virStoragePoolLoadAllConfigs;
|
||||||
virStoragePoolObjAssignDef;
|
virStoragePoolObjAssignDef;
|
||||||
virStoragePoolObjClearVols;
|
virStoragePoolObjClearVols;
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
#include "vircommand.h"
|
#include "vircommand.h"
|
||||||
#include "viraccessapicheck.h"
|
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
@ -630,67 +629,6 @@ getAdapterName(virStoragePoolSourceAdapter adapter)
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Using the host# name found via wwnn/wwpn lookup in the fc_host
|
|
||||||
* sysfs tree to get the parent 'scsi_host#'. On entry we need 'conn'
|
|
||||||
* set. We won't get here from the autostart path since the caller
|
|
||||||
* will return true before calling this function. For the shutdown
|
|
||||||
* path we won't be able to delete the vport.
|
|
||||||
*/
|
|
||||||
static char * ATTRIBUTE_NONNULL(1)
|
|
||||||
getVhbaSCSIHostParent(virConnectPtr conn,
|
|
||||||
const char *name)
|
|
||||||
{
|
|
||||||
char *nodedev_name = NULL;
|
|
||||||
virNodeDevicePtr device = NULL;
|
|
||||||
char *xml = NULL;
|
|
||||||
virNodeDeviceDefPtr def = NULL;
|
|
||||||
char *vhba_parent = NULL;
|
|
||||||
virErrorPtr savedError = 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:
|
|
||||||
if (!vhba_parent)
|
|
||||||
savedError = virSaveLastError();
|
|
||||||
VIR_FREE(nodedev_name);
|
|
||||||
virNodeDeviceDefFree(def);
|
|
||||||
VIR_FREE(xml);
|
|
||||||
virNodeDeviceFree(device);
|
|
||||||
if (savedError) {
|
|
||||||
virSetError(savedError);
|
|
||||||
virFreeError(savedError);
|
|
||||||
}
|
|
||||||
return vhba_parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Using the host# name found via wwnn/wwpn lookup in the fc_host
|
* Using the host# name found via wwnn/wwpn lookup in the fc_host
|
||||||
* sysfs tree to get the parent 'scsi_host#' to ensure it matches.
|
* sysfs tree to get the parent 'scsi_host#' to ensure it matches.
|
||||||
@ -709,7 +647,7 @@ checkVhbaSCSIHostParent(virConnectPtr conn,
|
|||||||
if (!conn)
|
if (!conn)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!(vhba_parent = getVhbaSCSIHostParent(conn, name)))
|
if (!(vhba_parent = virStoragePoolGetVhbaSCSIHostParent(conn, name)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (STRNEQ(parent_name, vhba_parent)) {
|
if (STRNEQ(parent_name, vhba_parent)) {
|
||||||
@ -886,7 +824,7 @@ 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 = getVhbaSCSIHostParent(conn, name)))
|
if (!(vhba_parent = virStoragePoolGetVhbaSCSIHostParent(conn, name)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virGetSCSIHostNumber(vhba_parent, &parent_host) < 0)
|
if (virGetSCSIHostNumber(vhba_parent, &parent_host) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user