mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: storage: Invert the way recursive metadata retrieval works
To avoid having the root of a backing chain present twice in the list we need to invert the working of virStorageFileGetMetadataRecurse. Until now the recursive worker created a new backing chain element from the name and other information passed as arguments. This required us to pass the data of the parent in a deconstructed way and the worker created a new entry for the parent. This patch converts this function so that it just fills in metadata about the parent and creates a backing chain element from those. This removes the duplication of the first element. To avoid breaking the test suite, virstoragetest now calls a wrapper that creates the parent structure explicitly and pre-fills it with the test data with same function signature as previously used.
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "virlog.h"
|
||||
#include "virstoragefile.h"
|
||||
#include "virstring.h"
|
||||
#include "dirname.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
@@ -88,6 +89,44 @@ testCleanupImages(void)
|
||||
virFileDeleteTree(datadir);
|
||||
}
|
||||
|
||||
|
||||
static virStorageSourcePtr
|
||||
testStorageFileGetMetadata(const char *path,
|
||||
int format,
|
||||
uid_t uid, gid_t gid,
|
||||
bool allow_probe)
|
||||
{
|
||||
virStorageSourcePtr ret = NULL;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
|
||||
ret->type = VIR_STORAGE_TYPE_FILE;
|
||||
ret->format = format;
|
||||
|
||||
if (VIR_STRDUP(ret->relPath, path) < 0)
|
||||
goto error;
|
||||
|
||||
if (!(ret->relDir = mdir_name(path))) {
|
||||
virReportOOMError();
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(ret->path = canonicalize_file_name(path))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "failed to resolve '%s'", path);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (virStorageFileGetMetadata(ret, uid, gid, allow_probe) < 0)
|
||||
goto error;
|
||||
|
||||
return ret;
|
||||
|
||||
error:
|
||||
virStorageSourceFree(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
testPrepImages(void)
|
||||
{
|
||||
@@ -272,8 +311,8 @@ testStorageChain(const void *args)
|
||||
char *broken = NULL;
|
||||
bool isAbs = !!(data->flags & ABS_START);
|
||||
|
||||
meta = virStorageFileGetMetadata(data->start, data->format, -1, -1,
|
||||
(data->flags & ALLOW_PROBE) != 0);
|
||||
meta = testStorageFileGetMetadata(data->start, data->format, -1, -1,
|
||||
(data->flags & ALLOW_PROBE) != 0);
|
||||
if (!meta) {
|
||||
if (data->flags & EXP_FAIL) {
|
||||
virResetLastError();
|
||||
@@ -825,8 +864,8 @@ mymain(void)
|
||||
ret = -1;
|
||||
|
||||
/* Test behavior of chain lookups, absolute backing from relative start */
|
||||
chain = virStorageFileGetMetadata("wrap", VIR_STORAGE_FILE_QCOW2,
|
||||
-1, -1, false);
|
||||
chain = testStorageFileGetMetadata("wrap", VIR_STORAGE_FILE_QCOW2,
|
||||
-1, -1, false);
|
||||
if (!chain) {
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
@@ -870,8 +909,8 @@ mymain(void)
|
||||
|
||||
/* Test behavior of chain lookups, relative backing from absolute start */
|
||||
virStorageSourceFree(chain);
|
||||
chain = virStorageFileGetMetadata(abswrap, VIR_STORAGE_FILE_QCOW2,
|
||||
-1, -1, false);
|
||||
chain = testStorageFileGetMetadata(abswrap, VIR_STORAGE_FILE_QCOW2,
|
||||
-1, -1, false);
|
||||
if (!chain) {
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
@@ -900,8 +939,8 @@ mymain(void)
|
||||
|
||||
/* Test behavior of chain lookups, relative backing */
|
||||
virStorageSourceFree(chain);
|
||||
chain = virStorageFileGetMetadata("sub/link2", VIR_STORAGE_FILE_QCOW2,
|
||||
-1, -1, false);
|
||||
chain = testStorageFileGetMetadata("sub/link2", VIR_STORAGE_FILE_QCOW2,
|
||||
-1, -1, false);
|
||||
if (!chain) {
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
|
||||
Reference in New Issue
Block a user