Skip to contentSkip to conversation

Mirror block job fixes for 2.6.0-rc3

GIT PULL Applied Kevin Wolf 2 participants 7 messages Apr 20, 2016 Block layer

lore
Share & tools
lore
author
#1 lore raw

[Qemu-devel] [PULL 5/5] iotests: Test case for drive-mirror with unaligned image size

In reply to Kevin Wolf

From: Fam Zheng <[email protected]>

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

[ kwolf: Added test_unaligned_with_update ]

---
 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
tests/qemu-iotests/152 new file +62 -0
new file mode 100644
index 0000000..fec546d
@@ -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'])
tests/qemu-iotests/152.out new file +5 -0
new file mode 100644
index 0000000..fbc63e6
@@ -0,0 +1,5 @@
+..
+----------------------------------------------------------------------
+Ran 2 tests
+
+OK
tests/qemu-iotests/group +1 -0
index 2952b9d..822953b 100644
@@ -152,3 +152,4 @@
 148 rw auto quick
 149 rw auto sudo
 150 rw auto quick
+152 rw auto quick
Signature · 1 line
1.8.3.1

Kevin Wolf

author
#0 lore raw

The following changes since commit 4113b0532da6c448f8e458b413ebde035234d0ea:

Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2016-04-19-tag' into staging (2016-04-20 15:05:19 +0100)

are available in the git repository at:

git://repo.or.cz/qemu/kevin.git tags/for-upstream

for you to fetch changes up to 8ca92f3c069558897269e609e4f47bd6255d6339:

iotests: Test case for drive-mirror with unaligned image size (2016-04-20 16:52:55 +0200)

----------------------------------------------------------------
Mirror block job fixes for 2.6.0-rc3

----------------------------------------------------------------
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

Max Reitz (2):
block/mirror: Revive dead yielding code block/mirror: Refresh stale bitmap iterator cache

 block/mirror.c                | 45 +++++++++++++++++++++----------
 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, 127 insertions(+), 36 deletions(-)
 create mode 100644 tests/qemu-iotests/152
 create mode 100644 tests/qemu-iotests/152.out
author
#2 lore raw

[Qemu-devel] [PULL 4/5] iotests: Add iotests.image_size

From: Fam Zheng <[email protected]>

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

---
 tests/qemu-iotests/iotests.py | 6 ++++++
 1 file changed, 6 insertions(+)
tests/qemu-iotests/iotests.py +6 -0
index d9ef60e..56f988a 100644
@@ -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)
Signature · 1 line
1.8.3.1
author
#3 lore raw

[Qemu-devel] [PULL 1/5] block/mirror: Revive dead yielding code

In reply to Kevin Wolf

From: Max Reitz <[email protected]>

mirror_iteration() is supposed to wait if the current chunk is subject to a still in-flight mirroring operation. However, it mixed checking this conflict situation with checking the dirty status of a chunk. A simplification for the latter condition (the first chunk encountered is always dirty) led to neglecting the former: We just skip the first chunk and thus never test whether it conflicts with an in-flight operation.

To fix this, pull out the code which waits for in-flight operations on the first chunk of the range to be mirrored to settle.

---
 block/mirror.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
block/mirror.c +12 -11
index c2cfc1a..2714a77 100644
@@ -298,7 +298,7 @@ static void mirror_do_zero_or_discard(MirrorBlockJob *s,
 static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
 {
     BlockDriverState *source = s->common.bs;
-    int64_t sector_num;
+    int64_t sector_num, first_chunk;
     uint64_t delay_ns = 0;
     /* At least the first dirty chunk is mirrored in one iteration. */
     int nb_chunks = 1;
@@ -313,6 +313,12 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
         assert(sector_num >= 0);
     }
 
+    first_chunk = sector_num / sectors_per_chunk;
+    while (test_bit(first_chunk, s->in_flight_bitmap)) {
+        trace_mirror_yield_in_flight(s, first_chunk, s->in_flight);
+        mirror_wait_for_io(s);
+    }
+
     /* Find the number of consective dirty chunks following the first dirty
      * one, and wait for in flight requests in them. */
     while (nb_chunks * sectors_per_chunk < (s->buf_size >> BDRV_SECTOR_BITS)) {
@@ -324,17 +330,12 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
             break;
         }
         if (test_bit(next_chunk, s->in_flight_bitmap)) {
-            if (nb_chunks > 0) {
-                break;
-            }
-            trace_mirror_yield_in_flight(s, next_sector, s->in_flight);
-            mirror_wait_for_io(s);
-            /* Now retry.  */
-        } else {
-            hbitmap_next = hbitmap_iter_next(&s->hbi);
-            assert(hbitmap_next == next_sector);
-            nb_chunks++;
+            break;
         }
+
+        hbitmap_next = hbitmap_iter_next(&s->hbi);
+        assert(hbitmap_next == next_sector);
+        nb_chunks++;
     }
 
     /* Clear dirty bits before querying the block status, because
Signature · 1 line
1.8.3.1
author
#4 lore raw

[Qemu-devel] [PULL 3/5] mirror: Don't extend the last sub-chunk

In reply to Kevin Wolf

From: Fam Zheng <[email protected]>

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 ]

---
 block/mirror.c             | 19 +++++++++++++++----
 tests/qemu-iotests/109.out | 44 ++++++++++++++++++++++----------------------
 2 files changed, 37 insertions(+), 26 deletions(-)
block/mirror.c +15 -4
index 9df1fae..d56e30e 100644
@@ -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;
tests/qemu-iotests/109.out +22 -22

120 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#5 lore raw

[Qemu-devel] [PULL 2/5] block/mirror: Refresh stale bitmap iterator cache

In reply to Kevin Wolf

From: Max Reitz <[email protected]>

If the drive's dirty bitmap is dirtied while the mirror operation is running, the cache of the iterator used by the mirror code may become stale and not contain all dirty bits.

This only becomes an issue if we are looking for contiguously dirty chunks on the drive. In that case, we can easily detect the discrepancy and just refresh the iterator if one occurs.

---
 block/mirror.c | 5 +++++
 1 file changed, 5 insertions(+)
block/mirror.c +5 -0
index 2714a77..9df1fae 100644
@@ -334,6 +334,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
         }
 
         hbitmap_next = hbitmap_iter_next(&s->hbi);
+        if (hbitmap_next > next_sector || hbitmap_next < 0) {
+            /* The bitmap iterator's cache is stale, refresh it */
+            bdrv_set_dirty_iter(&s->hbi, next_sector);
+            hbitmap_next = hbitmap_iter_next(&s->hbi);
+        }
         assert(hbitmap_next == next_sector);
         nb_chunks++;
     }
Signature · 1 line
1.8.3.1
#6 lore raw
In reply to Kevin Wolf
Quoted 7 lines · Kevin Wolf

The following changes since commit 4113b0532da6c448f8e458b413ebde035234d0ea:

Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2016-04-19-tag' into staging (2016-04-20 15:05:19 +0100)

are available in the git repository at:

Quoted 8 lines

git://repo.or.cz/qemu/kevin.git tags/for-upstream

for you to fetch changes up to 8ca92f3c069558897269e609e4f47bd6255d6339:

iotests: Test case for drive-mirror with unaligned image size (2016-04-20 16:52:55 +0200)

----------------------------------------------------------------
Mirror block job fixes for 2.6.0-rc3

Applied, thanks.

-- PMM