From 9bcb1744738ad065d5247f2ba933e003d8b42546 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 15 Oct 2009 11:41:53 -0400 Subject: [PATCH] storage: Break out function to add pool source to a SourceList. Similar in theory to *AssignDef type functions, this duplicate functionality will be used by an future FindPoolSources implementations. --- src/conf/storage_conf.c | 22 +++++++++++++++++++ src/conf/storage_conf.h | 3 +++ src/libvirt_private.syms | 1 + src/storage/storage_backend_fs.c | 31 ++++++++++++++++----------- src/storage/storage_backend_logical.c | 9 ++------ 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 6575fe0d44..13056e8cac 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1633,6 +1633,28 @@ virStoragePoolObjDeleteDef(virConnectPtr conn, return 0; } +virStoragePoolSourcePtr +virStoragePoolSourceListNewSource(virConnectPtr conn, + virStoragePoolSourceListPtr list) +{ + virStoragePoolSourcePtr source; + + if (VIR_ALLOC(source) < 0) { + virReportOOMError(conn); + return NULL; + } + + if (VIR_REALLOC_N(list->sources, list->nsources+1) < 0) { + virReportOOMError(conn); + return NULL; + } + + source = &list->sources[list->nsources++]; + memset(source, 0, sizeof(*source)); + + return source; +} + char *virStoragePoolSourceListFormat(virConnectPtr conn, virStoragePoolSourceListPtr def) { diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index a22ac5e19f..652448a3bb 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -375,6 +375,9 @@ void virStoragePoolObjListFree(virStoragePoolObjListPtr pools); void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, virStoragePoolObjPtr pool); +virStoragePoolSourcePtr +virStoragePoolSourceListNewSource(virConnectPtr conn, + virStoragePoolSourceListPtr list); char *virStoragePoolSourceListFormat(virConnectPtr conn, virStoragePoolSourceListPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 98ea7f885e..86974c3af2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -380,6 +380,7 @@ virStoragePoolObjListFree; virStoragePoolObjRemove; virStoragePoolObjSaveDef; virStoragePoolSourceFree; +virStoragePoolSourceListNewSource; virStoragePoolSourceListFormat; virStorageVolDefFindByKey; virStorageVolDefFindByName; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 6816da8ed6..2b7f083452 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -136,14 +136,15 @@ struct _virNetfsDiscoverState { typedef struct _virNetfsDiscoverState virNetfsDiscoverState; static int -virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_UNUSED, +virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, char **const groups, void *data) { virNetfsDiscoverState *state = data; const char *name, *path; - virStoragePoolSource *src; + virStoragePoolSource *src = NULL; + int ret = -1; path = groups[0]; @@ -151,30 +152,34 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_U if (name == NULL) { virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, _("invalid netfs path (no /): %s"), path); - return -1; + goto cleanup; } name += 1; if (*name == '\0') { virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, _("invalid netfs path (ends in /): %s"), path); - return -1; + goto cleanup; } - if (VIR_REALLOC_N(state->list.sources, state->list.nsources+1) < 0) { - virReportOOMError(conn); - return -1; - } - memset(state->list.sources + state->list.nsources, 0, sizeof(*state->list.sources)); + if (!(src = virStoragePoolSourceListNewSource(conn, &state->list))) + goto cleanup; - src = state->list.sources + state->list.nsources++; if (!(src->host.name = strdup(state->host)) || - !(src->dir = strdup(path))) - return -1; + !(src->dir = strdup(path))) { + virReportOOMError(conn); + goto cleanup; + } src->format = VIR_STORAGE_POOL_NETFS_NFS; - return 0; + src = NULL; + ret = 0; +cleanup: + if (src) + virStoragePoolSourceFree(src); + return ret; } + static char * virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn, const char *srcSpec, diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 4389120815..91726cd5be 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -278,15 +278,10 @@ virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn, } if (thisSource == NULL) { - if (VIR_REALLOC_N(sourceList->sources, sourceList->nsources + 1) != 0) { - virReportOOMError(conn); + if (!(thisSource = virStoragePoolSourceListNewSource(conn, + sourceList))) goto err_no_memory; - } - thisSource = &sourceList->sources[sourceList->nsources]; - sourceList->nsources++; - - memset(thisSource, 0, sizeof(*thisSource)); thisSource->name = vgname; } else