mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
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.
This commit is contained in:
parent
fcbbb289b6
commit
9bcb174473
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -380,6 +380,7 @@ virStoragePoolObjListFree;
|
||||
virStoragePoolObjRemove;
|
||||
virStoragePoolObjSaveDef;
|
||||
virStoragePoolSourceFree;
|
||||
virStoragePoolSourceListNewSource;
|
||||
virStoragePoolSourceListFormat;
|
||||
virStorageVolDefFindByKey;
|
||||
virStorageVolDefFindByName;
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user