To allow future change of virStorageFileMetadata to virStorageSource we need to store a full path in the "path" variable as rest of the code expects it to be a full path. Rename the "path" field to "relPath" to keep tracking the info but allowing a real "path" field. --- src/util/virstoragefile.c | 22 +++++++++++----------- src/util/virstoragefile.h | 2 +- tests/virstoragetest.c | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index e37be06..f11dd36 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -802,11 +802,11 @@ virStorageFileGetMetadataInternal(virStorageFileMetadataPtr meta, { int ret = -1; - VIR_DEBUG("path=%s, buf=%p, len=%zu, meta->format=%d", - meta->path, buf, len, meta->format); + VIR_DEBUG("relPath=%s, buf=%p, len=%zu, meta->format=%d", + meta->relPath, buf, len, meta->format); if (meta->format == VIR_STORAGE_FILE_AUTO) - meta->format = virStorageFileProbeFormatFromBuf(meta->path, buf, len); + meta->format = virStorageFileProbeFormatFromBuf(meta->relPath, buf, len); if (meta->format <= VIR_STORAGE_FILE_NONE || meta->format >= VIR_STORAGE_FILE_LAST) { @@ -945,7 +945,7 @@ virStorageFileMetadataNew(const char *path, ret->format = format; ret->type = VIR_STORAGE_TYPE_FILE; - if (VIR_STRDUP(ret->path, path) < 0) + if (VIR_STRDUP(ret->relPath, path) < 0) goto error; if (!(ret->canonPath = canonicalize_file_name(path))) { @@ -1033,7 +1033,7 @@ virStorageFileGetMetadataFromFDInternal(virStorageFileMetadataPtr meta, if (fstat(fd, &sb) < 0) { virReportSystemError(errno, _("cannot stat file '%s'"), - meta->path); + meta->relPath); return -1; } @@ -1050,12 +1050,12 @@ virStorageFileGetMetadataFromFDInternal(virStorageFileMetadataPtr meta, } if (lseek(fd, 0, SEEK_SET) == (off_t)-1) { - virReportSystemError(errno, _("cannot seek to start of '%s'"), meta->path); + virReportSystemError(errno, _("cannot seek to start of '%s'"), meta->relPath); goto cleanup; } if ((len = virFileReadHeaderFD(fd, len, &buf)) < 0) { - virReportSystemError(errno, _("cannot read header '%s'"), meta->path); + virReportSystemError(errno, _("cannot read header '%s'"), meta->relPath); goto cleanup; } @@ -1132,7 +1132,7 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath, return -1; if (virStorageIsFile(path)) { - if (VIR_STRDUP(meta->path, path) < 0) + if (VIR_STRDUP(meta->relPath, path) < 0) return -1; if (VIR_STRDUP(meta->canonPath, canonPath) < 0) return -1; @@ -1153,7 +1153,7 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath, /* FIXME: when the proper storage drivers are compiled in, it * would be nice to read metadata from the network storage to * allow for non-raw images. */ - if (VIR_STRDUP(meta->path, path) < 0) + if (VIR_STRDUP(meta->relPath, path) < 0) return -1; if (VIR_STRDUP(meta->canonPath, path) < 0) return -1; @@ -1316,7 +1316,7 @@ virStorageFileFreeMetadata(virStorageFileMetadata *meta) if (!meta) return; - VIR_FREE(meta->path); + VIR_FREE(meta->relPath); VIR_FREE(meta->canonPath); VIR_FREE(meta->relDir); @@ -1548,7 +1548,7 @@ virStorageFileChainLookup(virStorageFileMetadataPtr chain, if (!chain->backingMeta) break; } else { - if (STREQ(name, chain->path)) + if (STREQ(name, chain->relPath)) break; if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE || chain->type == VIR_STORAGE_TYPE_BLOCK)) { diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 1b8b14f..867214e 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -121,7 +121,7 @@ typedef virStorageFileMetadata *virStorageFileMetadataPtr; struct _virStorageFileMetadata { /* Name of the current file as spelled by the user (top level) or * metadata of the overlay (if this is a backing store). */ - char *path; + char *relPath; /* Canonical name of the current file, used to detect loops in the * backing store chain. */ char *canonPath; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 820e53f..b0de438 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -323,7 +323,7 @@ testStorageChain(const void *args) : data->files[i]->relDirRel; if (virAsprintf(&expect, "store:%s\nraw:%s\nother:%lld %d\n" - "path:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n", + "relPath:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n", NULLSTR(data->files[i]->expBackingStore), NULLSTR(data->files[i]->expBackingStoreRaw), data->files[i]->expCapacity, @@ -335,11 +335,11 @@ testStorageChain(const void *args) data->files[i]->format) < 0 || virAsprintf(&actual, "store:%s\nraw:%s\nother:%lld %d\n" - "path:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n", + "relPath:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n", NULLSTR(elt->backingStore), NULLSTR(elt->backingStoreRaw), elt->capacity, !!elt->encryption, - NULLSTR(elt->path), + NULLSTR(elt->relPath), NULLSTR(elt->canonPath), NULLSTR(elt->relDir), elt->type, elt->format) < 0) { -- 1.9.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list