From 86cfa1f603dc5a351db4e91d44cc333db48b1dcc Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 9 Apr 2014 20:37:16 -0600 Subject: [PATCH] conf: delete useless backingStoreFormat field Drop another redundant field from virStorageFileMetadata. * src/util/virstoragefile.h (_virStorageFileMetadata): Drop field. * src/util/virstoragefile.c (virStorageFileGetMetadataFromFDInternal) (virStorageFileGetMetadataFromFD) (virStorageFileGetMetadataRecurse): Adjust callers. * tests/virstoragetest.c (_testFileData, testStorageChain) (mymain): Simplify test. Signed-off-by: Eric Blake --- src/util/virstoragefile.c | 38 +++++++++++++++++--------------------- src/util/virstoragefile.h | 1 - tests/virstoragetest.c | 22 ++-------------------- 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 5a4fc4b1de..201391482d 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1035,13 +1035,18 @@ virStorageFileGetMetadataFromFDInternal(const char *path, const char *directory, int fd, int format, - virStorageFileMetadataPtr meta) + virStorageFileMetadataPtr meta, + int *backingFormat) { char *buf = NULL; ssize_t len = VIR_STORAGE_MAX_HEADER; struct stat sb; int ret = -1; + int dummy; + if (!backingFormat) + backingFormat = &dummy; + *backingFormat = VIR_STORAGE_FILE_NONE; if (fstat(fd, &sb) < 0) { virReportSystemError(errno, _("cannot stat file '%s'"), @@ -1074,7 +1079,7 @@ virStorageFileGetMetadataFromFDInternal(const char *path, ret = virStorageFileGetMetadataInternal(path, canonPath, directory, buf, len, format, meta, &meta->backingStoreRaw, - &meta->backingStoreFormat); + backingFormat); if (ret == 0) { if (S_ISREG(sb.st_mode)) @@ -1099,11 +1104,6 @@ virStorageFileGetMetadataFromFDInternal(const char *path, * format, since a malicious guest can turn a raw file into any * other non-raw format at will. * - * If the returned meta.backingStoreFormat is VIR_STORAGE_FILE_AUTO - * it indicates the image didn't specify an explicit format for its - * backing store. Callers are advised against probing for the - * backing store format in this case. - * * Caller MUST free the result after use via virStorageFileFreeMetadata. */ virStorageFileMetadataPtr @@ -1121,7 +1121,7 @@ virStorageFileGetMetadataFromFD(const char *path, if (VIR_ALLOC(ret) < 0) goto cleanup; if (virStorageFileGetMetadataFromFDInternal(path, canonPath, ".", - fd, format, ret) < 0) { + fd, format, ret, NULL) < 0) { virStorageFileFreeMetadata(ret); ret = NULL; } @@ -1142,6 +1142,8 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath, { int fd; int ret = -1; + int backingFormat; + VIR_DEBUG("path=%s canonPath=%s dir=%s format=%d uid=%d gid=%d probe=%d", path, canonPath, NULLSTR(directory), format, (int)uid, (int)gid, allow_probe); @@ -1163,7 +1165,8 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath, ret = virStorageFileGetMetadataFromFDInternal(path, canonPath, directory, - fd, format, meta); + fd, format, meta, + &backingFormat); if (VIR_CLOSE(fd) < 0) VIR_WARN("could not close file %s", path); @@ -1183,19 +1186,17 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath, if (ret == 0 && meta->backingStore) { virStorageFileMetadataPtr backing; - if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO && !allow_probe) - meta->backingStoreFormat = VIR_STORAGE_FILE_RAW; - else if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO_SAFE) - meta->backingStoreFormat = VIR_STORAGE_FILE_AUTO; - format = meta->backingStoreFormat; + if (backingFormat == VIR_STORAGE_FILE_AUTO && !allow_probe) + backingFormat = VIR_STORAGE_FILE_RAW; + else if (backingFormat == VIR_STORAGE_FILE_AUTO_SAFE) + backingFormat = VIR_STORAGE_FILE_AUTO; if (VIR_ALLOC(backing) < 0 || virStorageFileGetMetadataRecurse(meta->backingStoreRaw, meta->backingStore, - meta->directory, format, + meta->directory, backingFormat, uid, gid, allow_probe, cycle, backing) < 0) { /* If we failed to get backing data, mark the chain broken */ - meta->backingStoreFormat = VIR_STORAGE_FILE_NONE; VIR_FREE(meta->backingStore); virStorageFileFreeMetadata(backing); } else { @@ -1220,11 +1221,6 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath, * format, since a malicious guest can turn a raw file into any * other non-raw format at will. * - * If the returned meta.backingStoreFormat is VIR_STORAGE_FILE_AUTO - * it indicates the image didn't specify an explicit format for its - * backing store. Callers are advised against using ALLOW_PROBE, as - * it would probe the backing store format in this case. - * * Caller MUST free result after use via virStorageFileFreeMetadata. */ virStorageFileMetadataPtr diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index edfe9eb3d1..c747f20928 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -147,7 +147,6 @@ struct _virStorageFileMetadata { * store. */ char *backingStore; /* Canonical name (absolute file, or protocol). Should be same as backingMeta->canonPath */ char *directory; /* The directory containing basename of backingStoreRaw. Should be same as backingMeta->relDir */ - int backingStoreFormat; /* enum virStorageFileFormat. Should be same as backingMeta->format */ }; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 26f235b3e4..029561c9f7 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -235,7 +235,6 @@ struct _testFileData const char *expBackingStoreRaw; const char *expBackingDirRel; const char *expBackingDirAbs; - enum virStorageFileFormat expBackingFormat; unsigned long long expCapacity; bool expEncrypted; const char *pathRel; @@ -328,12 +327,11 @@ testStorageChain(const void *args) expRelDir = isAbs ? data->files[i]->relDirAbs : data->files[i]->relDirRel; if (virAsprintf(&expect, - "store:%s\nraw:%s\ndirectory:%s\nother:%d %lld %d\n" + "store:%s\nraw:%s\ndirectory:%s\nother:%lld %d\n" "path:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n", NULLSTR(data->files[i]->expBackingStore), NULLSTR(data->files[i]->expBackingStoreRaw), NULLSTR(expBackingDirectory), - data->files[i]->expBackingFormat, data->files[i]->expCapacity, data->files[i]->expEncrypted, NULLSTR(expPath), @@ -342,12 +340,11 @@ testStorageChain(const void *args) data->files[i]->type, data->files[i]->format) < 0 || virAsprintf(&actual, - "store:%s\nraw:%s\ndirectory:%s\nother:%d %lld %d\n" + "store:%s\nraw:%s\ndirectory:%s\nother:%lld %d\n" "path:%s\ncanon:%s\nrelDir:%s\ntype:%d %d\n", NULLSTR(elt->backingStore), NULLSTR(elt->backingStoreRaw), NULLSTR(elt->directory), - elt->backingStoreFormat, elt->capacity, !!elt->encryption, NULLSTR(elt->path), NULLSTR(elt->canonPath), @@ -431,7 +428,6 @@ mymain(void) /* Raw image, whether with right format or no specified format */ testFileData raw = { - .expBackingFormat = VIR_STORAGE_FILE_NONE, .pathRel = "raw", .pathAbs = canonraw, .canonPath = canonraw, @@ -458,7 +454,6 @@ mymain(void) .expBackingStoreRaw = "raw", .expBackingDirRel = ".", .expBackingDirAbs = datadir, - .expBackingFormat = VIR_STORAGE_FILE_RAW, .expCapacity = 1024, .pathRel = "qcow2", .pathAbs = canonqcow2, @@ -469,7 +464,6 @@ mymain(void) .format = VIR_STORAGE_FILE_QCOW2, }; testFileData qcow2_as_raw = { - .expBackingFormat = VIR_STORAGE_FILE_NONE, .pathRel = "qcow2", .pathAbs = canonqcow2, .canonPath = canonqcow2, @@ -519,7 +513,6 @@ mymain(void) .expBackingStoreRaw = absqcow2, .expBackingDirRel = datadir, .expBackingDirAbs = datadir, - .expBackingFormat = VIR_STORAGE_FILE_QCOW2, .expCapacity = 1024, .pathRel = "wrap", .pathAbs = abswrap, @@ -549,8 +542,6 @@ mymain(void) "-b", absqcow2, "wrap", NULL); if (virCommandRun(cmd, NULL) < 0) ret = -1; - wrap.expBackingFormat = VIR_STORAGE_FILE_AUTO; - qcow2.expBackingFormat = VIR_STORAGE_FILE_AUTO; qcow2_as_raw.pathRel = absqcow2; qcow2_as_raw.relDirRel = datadir; @@ -560,7 +551,6 @@ mymain(void) .expBackingStoreRaw = absqcow2, .expBackingDirRel = datadir, .expBackingDirAbs = datadir, - .expBackingFormat = VIR_STORAGE_FILE_RAW, .expCapacity = 1024, .pathRel = "wrap", .pathAbs = abswrap, @@ -585,7 +575,6 @@ mymain(void) ret = -1; qcow2.expBackingStore = NULL; qcow2.expBackingStoreRaw = datadir "/bogus"; - qcow2.expBackingFormat = VIR_STORAGE_FILE_NONE; qcow2.pathRel = "qcow2"; qcow2.relDirRel = "."; @@ -621,7 +610,6 @@ mymain(void) qcow2.expBackingStoreRaw = "nbd:example.org:6000"; qcow2.expBackingDirRel = NULL; qcow2.expBackingDirAbs = NULL; - qcow2.expBackingFormat = VIR_STORAGE_FILE_RAW; /* Qcow2 file with backing protocol instead of file */ testFileData nbd = { @@ -643,7 +631,6 @@ mymain(void) .expBackingStoreRaw = absraw, .expBackingDirRel = datadir, .expBackingDirAbs = datadir, - .expBackingFormat = VIR_STORAGE_FILE_RAW, .expCapacity = 1024, .pathRel = "qed", .pathAbs = absqed, @@ -654,7 +641,6 @@ mymain(void) .format = VIR_STORAGE_FILE_QED, }; testFileData qed_as_raw = { - .expBackingFormat = VIR_STORAGE_FILE_NONE, .pathRel = "qed", .pathAbs = absqed, .canonPath = canonqed, @@ -709,7 +695,6 @@ mymain(void) .expBackingStoreRaw = "../raw", .expBackingDirRel = "sub/../sub/..", .expBackingDirAbs = datadir "/sub/../sub/..", - .expBackingFormat = VIR_STORAGE_FILE_RAW, .expCapacity = 1024, .pathRel = "../sub/link1", .pathAbs = "../sub/link1", @@ -724,7 +709,6 @@ mymain(void) .expBackingStoreRaw = "../sub/link1", .expBackingDirRel = "sub/../sub", .expBackingDirAbs = datadir "/sub/../sub", - .expBackingFormat = VIR_STORAGE_FILE_QCOW2, .expCapacity = 1024, .pathRel = "sub/link2", .pathAbs = abslink2, @@ -755,7 +739,6 @@ mymain(void) qcow2.expBackingStoreRaw = "qcow2"; qcow2.expBackingDirRel = "."; qcow2.expBackingDirAbs = datadir; - qcow2.expBackingFormat= VIR_STORAGE_FILE_NONE; /* Behavior of an infinite loop chain */ TEST_CHAIN(16, "qcow2", absqcow2, VIR_STORAGE_FILE_QCOW2, @@ -780,7 +763,6 @@ mymain(void) qcow2.expBackingDirRel = datadir; qcow2.pathRel = absqcow2; qcow2.relDirRel = datadir; - wrap.expBackingFormat = VIR_STORAGE_FILE_QCOW2; /* Behavior of an infinite loop chain */ TEST_CHAIN(17, "wrap", abswrap, VIR_STORAGE_FILE_QCOW2,