提交 9bcb1744 编写于 作者: C Cole Robinson

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.
上级 fcbbb289
...@@ -1633,6 +1633,28 @@ virStoragePoolObjDeleteDef(virConnectPtr conn, ...@@ -1633,6 +1633,28 @@ virStoragePoolObjDeleteDef(virConnectPtr conn,
return 0; 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, char *virStoragePoolSourceListFormat(virConnectPtr conn,
virStoragePoolSourceListPtr def) virStoragePoolSourceListPtr def)
{ {
......
...@@ -375,6 +375,9 @@ void virStoragePoolObjListFree(virStoragePoolObjListPtr pools); ...@@ -375,6 +375,9 @@ void virStoragePoolObjListFree(virStoragePoolObjListPtr pools);
void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, void virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
virStoragePoolObjPtr pool); virStoragePoolObjPtr pool);
virStoragePoolSourcePtr
virStoragePoolSourceListNewSource(virConnectPtr conn,
virStoragePoolSourceListPtr list);
char *virStoragePoolSourceListFormat(virConnectPtr conn, char *virStoragePoolSourceListFormat(virConnectPtr conn,
virStoragePoolSourceListPtr def); virStoragePoolSourceListPtr def);
......
...@@ -380,6 +380,7 @@ virStoragePoolObjListFree; ...@@ -380,6 +380,7 @@ virStoragePoolObjListFree;
virStoragePoolObjRemove; virStoragePoolObjRemove;
virStoragePoolObjSaveDef; virStoragePoolObjSaveDef;
virStoragePoolSourceFree; virStoragePoolSourceFree;
virStoragePoolSourceListNewSource;
virStoragePoolSourceListFormat; virStoragePoolSourceListFormat;
virStorageVolDefFindByKey; virStorageVolDefFindByKey;
virStorageVolDefFindByName; virStorageVolDefFindByName;
......
...@@ -136,14 +136,15 @@ struct _virNetfsDiscoverState { ...@@ -136,14 +136,15 @@ struct _virNetfsDiscoverState {
typedef struct _virNetfsDiscoverState virNetfsDiscoverState; typedef struct _virNetfsDiscoverState virNetfsDiscoverState;
static int static int
virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_UNUSED, virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn,
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
char **const groups, char **const groups,
void *data) void *data)
{ {
virNetfsDiscoverState *state = data; virNetfsDiscoverState *state = data;
const char *name, *path; const char *name, *path;
virStoragePoolSource *src; virStoragePoolSource *src = NULL;
int ret = -1;
path = groups[0]; path = groups[0];
...@@ -151,30 +152,34 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_U ...@@ -151,30 +152,34 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_U
if (name == NULL) { if (name == NULL) {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("invalid netfs path (no /): %s"), path); _("invalid netfs path (no /): %s"), path);
return -1; goto cleanup;
} }
name += 1; name += 1;
if (*name == '\0') { if (*name == '\0') {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("invalid netfs path (ends in /): %s"), path); _("invalid netfs path (ends in /): %s"), path);
return -1; goto cleanup;
} }
if (VIR_REALLOC_N(state->list.sources, state->list.nsources+1) < 0) { if (!(src = virStoragePoolSourceListNewSource(conn, &state->list)))
virReportOOMError(conn); goto cleanup;
return -1;
}
memset(state->list.sources + state->list.nsources, 0, sizeof(*state->list.sources));
src = state->list.sources + state->list.nsources++;
if (!(src->host.name = strdup(state->host)) || if (!(src->host.name = strdup(state->host)) ||
!(src->dir = strdup(path))) !(src->dir = strdup(path))) {
return -1; virReportOOMError(conn);
goto cleanup;
}
src->format = VIR_STORAGE_POOL_NETFS_NFS; src->format = VIR_STORAGE_POOL_NETFS_NFS;
return 0; src = NULL;
ret = 0;
cleanup:
if (src)
virStoragePoolSourceFree(src);
return ret;
} }
static char * static char *
virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn, virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn,
const char *srcSpec, const char *srcSpec,
......
...@@ -278,15 +278,10 @@ virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn, ...@@ -278,15 +278,10 @@ virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn,
} }
if (thisSource == NULL) { if (thisSource == NULL) {
if (VIR_REALLOC_N(sourceList->sources, sourceList->nsources + 1) != 0) { if (!(thisSource = virStoragePoolSourceListNewSource(conn,
virReportOOMError(conn); sourceList)))
goto err_no_memory; goto err_no_memory;
}
thisSource = &sourceList->sources[sourceList->nsources];
sourceList->nsources++;
memset(thisSource, 0, sizeof(*thisSource));
thisSource->name = vgname; thisSource->name = vgname;
} }
else else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册