[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 04/11] Add support for iSCSI target auto-discovery



Since the previous patch added support for parsing the output of
the 'sendtargets' command, it is now trivial to support the
storage pool discovery API.

Given a hostname and optional portnumber and initiator IQN,
the code can return a full list of storage pool source docs,
each one representing a iSCSI target.

* src/storage/storage_backend_iscsi.c: Wire up target
  auto-discovery
---
 src/storage/storage_backend_iscsi.c |   68 +++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 2a36527..a67a428 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -571,6 +571,73 @@ virStorageBackendISCSIScanTargets(const char *portal,
 }
 
 
+static char *
+virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                      const char *srcSpec,
+                                      unsigned int flags ATTRIBUTE_UNUSED)
+{
+    virStoragePoolSourcePtr source = NULL;
+    size_t ntargets = 0;
+    char **targets = NULL;
+    char *ret = NULL;
+    int i;
+    virStoragePoolSourceList list = {
+        .type = VIR_STORAGE_POOL_ISCSI,
+        .nsources = 0,
+        .sources = NULL
+    };
+    char *portal = NULL;
+
+    if (!(source = virStoragePoolDefParseSourceString(srcSpec,
+                                                      list.type)))
+        return NULL;
+
+    if (!(portal = virStorageBackendISCSIPortal(source)))
+        goto cleanup;
+
+    VIR_ERROR("Got %s %s %d\n", source->initiator.iqn, source->host.name, source->host.port);
+
+    if (virStorageBackendISCSIScanTargets(portal,
+                                          source->initiator.iqn,
+                                          &ntargets, &targets) < 0)
+        goto cleanup;
+
+    if (VIR_ALLOC_N(list.sources, ntargets) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    for (i = 0 ; i < ntargets ; i++) {
+        if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+        list.sources[i].host = source->host;
+        list.sources[i].initiator = source->initiator;
+        list.sources[i].ndevice = 1;
+        list.sources[i].devices[0].path = targets[i];
+        list.nsources++;
+    }
+
+    if (!(ret = virStoragePoolSourceListFormat(&list))) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+cleanup:
+    if (list.sources) {
+        for (i = 0 ; i < ntargets ; i++)
+            VIR_FREE(list.sources[i].devices);
+        VIR_FREE(list.sources);
+    }
+    for (i = 0 ; i < ntargets ; i++)
+        VIR_FREE(targets[i]);
+    VIR_FREE(targets);
+    VIR_FREE(portal);
+    virStoragePoolSourceFree(source);
+    return ret;
+}
+
 static int
 virStorageBackendISCSIStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                                 virStoragePoolObjPtr pool)
@@ -671,4 +738,5 @@ virStorageBackend virStorageBackendISCSI = {
     .startPool = virStorageBackendISCSIStartPool,
     .refreshPool = virStorageBackendISCSIRefreshPool,
     .stopPool = virStorageBackendISCSIStopPool,
+    .findPoolSources = virStorageBackendISCSIFindPoolSources,
 };
-- 
1.7.2.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]