[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/4] 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.

Signed-off-by: Cole Robinson <crobinso redhat com>
---
 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 6575fe0..13056e8 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 a22ac5e..652448a 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 45d1069..ec3c7d9 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -376,6 +376,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 6816da8..2b7f083 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 4389120..91726cd 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
-- 
1.6.0.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]