From 1da8c5672fd95ddcd9a258149d4fb03e45ce4a49 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 12 Nov 2010 15:41:16 +0000 Subject: [PATCH] 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 | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c index 60a56acc25..b376de288a 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, };