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 4f51517..9ce3b62 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -3189,10 +3189,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 301452e..b33bc1a 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) {
@@ -907,9 +907,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;
@@ -1375,7 +1372,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)) {
@@ -1594,6 +1592,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, "/"))
@@ -1908,11 +1910,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 70deaef..1f2ae53 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 e1adce9..5fd2530 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 ||
@@ -767,7 +761,6 @@ mymain(void)
/* Raw image, whether with right format or no specified format */
testFileData raw = {
- .pathRel = "raw",
.pathAbs = canonraw,
.path = canonraw,
.relDirRel = ".",
@@ -788,10 +781,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 = ".",
@@ -800,7 +793,6 @@ mymain(void)
.format = VIR_STORAGE_FILE_QCOW2,
};
testFileData qcow2_as_raw = {
- .pathRel = "qcow2",
.pathAbs = canonqcow2,
.path = canonqcow2,
.relDirRel = ".",
@@ -826,7 +818,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;
@@ -846,7 +838,6 @@ mymain(void)
testFileData wrap = {
.expBackingStoreRaw = absqcow2,
.expCapacity = 1024,
- .pathRel = "wrap",
.pathAbs = abswrap,
.path = canonwrap,
.relDirRel = ".",
@@ -854,7 +845,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,
@@ -874,14 +864,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 = ".",
@@ -903,7 +891,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 */
@@ -938,7 +925,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,
@@ -956,7 +942,6 @@ mymain(void)
testFileData qed = {
.expBackingStoreRaw = absraw,
.expCapacity = 1024,
- .pathRel = "qed",
.pathAbs = absqed,
.path = canonqed,
.relDirRel = ".",
@@ -965,7 +950,6 @@ mymain(void)
.format = VIR_STORAGE_FILE_QED,
};
testFileData qed_as_raw = {
- .pathRel = "qed",
.pathAbs = absqed,
.path = canonqed,
.relDirRel = ".",
@@ -981,7 +965,6 @@ mymain(void)
/* directory */
testFileData dir = {
- .pathRel = "dir",
.pathAbs = absdir,
.path = canondir,
.relDirRel = ".",
@@ -1031,7 +1014,6 @@ mymain(void)
testFileData link2 = {
.expBackingStoreRaw = "../sub/link1",
.expCapacity = 1024,
- .pathRel = "sub/link2",
.pathAbs = abslink2,
.path = canonwrap,
.relDirRel = "sub",
@@ -1078,7 +1060,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