]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: modify tracking of encrypted images
authorEric Blake <eblake@redhat.com>
Wed, 2 Apr 2014 01:13:51 +0000 (19:13 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 2 Apr 2014 12:03:01 +0000 (06:03 -0600)
A future patch will merge virStorageFileMetadata and virStorageSource,
but I found it easier to do if both structs use the same information
for tracking whether a source file needs encryption keys.

* src/util/virstoragefile.h (_virStorageFileMetadata): Prepare
full encryption struct instead of just a bool.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Use transfer semantics.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal):
Populate struct.
(virStorageFileFreeMetadata): Adjust clients.
* tests/virstoragetest.c (testStorageChain): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/storage/storage_backend_fs.c
src/storage/storage_backend_gluster.c
src/util/virstoragefile.c
src/util/virstoragefile.h
tests/virstoragetest.c

index 501fa8d2583f89c0f816446effae11e47b2b8f9f..de6521cda8b20a718a10a0be87cff4533a0193d1 100644 (file)
@@ -142,9 +142,9 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
     if (meta && meta->capacity)
         target->capacity = meta->capacity;
 
-    if (encryption && meta && meta->encrypted) {
-        if (VIR_ALLOC(*encryption) < 0)
-            goto cleanup;
+    if (encryption && meta && meta->encryption) {
+        *encryption = meta->encryption;
+        meta->encryption = NULL;
 
         switch (target->format) {
         case VIR_STORAGE_FILE_QCOW:
index 4aec44bae226385b0f6e2d8ad93e83d5e79edb23..d131f13204a797d049782bdf6cfc605bb0fd937e 100644 (file)
@@ -310,9 +310,9 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     }
     if (meta->capacity)
         vol->target.capacity = meta->capacity;
-    if (meta->encrypted) {
-        if (VIR_ALLOC(vol->target.encryption) < 0)
-            goto cleanup;
+    if (meta->encryption) {
+        vol->target.encryption = meta->encryption;
+        meta->encryption = NULL;
         if (vol->target.format == VIR_STORAGE_FILE_QCOW ||
             vol->target.format == VIR_STORAGE_FILE_QCOW2)
             vol->target.encryption->format = VIR_STORAGE_ENCRYPTION_FORMAT_QCOW;
index 137bacc2694ed8feb1bd90bbfd0aa06624ef2067..e6a985de095bba204d9b48b095503c9fba3119c2 100644 (file)
@@ -837,7 +837,8 @@ virStorageFileGetMetadataInternal(const char *path,
 
         crypt_format = virReadBufInt32BE(buf +
                                          fileTypeInfo[format].qcowCryptOffset);
-        meta->encrypted = crypt_format != 0;
+        if (crypt_format && VIR_ALLOC(meta->encryption) < 0)
+            goto cleanup;
     }
 
     if (fileTypeInfo[format].getBackingStore != NULL) {
@@ -1209,6 +1210,7 @@ virStorageFileFreeMetadata(virStorageFileMetadata *meta)
     VIR_FREE(meta->compat);
     VIR_FREE(meta->directory);
     virBitmapFree(meta->features);
+    virStorageEncryptionFree(meta->encryption);
     VIR_FREE(meta);
 }
 
index aa06d41a670d5b3f222cb899910a3b80e67fd902..56105d0c09a223d1c8318ad06206f03f15846c55 100644 (file)
@@ -114,8 +114,9 @@ struct _virStorageFileMetadata {
     int backingStoreFormat; /* enum virStorageFileFormat */
     bool backingStoreIsFile;
     virStorageFileMetadataPtr backingMeta;
+
+    virStorageEncryptionPtr encryption;
     unsigned long long capacity;
-    bool encrypted;
     virBitmapPtr features; /* bits described by enum virStorageFileFeature */
     char *compat;
 };
index 2890651e9fc78f3c4aa5e38d5a46f888c26a81e7..3089d70919a10056aee09a1773ee8626bc76c291 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (C) 2013-2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -284,7 +284,7 @@ testStorageChain(const void *args)
                         NULLSTR(elt->backingStoreRaw),
                         NULLSTR(elt->directory),
                         elt->backingStoreFormat, elt->backingStoreIsFile,
-                        elt->capacity, elt->encrypted) < 0) {
+                        elt->capacity, !!elt->encryption) < 0) {
             VIR_FREE(expect);
             VIR_FREE(actual);
             goto cleanup;