aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2010-11-12 15:41:16 +0000
committerDaniel P. Berrange <berrange@redhat.com>2010-11-23 15:00:29 +0000
commit1da8c5672fd95ddcd9a258149d4fb03e45ce4a49 (patch)
tree908b44bef134a3d2eeb7685d830e0b9cc723d07d
parentStop iSCSI targets automatically logging back in after logout (diff)
downloadlibvirt-1da8c5672fd95ddcd9a258149d4fb03e45ce4a49.tar.gz
libvirt-1da8c5672fd95ddcd9a258149d4fb03e45ce4a49.tar.bz2
libvirt-1da8c5672fd95ddcd9a258149d4fb03e45ce4a49.zip
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
-rw-r--r--src/storage/storage_backend_iscsi.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 60a56acc2..b376de288 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -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,
};