Skip to contentSkip to conversation

qcow2: fix autoclear image header update

PATCH Superseded Stefan Hajnoczi 3 participants 3 messages Jun 14, 2012 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qcow2: fix autoclear image header update

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.

---
 block/qcow2.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
block/qcow2.c +9 -8
index c2e49cd..79201fc 100644
@@ -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);
 
Signature · 1 line
1.7.10
#1 lore raw

Am 14.06.2012 12:42, schrieb Stefan Hajnoczi:

Quoted 10 lines

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.

Ouch...

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

Kevin

#2 lore raw
Quoted 10 lines · Kevin Wolf

Am 14.06.2012 12:42, schrieb Stefan Hajnoczi:

Quoted 9 lines

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.

Quoted 6 lines
Quoted 1 line

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