qcow2: fix autoclear image header update
v2 cover qcow2: fix autoclear image header update
The code path to clear unknown autoclear feature bits when opening a qcow2 image file was broken. This series includes the fix along with the qemu-iotest to verify the issue and prevent regressions in the future.
v2:
* Add qemu-iotest [Kevin]
Stefan Hajnoczi (3):
qcow2: fix autoclear image header update
qemu-iotests: add qcow2.py set-feature-bit command
qemu-iotests: add 036 autoclear feature bit test
block/qcow2.c | 17 ++++++----- tests/qemu-iotests/036 | 68 +++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/036.out | 52 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + tests/qemu-iotests/qcow2.py | 23 +++++++++++++++ 5 files changed, 153 insertions(+), 8 deletions(-) create mode 100755 tests/qemu-iotests/036 create mode 100644 tests/qemu-iotests/036.out
Signature · 1 line
1.7.10
PATCH v2 1/3 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
@@ -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
PATCH v2 2/3 qemu-iotests: add qcow2.py set-feature-bit command
In reply to Stefan HajnocziThis new command sets feature bits in the image file header:
qcow2.py set-feature-bit incompatible|compatible|autoclear <bit>
The bit number must be in the range [0, 64).
--- tests/qemu-iotests/qcow2.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
tests/qemu-iotests/qcow2.py +23 -0
@@ -181,10 +181,33 @@ def cmd_del_header_ext(fd, magic): h.update(fd) +def cmd_set_feature_bit(fd, group, bit): + try: + bit = int(bit, 0) + if bit < 0 or bit >= 64: + raise ValueError + except: + print "'%s' is not a valid bit number in range [0, 64)" % bit + sys.exit(1) + + h = QcowHeader(fd) + if group == 'incompatible': + h.incompatible_features |= 1 << bit + elif group == 'compatible': + h.compatible_features |= 1 << bit + elif group == 'autoclear': + h.autoclear_features |= 1 << bit + else: + print "'%s' is not a valid group, try 'incompatible', 'compatible', or 'autoclear'" % group + sys.exit(1) + + h.update(fd) + cmds = [ [ 'dump-header', cmd_dump_header, 0, 'Dump image header and header extensions' ], [ 'add-header-ext', cmd_add_header_ext, 2, 'Add a header extension' ], [ 'del-header-ext', cmd_del_header_ext, 1, 'Delete a header extension' ], + [ 'set-feature-bit', cmd_set_feature_bit, 2, 'Set a feature bit'], ] def main(filename, cmd, args):
Signature · 1 line
1.7.10
Kevin Wolf
AppliedRe: [Qemu-devel] [PATCH v2 2/3] qemu-iotests: add qcow2.py set-feature-bit command
Am 14.06.2012 14:58, schrieb Stefan Hajnoczi:
Quoted 16 lines
This new command sets feature bits in the image file header:
qcow2.pyset-feature-bit incompatible|compatible|autoclear <bit>The bit number must be in the range [0, 64).
Signed-off-by Stefan Hajnoczi <[email protected]>--- tests/qemu-iotests/qcow2.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)tests/qemu-iotests/qcow2.py +0
-0
tests/qemu-iotests/qcow2.py def cmd_del_header_ext(fd, magic): · line 190
Quoted 10 lines
tests/qemu-iotests/qcow2.py +7
-0@@ -181,10 +181,33 @@ def cmd_del_header_ext(fd, magic): h.update(fd) +def cmd_set_feature_bit(fd, group, bit): + try: + bit = int(bit, 0) + if bit < 0 or bit >= 64: + raise ValueError + except: + print "'%s' is not a valid bit number in range [0, 64)" % bit
Heh, open intervals on integers are nice. ;-)
Thanks, applied all to the block branch.
Kevin
PATCH v2 3/3 qemu-iotests: add 036 autoclear feature bit test
In reply to Stefan HajnocziThis new test validates the autoclear feature bit behavior. When QEMU opens a qcow2v3 image file with an unknown autoclear feature bit the bit should be cleared in the image file header.
--- tests/qemu-iotests/036 | 68 ++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/036.out | 52 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 121 insertions(+) create mode 100755 tests/qemu-iotests/036 create mode 100644 tests/qemu-iotests/036.out
tests/qemu-iotests/036 new file +68 -0
@@ -0,0 +1,68 @@ +#!/bin/bash +# +# Test that qcow2 unknown autoclear feature bits are cleared +# +# Copyright (C) 2011 Red Hat, Inc. +# Copyright IBM, Corp. 2010 +# +# Based on test 031. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.pattern + +# This tests qcow2-specific low-level functionality +_supported_fmt qcow2 +_supported_proto generic +_supported_os Linux + +# Only qcow2v3 and later supports feature bits +IMGOPTS="compat=1.1" + +echo === Create image with unknown autoclear feature bit === +echo +_make_test_img 64M +./qcow2.py $TEST_IMG set-feature-bit autoclear 63 +./qcow2.py $TEST_IMG dump-header + +echo +echo === Repair image === +echo +$QEMU_IMG check -r all $TEST_IMG +./qcow2.py $TEST_IMG dump-header + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/036.out new file +52 -0
52 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -42,3 +42,4 @@ 033 rw auto 034 rw auto backing 035 rw auto quick +036 rw auto quick
Signature · 1 line
1.7.10