[libvirt] [PATCH] util: Force reading of meta data to get encryption capacity value

John Ferlan posted 1 patch 6 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20170615193105.29877-1-jferlan@redhat.com
src/util/virstoragefile.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
[libvirt] [PATCH] util: Force reading of meta data to get encryption capacity value
Posted by John Ferlan 6 years, 10 months ago
https://bugzilla.redhat.com/show_bug.cgi?id=1371892

As it turns out the volume create, build, and refresh path was not peeking
at the meta data, so immediately after a create operation the value displayed
for capacity was still incorrect. However, if a pool refresh was done the
correct value was fetched as a result of a meta data peek.

The reason is it seems historically if the file type is RAW then peeking
at the file just took the physical value for the capacity. However, since
we know if it's an encrypted file, then peeking at the meta data will be
required in order to get a true capacity value.

So check for encryption in the source and if present, use the meta data
in order to fill in the capacity value and set the payload_offset.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/util/virstoragefile.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index e82a7fb..11c3625 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -3446,13 +3446,16 @@ virStorageSourceUpdateCapacity(virStorageSourcePtr src,
         src->format = format;
     }
 
-    if (format == VIR_STORAGE_FILE_RAW)
+    if (format == VIR_STORAGE_FILE_RAW && !src->encryption) {
         src->capacity = src->physical;
-    else if ((meta = virStorageFileGetMetadataFromBuf(src->path, buf,
-                                                      len, format, NULL)))
+    } else if ((meta = virStorageFileGetMetadataFromBuf(src->path, buf,
+                                                        len, format, NULL))) {
         src->capacity = meta->capacity ? meta->capacity : src->physical;
-    else
+        if (src->encryption && meta->encryption)
+            src->encryption->payload_offset = meta->encryption->payload_offset;
+    } else {
         goto cleanup;
+    }
 
     if (src->encryption && src->encryption->payload_offset != -1)
         src->capacity -= src->encryption->payload_offset * 512;
-- 
2.9.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: Force reading of meta data to get encryption capacity value
Posted by Michal Privoznik 6 years, 10 months ago
On 06/15/2017 09:31 PM, John Ferlan wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1371892
> 
> As it turns out the volume create, build, and refresh path was not peeking
> at the meta data, so immediately after a create operation the value displayed
> for capacity was still incorrect. However, if a pool refresh was done the
> correct value was fetched as a result of a meta data peek.
> 
> The reason is it seems historically if the file type is RAW then peeking
> at the file just took the physical value for the capacity. However, since
> we know if it's an encrypted file, then peeking at the meta data will be
> required in order to get a true capacity value.
> 
> So check for encryption in the source and if present, use the meta data
> in order to fill in the capacity value and set the payload_offset.
> 
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/util/virstoragefile.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)

ACK

Michal

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