]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add support for iSCSI target auto-discovery
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 12 Nov 2010 15:41:16 +0000 (15:41 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 23 Nov 2010 15:00:29 +0000 (15:00 +0000)
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

index 60a56acc25851fdd4a629d2e7397e03e87abc764..b376de288ac820636ed45afe42bc940ec27d431e 100644 (file)
@@ -568,6 +568,71 @@ 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;
+
+    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)
@@ -668,4 +733,5 @@ virStorageBackend virStorageBackendISCSI = {
     .startPool = virStorageBackendISCSIStartPool,
     .refreshPool = virStorageBackendISCSIRefreshPool,
     .stopPool = virStorageBackendISCSIStopPool,
+    .findPoolSources = virStorageBackendISCSIFindPoolSources,
 };