From c8da29122142f498215881e8bb933de278a3809a Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Sun, 29 Dec 2013 22:06:54 +0100 Subject: [PATCH 3/8] qcow2.py: Subcommand for changing header fields RH-Author: Max Reitz Message-id: <1388354817-3013-3-git-send-email-mreitz@redhat.com> Patchwork-id: 56444 O-Subject: [RHEL-7.0 qemu-kvm PATCH 2/5] qcow2.py: Subcommand for changing header fields Bugzilla: 1004347 RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Fam Zheng RH-Acked-by: Kevin Wolf From: Kevin Wolf BZ: 1004347 Signed-off-by: Kevin Wolf (cherry picked from commit c93331c9146719958a4b102435fcd0566da45ea2) Signed-off-by: Max Reitz --- tests/qemu-iotests/qcow2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) Signed-off-by: Miroslav Rezanina --- tests/qemu-iotests/qcow2.py | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py index fecf5b9..44a2b45 100755 --- a/tests/qemu-iotests/qcow2.py +++ b/tests/qemu-iotests/qcow2.py @@ -149,6 +149,22 @@ def cmd_dump_header(fd): h.dump() h.dump_extensions() +def cmd_set_header(fd, name, value): + try: + value = int(value, 0) + except: + print "'%s' is not a valid number" % value + sys.exit(1) + + fields = (field[2] for field in QcowHeader.fields) + if not name in fields: + print "'%s' is not a known header field" % name + sys.exit(1) + + h = QcowHeader(fd) + h.__dict__[name] = value + h.update(fd) + def cmd_add_header_ext(fd, magic, data): try: magic = int(magic, 0) @@ -205,6 +221,7 @@ def cmd_set_feature_bit(fd, group, bit): cmds = [ [ 'dump-header', cmd_dump_header, 0, 'Dump image header and header extensions' ], + [ 'set-header', cmd_set_header, 2, 'Set a field in the header'], [ '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'], -- 1.7.1