From: Clementine Hayat Date: Sun, 12 Aug 2018 22:26:17 +0000 (+0200) Subject: storage: add SetConnection to iscsi-direct backend X-Git-Tag: v4.7.0-rc1~237 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e68426f0ad600e6fcc2dca515f5898017ca0fa2a;p=thirdparty%2Flibvirt.git 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: Clementine Hayat Signed-off-by: Michal Privoznik --- diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c index 26f960e7bc..97b39b1352 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -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; }