static char * virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec, unsigned int flags) { 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; virCheckFlags(0, 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 virStorageBackendISCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, bool *isActive) { char *session = NULL; int ret = -1; *isActive = false; if (pool->def->source.host.name == NULL) { virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source host")); return -1; } if (pool->def->source.ndevice != 1 || pool->def->source.devices[0].path == NULL) { virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source device")); return -1; } if ((session = virStorageBackendISCSISession(pool, 1)) != NULL) { *isActive = true; VIR_FREE(session); } ret = 0; return ret; }
static char * virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec, unsigned int flags) { /* * # showmount --no-headers -e HOSTNAME * /tmp * * /A dir demo1.foo.bar,demo2.foo.bar * * Extract directory name (including possible interior spaces ...). */ const char *regexes[] = { "^(/.*\\S) +\\S+$" }; int vars[] = { 1 }; virNetfsDiscoverState state = { .host = NULL, .list = { .type = VIR_STORAGE_POOL_NETFS, .nsources = 0, .sources = NULL } }; const char *prog[] = { SHOWMOUNT, "--no-headers", "--exports", NULL, NULL }; virStoragePoolSourcePtr source = NULL; char *retval = NULL; unsigned int i; virCheckFlags(0, NULL); source = virStoragePoolDefParseSourceString(srcSpec, VIR_STORAGE_POOL_NETFS); if (!source) goto cleanup; state.host = source->host.name; prog[3] = source->host.name; if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars, virStorageBackendFileSystemNetFindPoolSourcesFunc, &state, NULL) < 0) goto cleanup; retval = virStoragePoolSourceListFormat(&state.list); if (retval == NULL) { virReportOOMError(); goto cleanup; } cleanup: for (i = 0; i < state.list.nsources; i++) virStoragePoolSourceClear(&state.list.sources[i]); VIR_FREE(state.list.sources); virStoragePoolSourceFree(source); return retval; }
static char * virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec, unsigned int flags) { /* * # showmount --no-headers -e HOSTNAME * /tmp * * /A dir demo1.foo.bar,demo2.foo.bar * * Extract directory name (including possible interior spaces ...). */ const char *regexes[] = { "^(/.*\\S) +\\S+$" }; int vars[] = { 1 }; virNetfsDiscoverState state = { .host = NULL, .list = { .type = VIR_STORAGE_POOL_NETFS, .nsources = 0, .sources = NULL } }; virStoragePoolSourcePtr source = NULL; char *retval = NULL; unsigned int i; virCommandPtr cmd = NULL; virCheckFlags(0, NULL); if (!srcSpec) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("hostname must be specified for netfs sources")); return NULL; } if (!(source = virStoragePoolDefParseSourceString(srcSpec, VIR_STORAGE_POOL_NETFS))) return NULL; if (source->nhost != 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Expected exactly 1 host for the storage pool")); goto cleanup; } state.host = source->hosts[0].name; cmd = virCommandNewArgList(SHOWMOUNT, "--no-headers", "--exports", source->hosts[0].name, NULL); if (virStorageBackendRunProgRegex(NULL, cmd, 1, regexes, vars, virStorageBackendFileSystemNetFindPoolSourcesFunc, &state, NULL) < 0) goto cleanup; retval = virStoragePoolSourceListFormat(&state.list); if (retval == NULL) { virReportOOMError(); goto cleanup; } cleanup: for (i = 0; i < state.list.nsources; i++) virStoragePoolSourceClear(&state.list.sources[i]); VIR_FREE(state.list.sources); virStoragePoolSourceFree(source); virCommandFree(cmd); return retval; }