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 abslutely backed
storage. Return it's original purpose to store only the relative name of
the disk if it is backed relatively and tweak the tests.
---
src/storage/storage_driver.c | 4 ----
src/util/virstoragefile.c | 21 +++++++++------------
src/util/virstoragefile.h | 4 ++--
tests/virstoragetest.c | 25 +++----------------------
4 files changed, 14 insertions(+), 40 deletions(-)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 7116185..c6e2936 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2944,10 +2944,6 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
if (!(cycle = virHashCreate(5, NULL)))
return -1;
- if (!src->relPath &&
- VIR_STRDUP(src->relPath, src->path) < 0)
- goto cleanup;
-
if (!src->relDir &&
!(src->relDir = mdir_name(src->path))) {
virReportOOMError();
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index ac3bcba..7b4e46a 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -764,11 +764,11 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
{
int ret = -1;
- VIR_DEBUG("relPath=%s, buf=%p, len=%zu, meta->format=%d",
- meta->relPath, buf, len, meta->format);
+ VIR_DEBUG("path=%s, buf=%p, len=%zu, meta->format=%d",
+ meta->path, buf, len, meta->format);
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 ||
meta->format >= VIR_STORAGE_FILE_LAST) {
@@ -908,9 +908,6 @@ virStorageFileMetadataNew(const char *path,
ret->format = format;
ret->type = VIR_STORAGE_TYPE_FILE;
- if (VIR_STRDUP(ret->relPath, path) < 0)
- goto error;
-
if (VIR_STRDUP(ret->path, path) < 0)
goto error;
@@ -1378,7 +1375,8 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
if (idx == i)
break;
} else {
- if (STREQ_NULLABLE(name, chain->relPath))
+ if (STREQ_NULLABLE(name, chain->relPath) ||
+ STREQ(name, chain->path))
break;
if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE ||
chain->type == VIR_STORAGE_TYPE_BLOCK)) {
@@ -1602,6 +1600,10 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
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
* able to use mdir_name on parent->path instead of using parent->relDir */
if (STRNEQ(parent->relDir, "/"))
@@ -1916,11 +1918,6 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent)
ret = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw);
if (ret) {
- if (VIR_STRDUP(ret->relPath, parent->backingStoreRaw) < 0) {
- virStorageSourceFree(ret);
- return NULL;
- }
-
/* possibly update local type */
if (ret->type == VIR_STORAGE_TYPE_FILE) {
if (stat(ret->path, &st) == 0) {
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index ff8130d..38d1720 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -247,8 +247,8 @@ struct _virStorageSource {
virStorageDriverDataPtr drv;
/* metadata about storage image which need separate fields */
- /* Name of the current file as spelled by the user (top level) or
- * metadata of the overlay (if this is a backing store). */
+ /* Relative path of the backing image from the parent NULL if
+ * backed by absolute path */
char *relPath;
/* Directory to start from if backingStoreRaw is a relative file
* name. */
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index d3dc007..e2a06f2 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -116,9 +116,6 @@ testStorageFileGetMetadata(const char *path,
}
}
- if (VIR_STRDUP(ret->relPath, path) < 0)
- goto error;
-
if (!(ret->relDir = mdir_name(path))) {
virReportOOMError();
goto error;
@@ -371,7 +368,6 @@ testStorageChain(const void *args)
while (elt) {
char *expect = NULL;
char *actual = NULL;
- const char *expPath;
const char *expRelDir;
if (i == data->nfiles) {
@@ -379,8 +375,6 @@ testStorageChain(const void *args)
goto cleanup;
}
- expPath = isAbs ? data->files[i]->pathAbs
- : data->files[i]->pathRel;
expRelDir = isAbs ? data->files[i]->relDirAbs
: data->files[i]->relDirRel;
if (virAsprintf(&expect,
@@ -389,7 +383,7 @@ testStorageChain(const void *args)
NULLSTR(data->files[i]->expBackingStoreRaw),
data->files[i]->expCapacity,
data->files[i]->expEncrypted,
- NULLSTR(expPath),
+ NULLSTR(data->files[i]->pathRel),
NULLSTR(expRelDir),
data->files[i]->type,
data->files[i]->format) < 0 ||
@@ -740,7 +734,6 @@ mymain(void)
/* Raw image, whether with right format or no specified format */
testFileData raw = {
- .pathRel = "raw",
.pathAbs = canonraw,
.path = canonraw,
.relDirRel = ".",
@@ -761,10 +754,10 @@ mymain(void)
/* Qcow2 file with relative raw backing, format provided */
raw.pathAbs = "raw";
+ raw.pathRel = "raw";
testFileData qcow2 = {
.expBackingStoreRaw = "raw",
.expCapacity = 1024,
- .pathRel = "qcow2",
.pathAbs = canonqcow2,
.path = canonqcow2,
.relDirRel = ".",
@@ -773,7 +766,6 @@ mymain(void)
.format = VIR_STORAGE_FILE_QCOW2,
};
testFileData qcow2_as_raw = {
- .pathRel = "qcow2",
.pathAbs = canonqcow2,
.path = canonqcow2,
.relDirRel = ".",
@@ -799,7 +791,7 @@ mymain(void)
if (virCommandRun(cmd, NULL) < 0)
ret = -1;
qcow2.expBackingStoreRaw = absraw;
- raw.pathRel = absraw;
+ raw.pathRel = NULL;
raw.pathAbs = absraw;
raw.relDirRel = datadir;
@@ -819,7 +811,6 @@ mymain(void)
testFileData wrap = {
.expBackingStoreRaw = absqcow2,
.expCapacity = 1024,
- .pathRel = "wrap",
.pathAbs = abswrap,
.path = canonwrap,
.relDirRel = ".",
@@ -827,7 +818,6 @@ mymain(void)
.type = VIR_STORAGE_TYPE_FILE,
.format = VIR_STORAGE_FILE_QCOW2,
};
- qcow2.pathRel = absqcow2;
qcow2.relDirRel = datadir;
TEST_CHAIN(7, "wrap", abswrap, VIR_STORAGE_FILE_QCOW2,
(&wrap, &qcow2, &raw), EXP_PASS,
@@ -847,14 +837,12 @@ mymain(void)
"-b", absqcow2, "wrap", NULL);
if (virCommandRun(cmd, NULL) < 0)
ret = -1;
- qcow2_as_raw.pathRel = absqcow2;
qcow2_as_raw.relDirRel = datadir;
/* Qcow2 file with raw as absolute backing, backing format omitted */
testFileData wrap_as_raw = {
.expBackingStoreRaw = absqcow2,
.expCapacity = 1024,
- .pathRel = "wrap",
.pathAbs = abswrap,
.path = canonwrap,
.relDirRel = ".",
@@ -876,7 +864,6 @@ mymain(void)
if (virCommandRun(cmd, NULL) < 0)
ret = -1;
qcow2.expBackingStoreRaw = datadir "/bogus";
- qcow2.pathRel = "qcow2";
qcow2.relDirRel = ".";
/* Qcow2 file with missing backing file but specified type */
@@ -911,7 +898,6 @@ mymain(void)
/* Qcow2 file with backing protocol instead of file */
testFileData nbd = {
- .pathRel = "nbd:example.org:6000:exportname=blah",
.pathAbs = "nbd:example.org:6000:exportname=blah",
.path = "blah",
.type = VIR_STORAGE_TYPE_NETWORK,
@@ -929,7 +915,6 @@ mymain(void)
testFileData qed = {
.expBackingStoreRaw = absraw,
.expCapacity = 1024,
- .pathRel = "qed",
.pathAbs = absqed,
.path = canonqed,
.relDirRel = ".",
@@ -938,7 +923,6 @@ mymain(void)
.format = VIR_STORAGE_FILE_QED,
};
testFileData qed_as_raw = {
- .pathRel = "qed",
.pathAbs = absqed,
.path = canonqed,
.relDirRel = ".",
@@ -954,7 +938,6 @@ mymain(void)
/* directory */
testFileData dir = {
- .pathRel = "dir",
.pathAbs = absdir,
.path = canondir,
.relDirRel = ".",
@@ -1004,7 +987,6 @@ mymain(void)
testFileData link2 = {
.expBackingStoreRaw = "../sub/link1",
.expCapacity = 1024,
- .pathRel = "sub/link2",
.pathAbs = abslink2,
.path = canonwrap,
.relDirRel = "sub",
@@ -1051,7 +1033,6 @@ mymain(void)
if (virCommandRun(cmd, NULL) < 0)
ret = -1;
qcow2.expBackingStoreRaw = "wrap";
- qcow2.pathRel = absqcow2;
qcow2.relDirRel = datadir;
/* Behavior of an infinite loop chain */
--
1.9.3