mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
storage: netfs: Split up and tidy up NFS storage pool source function
Extract the NFS related stuff into a separate function and tidy up the rest of the code so we can reuse it to add gluster backend detection. Additionally avoid reporting of errors from "showmount" and return an empty source list instead. This will help when adding other detection backends.
This commit is contained in:
parent
09544abf2a
commit
18642d100f
@ -242,10 +242,8 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(char **const groups,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static void
|
||||||
virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
virStorageBackendFileSystemNetFindNFSPoolSources(virNetfsDiscoverState *state)
|
||||||
const char *srcSpec,
|
|
||||||
unsigned int flags)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* # showmount --no-headers -e HOSTNAME
|
* # showmount --no-headers -e HOSTNAME
|
||||||
@ -261,6 +259,29 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
|
|||||||
int vars[] = {
|
int vars[] = {
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virCommandPtr cmd = NULL;
|
||||||
|
|
||||||
|
cmd = virCommandNewArgList(SHOWMOUNT,
|
||||||
|
"--no-headers",
|
||||||
|
"--exports",
|
||||||
|
state->host,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (virCommandRunRegex(cmd, 1, regexes, vars,
|
||||||
|
virStorageBackendFileSystemNetFindPoolSourcesFunc,
|
||||||
|
&state, NULL) < 0)
|
||||||
|
virResetLastError();
|
||||||
|
|
||||||
|
virCommandFree(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *
|
||||||
|
virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
|
const char *srcSpec,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
virNetfsDiscoverState state = {
|
virNetfsDiscoverState state = {
|
||||||
.host = NULL,
|
.host = NULL,
|
||||||
.list = {
|
.list = {
|
||||||
@ -270,15 +291,14 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
virStoragePoolSourcePtr source = NULL;
|
virStoragePoolSourcePtr source = NULL;
|
||||||
char *retval = NULL;
|
char *ret = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
virCommandPtr cmd = NULL;
|
|
||||||
|
|
||||||
virCheckFlags(0, NULL);
|
virCheckFlags(0, NULL);
|
||||||
|
|
||||||
if (!srcSpec) {
|
if (!srcSpec) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
"%s", _("hostname must be specified for netfs sources"));
|
_("hostname must be specified for netfs sources"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,19 +314,9 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
|
|||||||
|
|
||||||
state.host = source->hosts[0].name;
|
state.host = source->hosts[0].name;
|
||||||
|
|
||||||
cmd = virCommandNewArgList(SHOWMOUNT,
|
virStorageBackendFileSystemNetFindNFSPoolSources(&state);
|
||||||
"--no-headers",
|
|
||||||
"--exports",
|
|
||||||
source->hosts[0].name,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (virCommandRunRegex(cmd, 1, regexes, vars,
|
if (!(ret = virStoragePoolSourceListFormat(&state.list)))
|
||||||
virStorageBackendFileSystemNetFindPoolSourcesFunc,
|
|
||||||
&state, NULL) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
retval = virStoragePoolSourceListFormat(&state.list);
|
|
||||||
if (retval == NULL)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -315,8 +325,7 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
|
|||||||
VIR_FREE(state.list.sources);
|
VIR_FREE(state.list.sources);
|
||||||
|
|
||||||
virStoragePoolSourceFree(source);
|
virStoragePoolSourceFree(source);
|
||||||
virCommandFree(cmd);
|
return ret;
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user