]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: add SetConnection to iscsi-direct backend
authorClementine Hayat <clem@lse.epita.fr>
Sun, 12 Aug 2018 22:26:17 +0000 (00:26 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 13 Aug 2018 06:20:06 +0000 (08:20 +0200)
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 <clem@lse.epita.fr>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/storage/storage_backend_iscsi_direct.c

index 26f960e7bc0166b3a0ec3135c589b312cb96262b..97b39b135272b3c2051440e91cfe99d738064011 100644 (file)
@@ -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;
 }