mirror of https://gitee.com/openkylin/libvirt.git
storage: Don't canonicalize paths unnecessarily
Store backing chain paths as non-canonical. The canonicalization step will be already taken. This will allow to avoid storing unnecessary amounts of data.
This commit is contained in:
parent
4074ad2d74
commit
e71437fff2
|
@ -1044,25 +1044,17 @@ virStorageFileGetMetadataFromFD(const char *path,
|
||||||
int *backingFormat)
|
int *backingFormat)
|
||||||
|
|
||||||
{
|
{
|
||||||
virStorageSourcePtr ret = NULL;
|
virStorageSourcePtr ret;
|
||||||
char *canonPath = NULL;
|
|
||||||
|
|
||||||
if (!(canonPath = canonicalize_file_name(path))) {
|
if (!(ret = virStorageFileMetadataNew(path, format)))
|
||||||
virReportSystemError(errno, _("unable to resolve '%s'"), path);
|
return NULL;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(ret = virStorageFileMetadataNew(canonPath, format)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
|
|
||||||
if (virStorageFileGetMetadataFromFDInternal(ret, fd, backingFormat) < 0) {
|
if (virStorageFileGetMetadataFromFDInternal(ret, fd, backingFormat) < 0) {
|
||||||
virStorageSourceFree(ret);
|
virStorageSourceFree(ret);
|
||||||
ret = NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(canonPath);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1641,15 +1633,6 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX we don't currently need to store the canonical path but the
|
|
||||||
* change would break the test suite. Get rid of this later */
|
|
||||||
char *tmp = ret->path;
|
|
||||||
if (!(ret->path = canonicalize_file_name(tmp))) {
|
|
||||||
ret->path = tmp;
|
|
||||||
tmp = NULL;
|
|
||||||
}
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
} else {
|
} else {
|
||||||
ret->type = VIR_STORAGE_TYPE_NETWORK;
|
ret->type = VIR_STORAGE_TYPE_NETWORK;
|
||||||
|
|
||||||
|
@ -1888,12 +1871,8 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX we don't currently need to store the canonical path but the
|
if (VIR_STRDUP(ret->path, path) < 0)
|
||||||
* change would break the test suite. Get rid of this later */
|
goto error;
|
||||||
if (!(ret->path = canonicalize_file_name(path))) {
|
|
||||||
if (VIR_STRDUP(ret->path, path) < 0)
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ret->type = VIR_STORAGE_TYPE_NETWORK;
|
ret->type = VIR_STORAGE_TYPE_NETWORK;
|
||||||
|
|
||||||
|
|
|
@ -121,10 +121,8 @@ testStorageFileGetMetadata(const char *path,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ret->path = canonicalize_file_name(path))) {
|
if (VIR_STRDUP(ret->path, path) < 0)
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "failed to resolve '%s'", path);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
if (virStorageFileGetMetadata(ret, uid, gid, allow_probe) < 0)
|
if (virStorageFileGetMetadata(ret, uid, gid, allow_probe) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -905,7 +903,7 @@ mymain(void)
|
||||||
.expBackingStoreRaw = "../raw",
|
.expBackingStoreRaw = "../raw",
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "../sub/link1",
|
.pathRel = "../sub/link1",
|
||||||
.path = canonqcow2,
|
.path = datadir "/sub/../sub/link1",
|
||||||
.relDir = datadir "/sub/../sub",
|
.relDir = datadir "/sub/../sub",
|
||||||
.type = VIR_STORAGE_TYPE_FILE,
|
.type = VIR_STORAGE_TYPE_FILE,
|
||||||
.format = VIR_STORAGE_FILE_QCOW2,
|
.format = VIR_STORAGE_FILE_QCOW2,
|
||||||
|
@ -913,11 +911,13 @@ mymain(void)
|
||||||
testFileData link2 = {
|
testFileData link2 = {
|
||||||
.expBackingStoreRaw = "../sub/link1",
|
.expBackingStoreRaw = "../sub/link1",
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.path = canonwrap,
|
.path = abslink2,
|
||||||
.relDir = datadir "/sub",
|
.relDir = datadir "/sub",
|
||||||
.type = VIR_STORAGE_TYPE_FILE,
|
.type = VIR_STORAGE_TYPE_FILE,
|
||||||
.format = VIR_STORAGE_FILE_QCOW2,
|
.format = VIR_STORAGE_FILE_QCOW2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
raw.path = datadir "/sub/../sub/../raw";
|
||||||
raw.pathRel = "../raw";
|
raw.pathRel = "../raw";
|
||||||
raw.relDir = datadir "/sub/../sub/..";
|
raw.relDir = datadir "/sub/../sub/..";
|
||||||
TEST_CHAIN(15, abslink2, VIR_STORAGE_FILE_QCOW2,
|
TEST_CHAIN(15, abslink2, VIR_STORAGE_FILE_QCOW2,
|
||||||
|
|
Loading…
Reference in New Issue