[PATCH 2/4] util: storage: Allow specifying format for virStorageFileGetMetadataFromBuf

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

 



To allow reusing this function in the qemu driver we need to allow to
specify the storage format. Also separate return of the backing store
path now isn't necessary.
---
 src/storage/storage_backend_gluster.c |  5 ++++-
 src/util/virstoragefile.c             | 31 ++++++++++++++-----------------
 src/util/virstoragefile.h             |  2 +-
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 1a2b4ec..5ecc098 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -294,10 +294,13 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
         goto cleanup;

     if (!(meta = virStorageFileGetMetadataFromBuf(name, header, len,
-                                                  &vol->backingStore.path,
+                                                  VIR_STORAGE_FILE_AUTO,
                                                   &vol->backingStore.format)))
         goto cleanup;

+    vol->backingStore.path = meta->backingStoreRaw;
+    meta->backingStoreRaw = NULL;
+
     vol->target.format = meta->format;
     if (vol->backingStore.path &&
         vol->backingStore.format < 0)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 01d4a7e..7ae4642 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -930,13 +930,15 @@ virStorageFileMetadataNew(const char *path,
  * @path: name of file, for error messages
  * @buf: header bytes from @path
  * @len: length of @buf
- * @backing: output malloc'd name of backing image, if any
+ * @format: format of the storage file
  * @backingFormat: format of @backing
  *
- * Extract metadata about the storage volume, including probing its
- * format.  Does not recurse.  Callers are advised not to trust the
- * learned format if a guest has ever used the volume when it was
- * raw, since a malicious guest can turn a raw file into any
+ * Extract metadata about the storage volume with the specified
+ * image format. If image format is VIR_STORAGE_FILE_AUTO, it
+ * will probe to automatically identify the format.  Does not recurse.
+ *
+ * Callers are advised never to use VIR_STORAGE_FILE_AUTO as a
+ * format, since a malicious guest can turn a raw file into any
  * other non-raw format at will.
  *
  * If the returned @backingFormat is VIR_STORAGE_FILE_AUTO
@@ -950,25 +952,20 @@ virStorageSourcePtr
 virStorageFileGetMetadataFromBuf(const char *path,
                                  char *buf,
                                  size_t len,
-                                 char **backing,
+                                 int format,
                                  int *backingFormat)
 {
     virStorageSourcePtr ret = NULL;
-    virStorageSourcePtr meta = NULL;

-    if (!(meta = virStorageFileMetadataNew(path, VIR_STORAGE_FILE_AUTO)))
+    if (!(ret = virStorageFileMetadataNew(path, format)))
         return NULL;

-    if (virStorageFileGetMetadataInternal(meta, buf, len,
-                                          backingFormat) < 0)
-        goto cleanup;
-    if (VIR_STRDUP(*backing, meta->backingStoreRaw) < 0)
-        goto cleanup;
+    if (virStorageFileGetMetadataInternal(ret, buf, len,
+                                          backingFormat) < 0) {
+        virStorageSourceFree(ret);
+        return NULL;
+    }

-    ret = meta;
-    meta = NULL;
- cleanup:
-    virStorageSourceFree(meta);
     return ret;
 }

diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 4f7357b..89ecc1e 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -290,7 +290,7 @@ virStorageSourcePtr virStorageFileGetMetadataFromFD(const char *path,
 virStorageSourcePtr virStorageFileGetMetadataFromBuf(const char *path,
                                                      char *buf,
                                                      size_t len,
-                                                     char **backing,
+                                                     int format,
                                                      int *backingFormat)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4)
     ATTRIBUTE_NONNULL(5);
-- 
2.0.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]