Patchwork qcow2: fix autoclear image header update

login
register
mail settings
Submitter Stefan Hajnoczi
Date June 14, 2012, 10:42 a.m.
Message ID <1339670543-6394-1-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/164906/
State New
Headers show

Comments

Stefan Hajnoczi - June 14, 2012, 10:42 a.m.
The autoclear feature bits can be used for qcow2 file format features
that are safe to "drop" by old programs that do not understand the
feature.  Upon opening the image file unknown autoclear feature bits are
cleared and the image file header is rewritten, but this was happening
too early in the code when critical header fields were not yet loaded.

Process autoclear feature bits after all necessary header information
has been loaded.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block/qcow2.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
Kevin Wolf - June 14, 2012, 11:06 a.m.
Am 14.06.2012 12:42, schrieb Stefan Hajnoczi:
> The autoclear feature bits can be used for qcow2 file format features
> that are safe to "drop" by old programs that do not understand the
> feature.  Upon opening the image file unknown autoclear feature bits are
> cleared and the image file header is rewritten, but this was happening
> too early in the code when critical header fields were not yet loaded.
> 
> Process autoclear feature bits after all necessary header information
> has been loaded.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Ouch...

You don't have a qemu-iotests case to offer for the feature bit
handling, by any chance?

Kevin
Stefan Hajnoczi - June 14, 2012, 11:16 a.m.
On Thu, Jun 14, 2012 at 12:06 PM, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 14.06.2012 12:42, schrieb Stefan Hajnoczi:
>> The autoclear feature bits can be used for qcow2 file format features
>> that are safe to "drop" by old programs that do not understand the
>> feature.  Upon opening the image file unknown autoclear feature bits are
>> cleared and the image file header is rewritten, but this was happening
>> too early in the code when critical header fields were not yet loaded.
>>
>> Process autoclear feature bits after all necessary header information
>> has been loaded.
>>
>> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>
> Ouch...
>
> You don't have a qemu-iotests case to offer for the feature bit
> handling, by any chance?

Nope.  I'll cook one up, should be easy with your qcow2.py module.

Stefan

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index c2e49cd..79201fc 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -298,14 +298,6 @@  static int qcow2_open(BlockDriverState *bs, int flags)
         goto fail;
     }
 
-    if (!bs->read_only && s->autoclear_features != 0) {
-        s->autoclear_features = 0;
-        ret = qcow2_update_header(bs);
-        if (ret < 0) {
-            goto fail;
-        }
-    }
-
     /* Check support for various header values */
     if (header.refcount_order != 4) {
         report_unsupported(bs, "%d bit reference counts",
@@ -411,6 +403,15 @@  static int qcow2_open(BlockDriverState *bs, int flags)
         goto fail;
     }
 
+    /* Clear unknown autoclear feature bits */
+    if (!bs->read_only && s->autoclear_features != 0) {
+        s->autoclear_features = 0;
+        ret = qcow2_update_header(bs);
+        if (ret < 0) {
+            goto fail;
+        }
+    }
+
     /* Initialise locks */
     qemu_co_mutex_init(&s->lock);