storage: Create helper for virStorageBackendLogicalFindPoolSources

Rework virStorageBackendLogicalFindPoolSources a bit to create a
helper virStorageBackendLogicalGetPoolSources that will make the
pvs call in order to generate a list of associated pv_name and vg_name's.

A future patch will make use of this for start/check processing to
ensure the storage pool source definition matches expectations.
This commit is contained in:
John Ferlan 2015-12-07 11:27:03 -05:00
parent dae7007d6e
commit ae5519f7f8

View File

@ -414,10 +414,16 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **const groups,
return -1; return -1;
} }
static char * /*
virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, * @sourceList: Pointer to a storage pool source list
const char *srcSpec ATTRIBUTE_UNUSED, *
unsigned int flags) * Use the pvs command to fill the list of pv_name and vg_name associated
* into the passed sourceList.
*
* Returns 0 if successful, -1 and sets error on failure
*/
static int
virStorageBackendLogicalGetPoolSources(virStoragePoolSourceListPtr sourceList)
{ {
/* /*
* # pvs --noheadings -o pv_name,vg_name * # pvs --noheadings -o pv_name,vg_name
@ -431,11 +437,7 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
2 2
}; };
virCommandPtr cmd; virCommandPtr cmd;
char *retval = NULL; int ret = -1;
virStoragePoolSourceList sourceList;
size_t i;
virCheckFlags(0, NULL);
/* /*
* NOTE: ignoring errors here; this is just to "touch" any logical volumes * NOTE: ignoring errors here; this is just to "touch" any logical volumes
@ -447,20 +449,38 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
VIR_WARN("Failure when running vgscan to refresh physical volumes"); VIR_WARN("Failure when running vgscan to refresh physical volumes");
virCommandFree(cmd); virCommandFree(cmd);
memset(&sourceList, 0, sizeof(sourceList));
sourceList.type = VIR_STORAGE_POOL_LOGICAL;
cmd = virCommandNewArgList(PVS, cmd = virCommandNewArgList(PVS,
"--noheadings", "--noheadings",
"-o", "pv_name,vg_name", "-o", "pv_name,vg_name",
NULL); NULL);
if (virCommandRunRegex(cmd, 1, regexes, vars, if (virCommandRunRegex(cmd, 1, regexes, vars,
virStorageBackendLogicalFindPoolSourcesFunc, virStorageBackendLogicalFindPoolSourcesFunc,
&sourceList, "pvs") < 0) { sourceList, "pvs") < 0)
virCommandFree(cmd); goto cleanup;
return NULL; ret = 0;
}
cleanup:
virCommandFree(cmd); virCommandFree(cmd);
return ret;
}
static char *
virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
const char *srcSpec ATTRIBUTE_UNUSED,
unsigned int flags)
{
virStoragePoolSourceList sourceList;
size_t i;
char *retval = NULL;
virCheckFlags(0, NULL);
memset(&sourceList, 0, sizeof(sourceList));
sourceList.type = VIR_STORAGE_POOL_LOGICAL;
if (virStorageBackendLogicalGetPoolSources(&sourceList) < 0)
goto cleanup;
retval = virStoragePoolSourceListFormat(&sourceList); retval = virStoragePoolSourceListFormat(&sourceList);
if (retval == NULL) { if (retval == NULL) {