提交 e68426f0 编写于 作者: C Clementine Hayat 提交者: Michal Privoznik

storage: add SetConnection to iscsi-direct backend

The code to set the connection and connect using libiscsi will always be
the same. Add function to avoid code duplication.
Signed-off-by: NClementine Hayat <clem@lse.epita.fr>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 14bfe9fa
......@@ -556,23 +556,45 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
return ret;
}
static int
virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool)
static struct iscsi_context *
virStorageBackendISCSIDirectSetConnection(virStoragePoolObjPtr pool,
char **portalRet)
{
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
struct iscsi_context *iscsi = NULL;
char *portal = NULL;
int ret = -1;
if (!(iscsi = virISCSIDirectCreateContext(def->source.initiator.iqn)))
goto cleanup;
goto error;
if (!(portal = virStorageBackendISCSIDirectPortal(&def->source)))
goto cleanup;
goto error;
if (virStorageBackendISCSIDirectSetAuth(iscsi, &def->source) < 0)
goto cleanup;
goto error;
if (virISCSIDirectSetContext(iscsi, def->source.devices[0].path, ISCSI_SESSION_NORMAL) < 0)
goto cleanup;
goto error;
if (virISCSIDirectConnect(iscsi, portal) < 0)
goto error;
if (portalRet)
VIR_STEAL_PTR(*portalRet, portal);
cleanup:
VIR_FREE(portal);
return iscsi;
error:
iscsi_destroy_context(iscsi);
iscsi = NULL;
goto cleanup;
}
static int
virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool)
{
struct iscsi_context *iscsi = NULL;
char *portal = NULL;
int ret = -1;
if (!(iscsi = virStorageBackendISCSIDirectSetConnection(pool, &portal)))
goto cleanup;
if (virISCSIDirectReportLuns(pool, iscsi, portal) < 0)
goto disconect;
......@@ -580,9 +602,9 @@ virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool)
ret = 0;
disconect:
virISCSIDirectDisconnect(iscsi);
iscsi_destroy_context(iscsi);
cleanup:
VIR_FREE(portal);
iscsi_destroy_context(iscsi);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册