Patchwork [v2,2/3] qemu-iotests: add qcow2.py set-feature-bit command

login
register
mail settings
Submitter Stefan Hajnoczi
Date June 14, 2012, 12:58 p.m.
Message ID <1339678698-17726-3-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/164925/
State New
Headers show

Comments

Stefan Hajnoczi - June 14, 2012, 12:58 p.m.
This 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).

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 tests/qemu-iotests/qcow2.py |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
Kevin Wolf - June 14, 2012, 3:02 p.m.
Am 14.06.2012 14:58, schrieb Stefan Hajnoczi:
> This 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).
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
>  tests/qemu-iotests/qcow2.py |   23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py
> index e27196a..97f3770 100755
> --- a/tests/qemu-iotests/qcow2.py
> +++ b/tests/qemu-iotests/qcow2.py
> @@ -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

diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py
index e27196a..97f3770 100755
--- a/tests/qemu-iotests/qcow2.py
+++ b/tests/qemu-iotests/qcow2.py
@@ -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):