]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
util: storage: Allow specifying format for virStorageFileGetMetadataFromBuf
authorPeter Krempa <pkrempa@redhat.com>
Mon, 7 Jul 2014 09:38:28 +0000 (11:38 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 8 Jul 2014 09:35:50 +0000 (11:35 +0200)
To allow reusing this function in the qemu driver we need to allow
specifying the storage format. Also separate return of the backing store
path now isn't necessary.

src/storage/storage_backend_gluster.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index 1a2b4ec5a3d2142b777f3a8a7e54ce4a903e88e0..5ecc098c7aaded805fa5f7fe8e794fea33b4817d 100644 (file)
@@ -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)
index 01d4a7eac998b418c57bfa169671549c5e5c0fcf..0b8715d04c44ec946f745290e86a0f9518ea95d9 100644 (file)
@@ -930,19 +930,20 @@ 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
- * other non-raw format at will.
+ * 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 on a file
+ * that might be raw if that file will then be passed to a guest, 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
- * 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.
+ * If the returned @backingFormat 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 virStorageSourceFree.
  */
@@ -950,25 +951,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;
 }
 
index 4f7357b229e72963b8b4f751ca1f0cc2d83b458c..89ecc1e187c6b8e9d3d58823f2658127b0a900be 100644 (file)
@@ -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);