mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
storage: open nodedev driver connection at time of use
Instead of passing around a virConnectPtr object, just open a connection to the nodedev driver at time of use. Opening connections on demand will be beneficial when the nodedev driver is in a separate daemon. It also solves the problem that a number of callers just pass in a NULL connection today which prevents nodedev lookup working at all. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
a494f7fd4f
commit
decaeb2882
@ -36,6 +36,7 @@
|
|||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "storage_util.h"
|
#include "storage_util.h"
|
||||||
#include "node_device_conf.h"
|
#include "node_device_conf.h"
|
||||||
|
#include "driver.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
@ -245,20 +246,20 @@ checkName(const char *name)
|
|||||||
* 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
|
||||||
checkParent(virConnectPtr conn,
|
checkParent(const char *name,
|
||||||
const char *name,
|
|
||||||
const char *parent_name)
|
const char *parent_name)
|
||||||
{
|
{
|
||||||
unsigned int host_num;
|
unsigned int host_num;
|
||||||
char *scsi_host_name = NULL;
|
char *scsi_host_name = NULL;
|
||||||
char *vhba_parent = NULL;
|
char *vhba_parent = NULL;
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
|
|
||||||
VIR_DEBUG("conn=%p, name=%s, parent_name=%s", conn, name, parent_name);
|
VIR_DEBUG("name=%s, parent_name=%s", name, parent_name);
|
||||||
|
|
||||||
/* autostarted pool - assume we're OK */
|
conn = virGetConnectNodeDev();
|
||||||
if (!conn)
|
if (!conn)
|
||||||
return true;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSCSIHostGetNumber(parent_name, &host_num) < 0) {
|
if (virSCSIHostGetNumber(parent_name, &host_num) < 0) {
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
@ -291,6 +292,7 @@ checkParent(virConnectPtr conn,
|
|||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
virObjectUnref(conn);
|
||||||
VIR_FREE(vhba_parent);
|
VIR_FREE(vhba_parent);
|
||||||
VIR_FREE(scsi_host_name);
|
VIR_FREE(scsi_host_name);
|
||||||
return retval;
|
return retval;
|
||||||
@ -298,8 +300,7 @@ checkParent(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
createVport(virConnectPtr conn,
|
createVport(virStoragePoolDefPtr def,
|
||||||
virStoragePoolDefPtr def,
|
|
||||||
const char *configFile,
|
const char *configFile,
|
||||||
virStorageAdapterFCHostPtr fchost)
|
virStorageAdapterFCHostPtr fchost)
|
||||||
{
|
{
|
||||||
@ -308,8 +309,8 @@ createVport(virConnectPtr conn,
|
|||||||
virThread thread;
|
virThread thread;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
VIR_DEBUG("conn=%p, configFile='%s' parent='%s', wwnn='%s' wwpn='%s'",
|
VIR_DEBUG("configFile='%s' parent='%s', wwnn='%s' wwpn='%s'",
|
||||||
conn, NULLSTR(configFile), NULLSTR(fchost->parent),
|
NULLSTR(configFile), NULLSTR(fchost->parent),
|
||||||
fchost->wwnn, fchost->wwpn);
|
fchost->wwnn, fchost->wwpn);
|
||||||
|
|
||||||
/* If we find an existing HBA/vHBA within the fc_host sysfs
|
/* If we find an existing HBA/vHBA within the fc_host sysfs
|
||||||
@ -322,7 +323,7 @@ createVport(virConnectPtr conn,
|
|||||||
|
|
||||||
/* If a parent was provided, let's make sure the 'name' we've
|
/* If a parent was provided, let's make sure the 'name' we've
|
||||||
* retrieved has the same parent. If not this will cause failure. */
|
* retrieved has the same parent. If not this will cause failure. */
|
||||||
if (!fchost->parent || checkParent(conn, name, fchost->parent))
|
if (!fchost->parent || checkParent(name, fchost->parent))
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -443,14 +444,14 @@ virStorageBackendSCSIRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendSCSIStartPool(virConnectPtr conn,
|
virStorageBackendSCSIStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool)
|
virStoragePoolObjPtr pool)
|
||||||
{
|
{
|
||||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||||
const char *configFile = virStoragePoolObjGetConfigFile(pool);
|
const char *configFile = virStoragePoolObjGetConfigFile(pool);
|
||||||
|
|
||||||
if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST)
|
if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST)
|
||||||
return createVport(conn, def, configFile,
|
return createVport(def, configFile,
|
||||||
&def->source.adapter.data.fchost);
|
&def->source.adapter.data.fchost);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -463,9 +464,17 @@ virStorageBackendSCSIStopPool(virConnectPtr conn,
|
|||||||
{
|
{
|
||||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||||
|
|
||||||
if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST)
|
if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
|
||||||
return virNodeDeviceDeleteVport(conn,
|
int ret;
|
||||||
|
conn = virGetConnectNodeDev();
|
||||||
|
if (!conn)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
ret = virNodeDeviceDeleteVport(conn,
|
||||||
&def->source.adapter.data.fchost);
|
&def->source.adapter.data.fchost);
|
||||||
|
virObjectUnref(conn);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user