mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
storage: Store relative path only for relatively backed storage
Due to various refactors and compatibility with the virstoragetest the relPath field of the virStorageSource structure was always filled either with the relative name or the full path in case of absolutely backed storage. Return its original purpose to store only the relative name of the disk if it is backed relatively and tweak the tests.
This commit is contained in:
parent
89bb95059a
commit
7ba6a6f973
@ -2945,10 +2945,6 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
|
|||||||
if (!(cycle = virHashCreate(5, NULL)))
|
if (!(cycle = virHashCreate(5, NULL)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!src->relPath &&
|
|
||||||
VIR_STRDUP(src->relPath, src->path) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!src->relDir &&
|
if (!src->relDir &&
|
||||||
!(src->relDir = mdir_name(src->path))) {
|
!(src->relDir = mdir_name(src->path))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
|
@ -764,11 +764,11 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
VIR_DEBUG("relPath=%s, buf=%p, len=%zu, meta->format=%d",
|
VIR_DEBUG("path=%s, buf=%p, len=%zu, meta->format=%d",
|
||||||
meta->relPath, buf, len, meta->format);
|
meta->path, buf, len, meta->format);
|
||||||
|
|
||||||
if (meta->format == VIR_STORAGE_FILE_AUTO)
|
if (meta->format == VIR_STORAGE_FILE_AUTO)
|
||||||
meta->format = virStorageFileProbeFormatFromBuf(meta->relPath, buf, len);
|
meta->format = virStorageFileProbeFormatFromBuf(meta->path, buf, len);
|
||||||
|
|
||||||
if (meta->format <= VIR_STORAGE_FILE_NONE ||
|
if (meta->format <= VIR_STORAGE_FILE_NONE ||
|
||||||
meta->format >= VIR_STORAGE_FILE_LAST) {
|
meta->format >= VIR_STORAGE_FILE_LAST) {
|
||||||
@ -908,9 +908,6 @@ virStorageFileMetadataNew(const char *path,
|
|||||||
ret->format = format;
|
ret->format = format;
|
||||||
ret->type = VIR_STORAGE_TYPE_FILE;
|
ret->type = VIR_STORAGE_TYPE_FILE;
|
||||||
|
|
||||||
if (VIR_STRDUP(ret->relPath, path) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (VIR_STRDUP(ret->path, path) < 0)
|
if (VIR_STRDUP(ret->path, path) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -1378,7 +1375,8 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
|
|||||||
if (idx == i)
|
if (idx == i)
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (STREQ_NULLABLE(name, chain->relPath))
|
if (STREQ_NULLABLE(name, chain->relPath) ||
|
||||||
|
STREQ(name, chain->path))
|
||||||
break;
|
break;
|
||||||
if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE ||
|
if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE ||
|
||||||
chain->type == VIR_STORAGE_TYPE_BLOCK)) {
|
chain->type == VIR_STORAGE_TYPE_BLOCK)) {
|
||||||
@ -1625,6 +1623,10 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
|
|||||||
|
|
||||||
ret->backingRelative = true;
|
ret->backingRelative = true;
|
||||||
|
|
||||||
|
/* store relative name */
|
||||||
|
if (VIR_STRDUP(ret->relPath, parent->backingStoreRaw) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
/* XXX Once we get rid of the need to use canonical names in path, we will be
|
/* XXX Once we get rid of the need to use canonical names in path, we will be
|
||||||
* able to use mdir_name on parent->path instead of using parent->relDir */
|
* able to use mdir_name on parent->path instead of using parent->relDir */
|
||||||
if (STRNEQ(parent->relDir, "/"))
|
if (STRNEQ(parent->relDir, "/"))
|
||||||
@ -1939,11 +1941,6 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent)
|
|||||||
ret = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw);
|
ret = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (VIR_STRDUP(ret->relPath, parent->backingStoreRaw) < 0) {
|
|
||||||
virStorageSourceFree(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* possibly update local type */
|
/* possibly update local type */
|
||||||
if (ret->type == VIR_STORAGE_TYPE_FILE) {
|
if (ret->type == VIR_STORAGE_TYPE_FILE) {
|
||||||
if (stat(ret->path, &st) == 0) {
|
if (stat(ret->path, &st) == 0) {
|
||||||
|
@ -247,8 +247,8 @@ struct _virStorageSource {
|
|||||||
virStorageDriverDataPtr drv;
|
virStorageDriverDataPtr drv;
|
||||||
|
|
||||||
/* metadata about storage image which need separate fields */
|
/* metadata about storage image which need separate fields */
|
||||||
/* Name of the current file as spelled by the user (top level) or
|
/* Relative name by which this image was opened from its parent, or NULL
|
||||||
* metadata of the overlay (if this is a backing store). */
|
* if this image was opened by absolute name */
|
||||||
char *relPath;
|
char *relPath;
|
||||||
/* Directory to start from if backingStoreRaw is a relative file
|
/* Directory to start from if backingStoreRaw is a relative file
|
||||||
* name. */
|
* name. */
|
||||||
|
@ -116,9 +116,6 @@ testStorageFileGetMetadata(const char *path,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_STRDUP(ret->relPath, path) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(ret->relDir = mdir_name(path))) {
|
if (!(ret->relDir = mdir_name(path))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto error;
|
goto error;
|
||||||
@ -371,7 +368,6 @@ testStorageChain(const void *args)
|
|||||||
while (elt) {
|
while (elt) {
|
||||||
char *expect = NULL;
|
char *expect = NULL;
|
||||||
char *actual = NULL;
|
char *actual = NULL;
|
||||||
const char *expPath;
|
|
||||||
const char *expRelDir;
|
const char *expRelDir;
|
||||||
|
|
||||||
if (i == data->nfiles) {
|
if (i == data->nfiles) {
|
||||||
@ -379,8 +375,6 @@ testStorageChain(const void *args)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
expPath = isAbs ? data->files[i]->pathAbs
|
|
||||||
: data->files[i]->pathRel;
|
|
||||||
expRelDir = isAbs ? data->files[i]->relDirAbs
|
expRelDir = isAbs ? data->files[i]->relDirAbs
|
||||||
: data->files[i]->relDirRel;
|
: data->files[i]->relDirRel;
|
||||||
if (virAsprintf(&expect,
|
if (virAsprintf(&expect,
|
||||||
@ -389,7 +383,7 @@ testStorageChain(const void *args)
|
|||||||
NULLSTR(data->files[i]->expBackingStoreRaw),
|
NULLSTR(data->files[i]->expBackingStoreRaw),
|
||||||
data->files[i]->expCapacity,
|
data->files[i]->expCapacity,
|
||||||
data->files[i]->expEncrypted,
|
data->files[i]->expEncrypted,
|
||||||
NULLSTR(expPath),
|
NULLSTR(data->files[i]->pathRel),
|
||||||
NULLSTR(expRelDir),
|
NULLSTR(expRelDir),
|
||||||
data->files[i]->type,
|
data->files[i]->type,
|
||||||
data->files[i]->format) < 0 ||
|
data->files[i]->format) < 0 ||
|
||||||
@ -740,7 +734,6 @@ mymain(void)
|
|||||||
|
|
||||||
/* Raw image, whether with right format or no specified format */
|
/* Raw image, whether with right format or no specified format */
|
||||||
testFileData raw = {
|
testFileData raw = {
|
||||||
.pathRel = "raw",
|
|
||||||
.pathAbs = canonraw,
|
.pathAbs = canonraw,
|
||||||
.path = canonraw,
|
.path = canonraw,
|
||||||
.relDirRel = ".",
|
.relDirRel = ".",
|
||||||
@ -761,10 +754,10 @@ mymain(void)
|
|||||||
|
|
||||||
/* Qcow2 file with relative raw backing, format provided */
|
/* Qcow2 file with relative raw backing, format provided */
|
||||||
raw.pathAbs = "raw";
|
raw.pathAbs = "raw";
|
||||||
|
raw.pathRel = "raw";
|
||||||
testFileData qcow2 = {
|
testFileData qcow2 = {
|
||||||
.expBackingStoreRaw = "raw",
|
.expBackingStoreRaw = "raw",
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "qcow2",
|
|
||||||
.pathAbs = canonqcow2,
|
.pathAbs = canonqcow2,
|
||||||
.path = canonqcow2,
|
.path = canonqcow2,
|
||||||
.relDirRel = ".",
|
.relDirRel = ".",
|
||||||
@ -773,7 +766,6 @@ mymain(void)
|
|||||||
.format = VIR_STORAGE_FILE_QCOW2,
|
.format = VIR_STORAGE_FILE_QCOW2,
|
||||||
};
|
};
|
||||||
testFileData qcow2_as_raw = {
|
testFileData qcow2_as_raw = {
|
||||||
.pathRel = "qcow2",
|
|
||||||
.pathAbs = canonqcow2,
|
.pathAbs = canonqcow2,
|
||||||
.path = canonqcow2,
|
.path = canonqcow2,
|
||||||
.relDirRel = ".",
|
.relDirRel = ".",
|
||||||
@ -799,7 +791,7 @@ mymain(void)
|
|||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
qcow2.expBackingStoreRaw = absraw;
|
qcow2.expBackingStoreRaw = absraw;
|
||||||
raw.pathRel = absraw;
|
raw.pathRel = NULL;
|
||||||
raw.pathAbs = absraw;
|
raw.pathAbs = absraw;
|
||||||
raw.relDirRel = datadir;
|
raw.relDirRel = datadir;
|
||||||
|
|
||||||
@ -819,7 +811,6 @@ mymain(void)
|
|||||||
testFileData wrap = {
|
testFileData wrap = {
|
||||||
.expBackingStoreRaw = absqcow2,
|
.expBackingStoreRaw = absqcow2,
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "wrap",
|
|
||||||
.pathAbs = abswrap,
|
.pathAbs = abswrap,
|
||||||
.path = canonwrap,
|
.path = canonwrap,
|
||||||
.relDirRel = ".",
|
.relDirRel = ".",
|
||||||
@ -827,7 +818,6 @@ mymain(void)
|
|||||||
.type = VIR_STORAGE_TYPE_FILE,
|
.type = VIR_STORAGE_TYPE_FILE,
|
||||||
.format = VIR_STORAGE_FILE_QCOW2,
|
.format = VIR_STORAGE_FILE_QCOW2,
|
||||||
};
|
};
|
||||||
qcow2.pathRel = absqcow2;
|
|
||||||
qcow2.relDirRel = datadir;
|
qcow2.relDirRel = datadir;
|
||||||
TEST_CHAIN(7, "wrap", abswrap, VIR_STORAGE_FILE_QCOW2,
|
TEST_CHAIN(7, "wrap", abswrap, VIR_STORAGE_FILE_QCOW2,
|
||||||
(&wrap, &qcow2, &raw), EXP_PASS,
|
(&wrap, &qcow2, &raw), EXP_PASS,
|
||||||
@ -847,14 +837,12 @@ mymain(void)
|
|||||||
"-b", absqcow2, "wrap", NULL);
|
"-b", absqcow2, "wrap", NULL);
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
qcow2_as_raw.pathRel = absqcow2;
|
|
||||||
qcow2_as_raw.relDirRel = datadir;
|
qcow2_as_raw.relDirRel = datadir;
|
||||||
|
|
||||||
/* Qcow2 file with raw as absolute backing, backing format omitted */
|
/* Qcow2 file with raw as absolute backing, backing format omitted */
|
||||||
testFileData wrap_as_raw = {
|
testFileData wrap_as_raw = {
|
||||||
.expBackingStoreRaw = absqcow2,
|
.expBackingStoreRaw = absqcow2,
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "wrap",
|
|
||||||
.pathAbs = abswrap,
|
.pathAbs = abswrap,
|
||||||
.path = canonwrap,
|
.path = canonwrap,
|
||||||
.relDirRel = ".",
|
.relDirRel = ".",
|
||||||
@ -876,7 +864,6 @@ mymain(void)
|
|||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
qcow2.expBackingStoreRaw = datadir "/bogus";
|
qcow2.expBackingStoreRaw = datadir "/bogus";
|
||||||
qcow2.pathRel = "qcow2";
|
|
||||||
qcow2.relDirRel = ".";
|
qcow2.relDirRel = ".";
|
||||||
|
|
||||||
/* Qcow2 file with missing backing file but specified type */
|
/* Qcow2 file with missing backing file but specified type */
|
||||||
@ -911,7 +898,6 @@ mymain(void)
|
|||||||
|
|
||||||
/* Qcow2 file with backing protocol instead of file */
|
/* Qcow2 file with backing protocol instead of file */
|
||||||
testFileData nbd = {
|
testFileData nbd = {
|
||||||
.pathRel = "nbd:example.org:6000:exportname=blah",
|
|
||||||
.pathAbs = "nbd:example.org:6000:exportname=blah",
|
.pathAbs = "nbd:example.org:6000:exportname=blah",
|
||||||
.path = "blah",
|
.path = "blah",
|
||||||
.type = VIR_STORAGE_TYPE_NETWORK,
|
.type = VIR_STORAGE_TYPE_NETWORK,
|
||||||
@ -929,7 +915,6 @@ mymain(void)
|
|||||||
testFileData qed = {
|
testFileData qed = {
|
||||||
.expBackingStoreRaw = absraw,
|
.expBackingStoreRaw = absraw,
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "qed",
|
|
||||||
.pathAbs = absqed,
|
.pathAbs = absqed,
|
||||||
.path = canonqed,
|
.path = canonqed,
|
||||||
.relDirRel = ".",
|
.relDirRel = ".",
|
||||||
@ -938,7 +923,6 @@ mymain(void)
|
|||||||
.format = VIR_STORAGE_FILE_QED,
|
.format = VIR_STORAGE_FILE_QED,
|
||||||
};
|
};
|
||||||
testFileData qed_as_raw = {
|
testFileData qed_as_raw = {
|
||||||
.pathRel = "qed",
|
|
||||||
.pathAbs = absqed,
|
.pathAbs = absqed,
|
||||||
.path = canonqed,
|
.path = canonqed,
|
||||||
.relDirRel = ".",
|
.relDirRel = ".",
|
||||||
@ -954,7 +938,6 @@ mymain(void)
|
|||||||
|
|
||||||
/* directory */
|
/* directory */
|
||||||
testFileData dir = {
|
testFileData dir = {
|
||||||
.pathRel = "dir",
|
|
||||||
.pathAbs = absdir,
|
.pathAbs = absdir,
|
||||||
.path = canondir,
|
.path = canondir,
|
||||||
.relDirRel = ".",
|
.relDirRel = ".",
|
||||||
@ -1004,7 +987,6 @@ mymain(void)
|
|||||||
testFileData link2 = {
|
testFileData link2 = {
|
||||||
.expBackingStoreRaw = "../sub/link1",
|
.expBackingStoreRaw = "../sub/link1",
|
||||||
.expCapacity = 1024,
|
.expCapacity = 1024,
|
||||||
.pathRel = "sub/link2",
|
|
||||||
.pathAbs = abslink2,
|
.pathAbs = abslink2,
|
||||||
.path = canonwrap,
|
.path = canonwrap,
|
||||||
.relDirRel = "sub",
|
.relDirRel = "sub",
|
||||||
@ -1051,7 +1033,6 @@ mymain(void)
|
|||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
qcow2.expBackingStoreRaw = "wrap";
|
qcow2.expBackingStoreRaw = "wrap";
|
||||||
qcow2.pathRel = absqcow2;
|
|
||||||
qcow2.relDirRel = datadir;
|
qcow2.relDirRel = datadir;
|
||||||
|
|
||||||
/* Behavior of an infinite loop chain */
|
/* Behavior of an infinite loop chain */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user