[PATCH 5/5] conf: delete useless backingStoreFormat field

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <eblake@xxxxxxxxxx>
---
 src/util/virstoragefile.c | 39 ++++++++++++++++++---------------------
 src/util/virstoragefile.h |  1 -
 tests/virstoragetest.c    | 22 ++--------------------
 3 files changed, 20 insertions(+), 42 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index c509a9a..3645abb 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1035,13 +1035,19 @@ 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 = VIR_STORAGE_FILE_NONE;
+    else
+        backingFormat = &dummy;
     if (fstat(fd, &sb) < 0) {
         virReportSystemError(errno,
                              _("cannot stat file '%s'"),
@@ -1074,7 +1080,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 +1105,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 +1122,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 +1143,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 +1166,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 +1187,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 +1222,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 edfe9eb..c747f20 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 846d130..13b5032 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -232,7 +232,6 @@ struct _testFileData
     const char *expBackingStoreRaw;
     const char *expBackingDirRel;
     const char *expBackingDirAbs;
-    enum virStorageFileFormat expBackingFormat;
     unsigned long long expCapacity;
     bool expEncrypted;
     const char *pathRel;
@@ -325,12 +324,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),
@@ -339,12 +337,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),
@@ -428,7 +425,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,
@@ -455,7 +451,6 @@ mymain(void)
         .expBackingStoreRaw = "raw",
         .expBackingDirRel = ".",
         .expBackingDirAbs = datadir,
-        .expBackingFormat = VIR_STORAGE_FILE_RAW,
         .expCapacity = 1024,
         .pathRel = "qcow2",
         .pathAbs = canonqcow2,
@@ -466,7 +461,6 @@ mymain(void)
         .format = VIR_STORAGE_FILE_QCOW2,
     };
     testFileData qcow2_as_raw = {
-        .expBackingFormat = VIR_STORAGE_FILE_NONE,
         .pathRel = "qcow2",
         .pathAbs = canonqcow2,
         .canonPath = canonqcow2,
@@ -516,7 +510,6 @@ mymain(void)
         .expBackingStoreRaw = absqcow2,
         .expBackingDirRel = datadir,
         .expBackingDirAbs = datadir,
-        .expBackingFormat = VIR_STORAGE_FILE_QCOW2,
         .expCapacity = 1024,
         .pathRel = "wrap",
         .pathAbs = abswrap,
@@ -546,8 +539,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;

@@ -557,7 +548,6 @@ mymain(void)
         .expBackingStoreRaw = absqcow2,
         .expBackingDirRel = datadir,
         .expBackingDirAbs = datadir,
-        .expBackingFormat = VIR_STORAGE_FILE_RAW,
         .expCapacity = 1024,
         .pathRel = "wrap",
         .pathAbs = abswrap,
@@ -582,7 +572,6 @@ mymain(void)
         ret = -1;
     qcow2.expBackingStore = NULL;
     qcow2.expBackingStoreRaw = datadir "/bogus";
-    qcow2.expBackingFormat = VIR_STORAGE_FILE_NONE;
     qcow2.pathRel = "qcow2";
     qcow2.relDirRel = ".";

@@ -618,7 +607,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 = {
@@ -640,7 +628,6 @@ mymain(void)
         .expBackingStoreRaw = absraw,
         .expBackingDirRel = datadir,
         .expBackingDirAbs = datadir,
-        .expBackingFormat = VIR_STORAGE_FILE_RAW,
         .expCapacity = 1024,
         .pathRel = "qed",
         .pathAbs = absqed,
@@ -651,7 +638,6 @@ mymain(void)
         .format = VIR_STORAGE_FILE_QED,
     };
     testFileData qed_as_raw = {
-        .expBackingFormat = VIR_STORAGE_FILE_NONE,
         .pathRel = "qed",
         .pathAbs = absqed,
         .canonPath = canonqed,
@@ -706,7 +692,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",
@@ -721,7 +706,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,
@@ -752,7 +736,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,
@@ -777,7 +760,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,
-- 
1.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]