qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity
@ 2016-04-20 14:32 Kevin Wolf
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 1/3] mirror: Don't extend the last sub-chunk Kevin Wolf
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Kevin Wolf @ 2016-04-20 14:32 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, famz, mreitz, jcody, qemu-devel

Taking over Fam's series as we're late for -rc3. Original cover letter:

    This fixes the bug introduced in e5b43573e28 and lately noticed by Kevin.

v2: Move the mirror_clip_sectors() to mirror_iteration. [Max]
v3: Fix nb_clusters calculation and add a test case for it [Kevin]

Fam Zheng (3):
  mirror: Don't extend the last sub-chunk
  iotests: Add iotests.image_size
  iotests: Test case for drive-mirror with unaligned image size

 block/mirror.c                | 19 ++++++++++---
 tests/qemu-iotests/109.out    | 44 +++++++++++++++---------------
 tests/qemu-iotests/152        | 62 +++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/152.out    |  5 ++++
 tests/qemu-iotests/group      |  1 +
 tests/qemu-iotests/iotests.py |  6 +++++
 6 files changed, 111 insertions(+), 26 deletions(-)
 create mode 100644 tests/qemu-iotests/152
 create mode 100644 tests/qemu-iotests/152.out

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH for-2.6 v3 1/3] mirror: Don't extend the last sub-chunk
  2016-04-20 14:32 [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Kevin Wolf
@ 2016-04-20 14:32 ` Kevin Wolf
  2016-04-20 14:46   ` Max Reitz
  2016-04-20 14:47   ` Jeff Cody
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 2/3] iotests: Add iotests.image_size Kevin Wolf
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 12+ messages in thread
From: Kevin Wolf @ 2016-04-20 14:32 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, famz, mreitz, jcody, qemu-devel

From: Fam Zheng <famz@redhat.com>

The last sub-chunk is rounded up to the copy granularity in the target
image, resulting in a larger size than the source.

Add a function to clip the copied sectors to the end.

This undoes the "wrong" changes to tests/qemu-iotests/109.out in
e5b43573e28. The remaining two offset changes are okay.

[ kwolf: Use DIV_ROUND_UP to calculate nb_chunks now ]

Reported-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/mirror.c             | 19 +++++++++++++++----
 tests/qemu-iotests/109.out | 44 ++++++++++++++++++++++----------------------
 2 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index 9df1fae..d56e30e 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -108,7 +108,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret)
 
     sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
     chunk_num = op->sector_num / sectors_per_chunk;
-    nb_chunks = op->nb_sectors / sectors_per_chunk;
+    nb_chunks = DIV_ROUND_UP(op->nb_sectors, sectors_per_chunk);
     bitmap_clear(s->in_flight_bitmap, chunk_num, nb_chunks);
     if (ret >= 0) {
         if (s->cow_bitmap) {
@@ -161,6 +161,14 @@ static void mirror_read_complete(void *opaque, int ret)
                     mirror_write_complete, op);
 }
 
+static inline void mirror_clip_sectors(MirrorBlockJob *s,
+                                       int64_t sector_num,
+                                       int *nb_sectors)
+{
+    *nb_sectors = MIN(*nb_sectors,
+                      s->bdev_length / BDRV_SECTOR_SIZE - sector_num);
+}
+
 /* Round sector_num and/or nb_sectors to target cluster if COW is needed, and
  * return the offset of the adjusted tail sector against original. */
 static int mirror_cow_align(MirrorBlockJob *s,
@@ -189,6 +197,9 @@ static int mirror_cow_align(MirrorBlockJob *s,
                                                s->target_cluster_sectors);
         }
     }
+    /* Clipping may result in align_nb_sectors unaligned to chunk boundary, but
+     * that doesn't matter because it's already the end of source image. */
+    mirror_clip_sectors(s, align_sector_num, &align_nb_sectors);
 
     ret = align_sector_num + align_nb_sectors - (*sector_num + *nb_sectors);
     *sector_num = align_sector_num;
@@ -231,9 +242,8 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,
     /* The sector range must meet granularity because:
      * 1) Caller passes in aligned values;
      * 2) mirror_cow_align is used only when target cluster is larger. */
-    assert(!(nb_sectors % sectors_per_chunk));
     assert(!(sector_num % sectors_per_chunk));
-    nb_chunks = nb_sectors / sectors_per_chunk;
+    nb_chunks = DIV_ROUND_UP(nb_sectors, sectors_per_chunk);
 
     while (s->buf_free_count < nb_chunks) {
         trace_mirror_yield_in_flight(s, sector_num, s->in_flight);
@@ -384,6 +394,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
             }
         }
 
+        mirror_clip_sectors(s, sector_num, &io_sectors);
         switch (mirror_method) {
         case MIRROR_METHOD_COPY:
             io_sectors = mirror_do_read(s, sector_num, io_sectors);
@@ -399,7 +410,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
         }
         assert(io_sectors);
         sector_num += io_sectors;
-        nb_chunks -= io_sectors / sectors_per_chunk;
+        nb_chunks -= DIV_ROUND_UP(io_sectors, sectors_per_chunk);
         delay_ns += ratelimit_calculate_delay(&s->limit, io_sectors);
     }
     return delay_ns;
diff --git a/tests/qemu-iotests/109.out b/tests/qemu-iotests/109.out
index b3358de..38bc073 100644
--- a/tests/qemu-iotests/109.out
+++ b/tests/qemu-iotests/109.out
@@ -10,14 +10,14 @@ Automatically detecting the format is dangerous for raw images, write operations
 Specify the 'raw' format explicitly to remove the restrictions.
 {"return": {}}
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 1024, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
 {"return": []}
 read 65536/65536 bytes at offset 0
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
-{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 1024, "offset": 1024, "speed": 0, "type": "mirror"}}
+{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 1024, "offset": 1024, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
 Warning: Image size mismatch!
 Images are identical.
 
@@ -31,14 +31,14 @@ Automatically detecting the format is dangerous for raw images, write operations
 Specify the 'raw' format explicitly to remove the restrictions.
 {"return": {}}
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 262144, "offset": 65536, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 197120, "offset": 512, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
 {"return": []}
 read 65536/65536 bytes at offset 0
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 262144, "offset": 262144, "speed": 0, "type": "mirror"}}
-{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 262144, "offset": 262144, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 197120, "offset": 197120, "speed": 0, "type": "mirror"}}
+{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 197120, "offset": 197120, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
 Warning: Image size mismatch!
 Images are identical.
 
@@ -73,14 +73,14 @@ Automatically detecting the format is dangerous for raw images, write operations
 Specify the 'raw' format explicitly to remove the restrictions.
 {"return": {}}
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 1024, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
 {"return": []}
 read 65536/65536 bytes at offset 0
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
-{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 1024, "offset": 1024, "speed": 0, "type": "mirror"}}
+{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 1024, "offset": 1024, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
 Warning: Image size mismatch!
 Images are identical.
 
@@ -115,14 +115,14 @@ Automatically detecting the format is dangerous for raw images, write operations
 Specify the 'raw' format explicitly to remove the restrictions.
 {"return": {}}
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2560, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
 {"return": []}
 read 65536/65536 bytes at offset 0
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
-{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 2560, "offset": 2560, "speed": 0, "type": "mirror"}}
+{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 2560, "offset": 2560, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
 Warning: Image size mismatch!
 Images are identical.
 
@@ -135,14 +135,14 @@ Automatically detecting the format is dangerous for raw images, write operations
 Specify the 'raw' format explicitly to remove the restrictions.
 {"return": {}}
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2560, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
 {"return": []}
 read 65536/65536 bytes at offset 0
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
-{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 2560, "offset": 2560, "speed": 0, "type": "mirror"}}
+{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 2560, "offset": 2560, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
 Image resized.
 Warning: Image size mismatch!
 Images are identical.
@@ -198,14 +198,14 @@ Automatically detecting the format is dangerous for raw images, write operations
 Specify the 'raw' format explicitly to remove the restrictions.
 {"return": {}}
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2048, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
 {"return": []}
 read 65536/65536 bytes at offset 0
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
-{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 2048, "offset": 2048, "speed": 0, "type": "mirror"}}
+{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 2048, "offset": 2048, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
 Image resized.
 Warning: Image size mismatch!
 Images are identical.
@@ -218,14 +218,14 @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed
 Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
 Specify the 'raw' format explicitly to remove the restrictions.
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
-{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 512, "offset": 512, "speed": 0, "type": "mirror"}}
+{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 512, "offset": 512, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
 Warning: Image size mismatch!
 Images are identical.
 {"return": {}}
 {"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
-{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 512, "offset": 512, "speed": 0, "type": "mirror"}}
+{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 512, "offset": 512, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
 Warning: Image size mismatch!
 Images are identical.
 *** done
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH for-2.6 v3 2/3] iotests: Add iotests.image_size
  2016-04-20 14:32 [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Kevin Wolf
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 1/3] mirror: Don't extend the last sub-chunk Kevin Wolf
@ 2016-04-20 14:32 ` Kevin Wolf
  2016-04-20 14:48   ` Jeff Cody
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 3/3] iotests: Test case for drive-mirror with unaligned image size Kevin Wolf
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Kevin Wolf @ 2016-04-20 14:32 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, famz, mreitz, jcody, qemu-devel

From: Fam Zheng <famz@redhat.com>

This retrieves the virtual size of the image out of qemu-img info.

Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/iotests.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index d9ef60e..56f988a 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -28,6 +28,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts', '
 import qmp
 import qtest
 import struct
+import json
 
 
 # This will not work if arguments contain spaces but is necessary if we
@@ -103,6 +104,11 @@ def create_image(name, size):
         i = i + 512
     file.close()
 
+def image_size(img):
+    '''Return image's virtual size'''
+    r = qemu_img_pipe('info', '--output=json', '-f', imgfmt, img)
+    return json.loads(r)['virtual-size']
+
 test_dir_re = re.compile(r"%s" % test_dir)
 def filter_test_dir(msg):
     return test_dir_re.sub("TEST_DIR", msg)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH for-2.6 v3 3/3] iotests: Test case for drive-mirror with unaligned image size
  2016-04-20 14:32 [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Kevin Wolf
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 1/3] mirror: Don't extend the last sub-chunk Kevin Wolf
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 2/3] iotests: Add iotests.image_size Kevin Wolf
@ 2016-04-20 14:32 ` Kevin Wolf
  2016-04-20 14:49   ` Max Reitz
  2016-04-20 14:50   ` Jeff Cody
  2016-04-20 14:51 ` [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Jeff Cody
  2016-04-21  2:12 ` Fam Zheng
  4 siblings, 2 replies; 12+ messages in thread
From: Kevin Wolf @ 2016-04-20 14:32 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, famz, mreitz, jcody, qemu-devel

From: Fam Zheng <famz@redhat.com>

This is the regression test for the virtual size mismatch issue between
target and source images.

[ kwolf: Added test_unaligned_with_update ]

Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/152     | 62 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/152.out |  5 ++++
 tests/qemu-iotests/group   |  1 +
 3 files changed, 68 insertions(+)
 create mode 100644 tests/qemu-iotests/152
 create mode 100644 tests/qemu-iotests/152.out

diff --git a/tests/qemu-iotests/152 b/tests/qemu-iotests/152
new file mode 100644
index 0000000..fec546d
--- /dev/null
+++ b/tests/qemu-iotests/152
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+#
+# Tests for drive-mirror with source size unaligned to granularity
+#
+# Copyright (C) 2016 Red Hat, Inc.
+#
+# 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/>.
+#
+
+import os
+import iotests
+from iotests import qemu_img
+
+test_img = os.path.join(iotests.test_dir, 'test.img')
+target_img = os.path.join(iotests.test_dir, 'target.img')
+
+class TestUnaligned(iotests.QMPTestCase):
+    def setUp(self):
+        qemu_img('create', '-f', iotests.imgfmt, test_img, '512')
+        self.vm = iotests.VM().add_drive(test_img)
+        self.vm.launch()
+
+    def tearDown(self):
+        self.vm.shutdown()
+        os.remove(test_img)
+        try:
+            os.remove(target_img)
+        except OSError:
+            pass
+
+    def test_unaligned(self):
+        result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
+                             granularity=65536, target=target_img)
+        self.complete_and_wait()
+        self.vm.shutdown()
+        self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img),
+                         "Target size doesn't match source when granularity when unaligend")
+
+    def test_unaligned_with_update(self):
+        result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
+                             granularity=65536, target=target_img)
+        self.wait_ready()
+        self.vm.hmp_qemu_io('drive0', 'write 0 512')
+        self.complete_and_wait(wait_ready=False)
+        self.vm.shutdown()
+        self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img),
+                         "Target size doesn't match source when granularity when unaligend")
+
+
+if __name__ == '__main__':
+    iotests.main(supported_fmts=['raw', 'qcow2'])
diff --git a/tests/qemu-iotests/152.out b/tests/qemu-iotests/152.out
new file mode 100644
index 0000000..fbc63e6
--- /dev/null
+++ b/tests/qemu-iotests/152.out
@@ -0,0 +1,5 @@
+..
+----------------------------------------------------------------------
+Ran 2 tests
+
+OK
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 2952b9d..822953b 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -152,3 +152,4 @@
 148 rw auto quick
 149 rw auto sudo
 150 rw auto quick
+152 rw auto quick
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6 v3 1/3] mirror: Don't extend the last sub-chunk
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 1/3] mirror: Don't extend the last sub-chunk Kevin Wolf
@ 2016-04-20 14:46   ` Max Reitz
  2016-04-20 14:47   ` Jeff Cody
  1 sibling, 0 replies; 12+ messages in thread
From: Max Reitz @ 2016-04-20 14:46 UTC (permalink / raw)
  To: Kevin Wolf, qemu-block; +Cc: famz, jcody, qemu-devel


[-- Attachment #1.1: Type: text/plain, Size: 854 bytes --]

On 20.04.2016 16:32, Kevin Wolf wrote:
> From: Fam Zheng <famz@redhat.com>
> 
> The last sub-chunk is rounded up to the copy granularity in the target
> image, resulting in a larger size than the source.
> 
> Add a function to clip the copied sectors to the end.
> 
> This undoes the "wrong" changes to tests/qemu-iotests/109.out in
> e5b43573e28. The remaining two offset changes are okay.
> 
> [ kwolf: Use DIV_ROUND_UP to calculate nb_chunks now ]
> 
> Reported-by: Kevin Wolf <kwolf@redhat.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block/mirror.c             | 19 +++++++++++++++----
>  tests/qemu-iotests/109.out | 44 ++++++++++++++++++++++----------------------
>  2 files changed, 37 insertions(+), 26 deletions(-)

Reviewed-by: Max Reitz <mreitz@redhat.com>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6 v3 1/3] mirror: Don't extend the last sub-chunk
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 1/3] mirror: Don't extend the last sub-chunk Kevin Wolf
  2016-04-20 14:46   ` Max Reitz
@ 2016-04-20 14:47   ` Jeff Cody
  1 sibling, 0 replies; 12+ messages in thread
From: Jeff Cody @ 2016-04-20 14:47 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-block, famz, mreitz, qemu-devel

On Wed, Apr 20, 2016 at 04:32:44PM +0200, Kevin Wolf wrote:
> From: Fam Zheng <famz@redhat.com>
> 
> The last sub-chunk is rounded up to the copy granularity in the target
> image, resulting in a larger size than the source.
> 
> Add a function to clip the copied sectors to the end.
> 
> This undoes the "wrong" changes to tests/qemu-iotests/109.out in
> e5b43573e28. The remaining two offset changes are okay.
> 
> [ kwolf: Use DIV_ROUND_UP to calculate nb_chunks now ]
> 
> Reported-by: Kevin Wolf <kwolf@redhat.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block/mirror.c             | 19 +++++++++++++++----
>  tests/qemu-iotests/109.out | 44 ++++++++++++++++++++++----------------------
>  2 files changed, 37 insertions(+), 26 deletions(-)
> 
> diff --git a/block/mirror.c b/block/mirror.c
> index 9df1fae..d56e30e 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -108,7 +108,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret)
>  
>      sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
>      chunk_num = op->sector_num / sectors_per_chunk;
> -    nb_chunks = op->nb_sectors / sectors_per_chunk;
> +    nb_chunks = DIV_ROUND_UP(op->nb_sectors, sectors_per_chunk);
>      bitmap_clear(s->in_flight_bitmap, chunk_num, nb_chunks);
>      if (ret >= 0) {
>          if (s->cow_bitmap) {
> @@ -161,6 +161,14 @@ static void mirror_read_complete(void *opaque, int ret)
>                      mirror_write_complete, op);
>  }
>  
> +static inline void mirror_clip_sectors(MirrorBlockJob *s,
> +                                       int64_t sector_num,
> +                                       int *nb_sectors)
> +{
> +    *nb_sectors = MIN(*nb_sectors,
> +                      s->bdev_length / BDRV_SECTOR_SIZE - sector_num);
> +}
> +
>  /* Round sector_num and/or nb_sectors to target cluster if COW is needed, and
>   * return the offset of the adjusted tail sector against original. */
>  static int mirror_cow_align(MirrorBlockJob *s,
> @@ -189,6 +197,9 @@ static int mirror_cow_align(MirrorBlockJob *s,
>                                                 s->target_cluster_sectors);
>          }
>      }
> +    /* Clipping may result in align_nb_sectors unaligned to chunk boundary, but
> +     * that doesn't matter because it's already the end of source image. */
> +    mirror_clip_sectors(s, align_sector_num, &align_nb_sectors);
>  
>      ret = align_sector_num + align_nb_sectors - (*sector_num + *nb_sectors);
>      *sector_num = align_sector_num;
> @@ -231,9 +242,8 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,
>      /* The sector range must meet granularity because:
>       * 1) Caller passes in aligned values;
>       * 2) mirror_cow_align is used only when target cluster is larger. */
> -    assert(!(nb_sectors % sectors_per_chunk));
>      assert(!(sector_num % sectors_per_chunk));
> -    nb_chunks = nb_sectors / sectors_per_chunk;
> +    nb_chunks = DIV_ROUND_UP(nb_sectors, sectors_per_chunk);
>  
>      while (s->buf_free_count < nb_chunks) {
>          trace_mirror_yield_in_flight(s, sector_num, s->in_flight);
> @@ -384,6 +394,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
>              }
>          }
>  
> +        mirror_clip_sectors(s, sector_num, &io_sectors);
>          switch (mirror_method) {
>          case MIRROR_METHOD_COPY:
>              io_sectors = mirror_do_read(s, sector_num, io_sectors);
> @@ -399,7 +410,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
>          }
>          assert(io_sectors);
>          sector_num += io_sectors;
> -        nb_chunks -= io_sectors / sectors_per_chunk;
> +        nb_chunks -= DIV_ROUND_UP(io_sectors, sectors_per_chunk);
>          delay_ns += ratelimit_calculate_delay(&s->limit, io_sectors);
>      }
>      return delay_ns;
> diff --git a/tests/qemu-iotests/109.out b/tests/qemu-iotests/109.out
> index b3358de..38bc073 100644
> --- a/tests/qemu-iotests/109.out
> +++ b/tests/qemu-iotests/109.out
> @@ -10,14 +10,14 @@ Automatically detecting the format is dangerous for raw images, write operations
>  Specify the 'raw' format explicitly to remove the restrictions.
>  {"return": {}}
>  {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 1024, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
>  {"return": []}
>  read 65536/65536 bytes at offset 0
>  64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>  {"return": {}}
>  {"return": {}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
> -{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 1024, "offset": 1024, "speed": 0, "type": "mirror"}}
> +{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 1024, "offset": 1024, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
>  Warning: Image size mismatch!
>  Images are identical.
>  
> @@ -31,14 +31,14 @@ Automatically detecting the format is dangerous for raw images, write operations
>  Specify the 'raw' format explicitly to remove the restrictions.
>  {"return": {}}
>  {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 262144, "offset": 65536, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 197120, "offset": 512, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
>  {"return": []}
>  read 65536/65536 bytes at offset 0
>  64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>  {"return": {}}
>  {"return": {}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 262144, "offset": 262144, "speed": 0, "type": "mirror"}}
> -{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 262144, "offset": 262144, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 197120, "offset": 197120, "speed": 0, "type": "mirror"}}
> +{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 197120, "offset": 197120, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
>  Warning: Image size mismatch!
>  Images are identical.
>  
> @@ -73,14 +73,14 @@ Automatically detecting the format is dangerous for raw images, write operations
>  Specify the 'raw' format explicitly to remove the restrictions.
>  {"return": {}}
>  {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 1024, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
>  {"return": []}
>  read 65536/65536 bytes at offset 0
>  64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>  {"return": {}}
>  {"return": {}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
> -{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 1024, "offset": 1024, "speed": 0, "type": "mirror"}}
> +{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 1024, "offset": 1024, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
>  Warning: Image size mismatch!
>  Images are identical.
>  
> @@ -115,14 +115,14 @@ Automatically detecting the format is dangerous for raw images, write operations
>  Specify the 'raw' format explicitly to remove the restrictions.
>  {"return": {}}
>  {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2560, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
>  {"return": []}
>  read 65536/65536 bytes at offset 0
>  64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>  {"return": {}}
>  {"return": {}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
> -{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 2560, "offset": 2560, "speed": 0, "type": "mirror"}}
> +{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 2560, "offset": 2560, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
>  Warning: Image size mismatch!
>  Images are identical.
>  
> @@ -135,14 +135,14 @@ Automatically detecting the format is dangerous for raw images, write operations
>  Specify the 'raw' format explicitly to remove the restrictions.
>  {"return": {}}
>  {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2560, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
>  {"return": []}
>  read 65536/65536 bytes at offset 0
>  64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>  {"return": {}}
>  {"return": {}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
> -{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 2560, "offset": 2560, "speed": 0, "type": "mirror"}}
> +{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 2560, "offset": 2560, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
>  Image resized.
>  Warning: Image size mismatch!
>  Images are identical.
> @@ -198,14 +198,14 @@ Automatically detecting the format is dangerous for raw images, write operations
>  Specify the 'raw' format explicitly to remove the restrictions.
>  {"return": {}}
>  {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_ERROR", "data": {"device": "src", "operation": "write", "action": "report"}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2048, "offset": 0, "speed": 0, "type": "mirror", "error": "Operation not permitted"}}
>  {"return": []}
>  read 65536/65536 bytes at offset 0
>  64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>  {"return": {}}
>  {"return": {}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
> -{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 2048, "offset": 2048, "speed": 0, "type": "mirror"}}
> +{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 2048, "offset": 2048, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
>  Image resized.
>  Warning: Image size mismatch!
>  Images are identical.
> @@ -218,14 +218,14 @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed
>  Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
>  Specify the 'raw' format explicitly to remove the restrictions.
>  {"return": {}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
> -{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 512, "offset": 512, "speed": 0, "type": "mirror"}}
> +{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 512, "offset": 512, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
>  Warning: Image size mismatch!
>  Images are identical.
>  {"return": {}}
>  {"return": {}}
> -{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
> -{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 65536, "offset": 65536, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
> +{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "src", "len": 512, "offset": 512, "speed": 0, "type": "mirror"}}
> +{"return": [{"io-status": "ok", "device": "src", "busy": false, "len": 512, "offset": 512, "paused": false, "speed": 0, "ready": true, "type": "mirror"}]}
>  Warning: Image size mismatch!
>  Images are identical.
>  *** done
> -- 
> 1.8.3.1
>

Reviewed-by: Jeff Cody <jcody@redhat.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6 v3 2/3] iotests: Add iotests.image_size
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 2/3] iotests: Add iotests.image_size Kevin Wolf
@ 2016-04-20 14:48   ` Jeff Cody
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Cody @ 2016-04-20 14:48 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-block, famz, mreitz, qemu-devel

On Wed, Apr 20, 2016 at 04:32:45PM +0200, Kevin Wolf wrote:
> From: Fam Zheng <famz@redhat.com>
> 
> This retrieves the virtual size of the image out of qemu-img info.
> 
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  tests/qemu-iotests/iotests.py | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index d9ef60e..56f988a 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -28,6 +28,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts', '
>  import qmp
>  import qtest
>  import struct
> +import json
>  
>  
>  # This will not work if arguments contain spaces but is necessary if we
> @@ -103,6 +104,11 @@ def create_image(name, size):
>          i = i + 512
>      file.close()
>  
> +def image_size(img):
> +    '''Return image's virtual size'''
> +    r = qemu_img_pipe('info', '--output=json', '-f', imgfmt, img)
> +    return json.loads(r)['virtual-size']
> +
>  test_dir_re = re.compile(r"%s" % test_dir)
>  def filter_test_dir(msg):
>      return test_dir_re.sub("TEST_DIR", msg)
> -- 
> 1.8.3.1
> 

Reviewed-by: Jeff Cody <jcody@redhat.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6 v3 3/3] iotests: Test case for drive-mirror with unaligned image size
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 3/3] iotests: Test case for drive-mirror with unaligned image size Kevin Wolf
@ 2016-04-20 14:49   ` Max Reitz
  2016-04-20 14:50   ` Jeff Cody
  1 sibling, 0 replies; 12+ messages in thread
From: Max Reitz @ 2016-04-20 14:49 UTC (permalink / raw)
  To: Kevin Wolf, qemu-block; +Cc: famz, jcody, qemu-devel


[-- Attachment #1.1: Type: text/plain, Size: 685 bytes --]

On 20.04.2016 16:32, Kevin Wolf wrote:
> From: Fam Zheng <famz@redhat.com>
> 
> This is the regression test for the virtual size mismatch issue between
> target and source images.
> 
> [ kwolf: Added test_unaligned_with_update ]
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  tests/qemu-iotests/152     | 62 ++++++++++++++++++++++++++++++++++++++++++++++
>  tests/qemu-iotests/152.out |  5 ++++
>  tests/qemu-iotests/group   |  1 +
>  3 files changed, 68 insertions(+)
>  create mode 100644 tests/qemu-iotests/152
>  create mode 100644 tests/qemu-iotests/152.out

Reviewed-by: Max Reitz <mreitz@redhat.com>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6 v3 3/3] iotests: Test case for drive-mirror with unaligned image size
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 3/3] iotests: Test case for drive-mirror with unaligned image size Kevin Wolf
  2016-04-20 14:49   ` Max Reitz
@ 2016-04-20 14:50   ` Jeff Cody
  1 sibling, 0 replies; 12+ messages in thread
From: Jeff Cody @ 2016-04-20 14:50 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-block, famz, mreitz, qemu-devel

On Wed, Apr 20, 2016 at 04:32:46PM +0200, Kevin Wolf wrote:
> From: Fam Zheng <famz@redhat.com>
> 
> This is the regression test for the virtual size mismatch issue between
> target and source images.
> 
> [ kwolf: Added test_unaligned_with_update ]
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  tests/qemu-iotests/152     | 62 ++++++++++++++++++++++++++++++++++++++++++++++
>  tests/qemu-iotests/152.out |  5 ++++
>  tests/qemu-iotests/group   |  1 +
>  3 files changed, 68 insertions(+)
>  create mode 100644 tests/qemu-iotests/152
>  create mode 100644 tests/qemu-iotests/152.out
> 
> diff --git a/tests/qemu-iotests/152 b/tests/qemu-iotests/152
> new file mode 100644
> index 0000000..fec546d
> --- /dev/null
> +++ b/tests/qemu-iotests/152
> @@ -0,0 +1,62 @@
> +#!/usr/bin/env python
> +#
> +# Tests for drive-mirror with source size unaligned to granularity
> +#
> +# Copyright (C) 2016 Red Hat, Inc.
> +#
> +# 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/>.
> +#
> +
> +import os
> +import iotests
> +from iotests import qemu_img
> +
> +test_img = os.path.join(iotests.test_dir, 'test.img')
> +target_img = os.path.join(iotests.test_dir, 'target.img')
> +
> +class TestUnaligned(iotests.QMPTestCase):
> +    def setUp(self):
> +        qemu_img('create', '-f', iotests.imgfmt, test_img, '512')
> +        self.vm = iotests.VM().add_drive(test_img)
> +        self.vm.launch()
> +
> +    def tearDown(self):
> +        self.vm.shutdown()
> +        os.remove(test_img)
> +        try:
> +            os.remove(target_img)
> +        except OSError:
> +            pass
> +
> +    def test_unaligned(self):
> +        result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
> +                             granularity=65536, target=target_img)
> +        self.complete_and_wait()
> +        self.vm.shutdown()
> +        self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img),
> +                         "Target size doesn't match source when granularity when unaligend")
> +
> +    def test_unaligned_with_update(self):
> +        result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
> +                             granularity=65536, target=target_img)
> +        self.wait_ready()
> +        self.vm.hmp_qemu_io('drive0', 'write 0 512')
> +        self.complete_and_wait(wait_ready=False)
> +        self.vm.shutdown()
> +        self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img),
> +                         "Target size doesn't match source when granularity when unaligend")
> +
> +
> +if __name__ == '__main__':
> +    iotests.main(supported_fmts=['raw', 'qcow2'])
> diff --git a/tests/qemu-iotests/152.out b/tests/qemu-iotests/152.out
> new file mode 100644
> index 0000000..fbc63e6
> --- /dev/null
> +++ b/tests/qemu-iotests/152.out
> @@ -0,0 +1,5 @@
> +..
> +----------------------------------------------------------------------
> +Ran 2 tests
> +
> +OK
> diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
> index 2952b9d..822953b 100644
> --- a/tests/qemu-iotests/group
> +++ b/tests/qemu-iotests/group
> @@ -152,3 +152,4 @@
>  148 rw auto quick
>  149 rw auto sudo
>  150 rw auto quick
> +152 rw auto quick
> -- 
> 1.8.3.1
>

Reviewed-by: Jeff Cody <jcody@redhat.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity
  2016-04-20 14:32 [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Kevin Wolf
                   ` (2 preceding siblings ...)
  2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 3/3] iotests: Test case for drive-mirror with unaligned image size Kevin Wolf
@ 2016-04-20 14:51 ` Jeff Cody
  2016-04-20 14:59   ` Jeff Cody
  2016-04-21  2:12 ` Fam Zheng
  4 siblings, 1 reply; 12+ messages in thread
From: Jeff Cody @ 2016-04-20 14:51 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-block, famz, mreitz, qemu-devel

On Wed, Apr 20, 2016 at 04:32:43PM +0200, Kevin Wolf wrote:
> Taking over Fam's series as we're late for -rc3. Original cover letter:
> 
>     This fixes the bug introduced in e5b43573e28 and lately noticed by Kevin.
> 
> v2: Move the mirror_clip_sectors() to mirror_iteration. [Max]
> v3: Fix nb_clusters calculation and add a test case for it [Kevin]
> 
> Fam Zheng (3):
>   mirror: Don't extend the last sub-chunk
>   iotests: Add iotests.image_size
>   iotests: Test case for drive-mirror with unaligned image size
> 
>  block/mirror.c                | 19 ++++++++++---
>  tests/qemu-iotests/109.out    | 44 +++++++++++++++---------------
>  tests/qemu-iotests/152        | 62 +++++++++++++++++++++++++++++++++++++++++++
>  tests/qemu-iotests/152.out    |  5 ++++
>  tests/qemu-iotests/group      |  1 +
>  tests/qemu-iotests/iotests.py |  6 +++++
>  6 files changed, 111 insertions(+), 26 deletions(-)
>  create mode 100644 tests/qemu-iotests/152
>  create mode 100644 tests/qemu-iotests/152.out
> 
> -- 
> 1.8.3.1
> 

Thanks,

Applied to my block branch:

git://github.com/codyprime/qemu-kvm-jtc.git block

-Jeff

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity
  2016-04-20 14:51 ` [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Jeff Cody
@ 2016-04-20 14:59   ` Jeff Cody
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Cody @ 2016-04-20 14:59 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-block, famz, mreitz, qemu-devel

On Wed, Apr 20, 2016 at 10:51:04AM -0400, Jeff Cody wrote:
> On Wed, Apr 20, 2016 at 04:32:43PM +0200, Kevin Wolf wrote:
> > Taking over Fam's series as we're late for -rc3. Original cover letter:
> > 
> >     This fixes the bug introduced in e5b43573e28 and lately noticed by Kevin.
> > 
> > v2: Move the mirror_clip_sectors() to mirror_iteration. [Max]
> > v3: Fix nb_clusters calculation and add a test case for it [Kevin]
> > 
> > Fam Zheng (3):
> >   mirror: Don't extend the last sub-chunk
> >   iotests: Add iotests.image_size
> >   iotests: Test case for drive-mirror with unaligned image size
> > 
> >  block/mirror.c                | 19 ++++++++++---
> >  tests/qemu-iotests/109.out    | 44 +++++++++++++++---------------
> >  tests/qemu-iotests/152        | 62 +++++++++++++++++++++++++++++++++++++++++++
> >  tests/qemu-iotests/152.out    |  5 ++++
> >  tests/qemu-iotests/group      |  1 +
> >  tests/qemu-iotests/iotests.py |  6 +++++
> >  6 files changed, 111 insertions(+), 26 deletions(-)
> >  create mode 100644 tests/qemu-iotests/152
> >  create mode 100644 tests/qemu-iotests/152.out
> > 
> > -- 
> > 1.8.3.1
> > 
> 
> Thanks,
> 
> Applied to my block branch:
> 
> git://github.com/codyprime/qemu-kvm-jtc.git block
>

Per IRC discussion:

Since Kevin already has a pull request queued up and ready to go with this
series, that will be the faster path.  De-queuing this from my branch, and
Kevin will issue the pull request through his.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity
  2016-04-20 14:32 [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Kevin Wolf
                   ` (3 preceding siblings ...)
  2016-04-20 14:51 ` [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Jeff Cody
@ 2016-04-21  2:12 ` Fam Zheng
  4 siblings, 0 replies; 12+ messages in thread
From: Fam Zheng @ 2016-04-21  2:12 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-block, jcody, qemu-devel, mreitz

On Wed, 04/20 16:32, Kevin Wolf wrote:
> Taking over Fam's series as we're late for -rc3.

Much appriciated! Thanks, Kevin.


Fam

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-04-21  2:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-20 14:32 [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Kevin Wolf
2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 1/3] mirror: Don't extend the last sub-chunk Kevin Wolf
2016-04-20 14:46   ` Max Reitz
2016-04-20 14:47   ` Jeff Cody
2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 2/3] iotests: Add iotests.image_size Kevin Wolf
2016-04-20 14:48   ` Jeff Cody
2016-04-20 14:32 ` [Qemu-devel] [PATCH for-2.6 v3 3/3] iotests: Test case for drive-mirror with unaligned image size Kevin Wolf
2016-04-20 14:49   ` Max Reitz
2016-04-20 14:50   ` Jeff Cody
2016-04-20 14:51 ` [Qemu-devel] [PATCH for-2.6 v3 0/3] block: Fix drive-mirror with image size unaligned with granularity Jeff Cody
2016-04-20 14:59   ` Jeff Cody
2016-04-21  2:12 ` Fam Zheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).