[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 12/21] mirror: Fail gracefully for source == target
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 12/21] mirror: Fail gracefully for source == target |
Date: |
Wed, 15 Aug 2018 14:55:28 +0200 |
blockdev-mirror with the same node for source and target segfaults
today: A node is in its own backing chain, so mirror_start_job() decides
that this is an active commit. When adding the intermediate nodes with
block_job_add_bdrv(), it starts the iteration through the subchain with
the backing file of source, though, so it never reaches target and
instead runs into NULL at the base.
While we could fix that by starting with source itself, there is no
point in allowing mirroring a node into itself and I wouldn't be
surprised if this caused more problems later.
So just check for this scenario and error out.
Cc: address@hidden
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
block/mirror.c | 5 +++++
tests/qemu-iotests/041 | 6 ++++++
tests/qemu-iotests/041.out | 4 ++--
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index b48c3f8cf5..dd5ca02b09 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -1499,6 +1499,11 @@ static void mirror_start_job(const char *job_id,
BlockDriverState *bs,
buf_size = DEFAULT_MIRROR_BUF_SIZE;
}
+ if (bs == target) {
+ error_setg(errp, "Can't mirror node into itself");
+ return;
+ }
+
/* In the case of active commit, add dummy driver to provide consistent
* reads on the top, while disabling it in the intermediate nodes, and make
* the backing chain writable. */
diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index c20ac7da87..9336ab6ff5 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -234,6 +234,12 @@ class TestSingleBlockdev(TestSingleDrive):
result = self.vm.qmp("blockdev-add", **args)
self.assert_qmp(result, 'return', {})
+ def test_mirror_to_self(self):
+ result = self.vm.qmp(self.qmp_cmd, job_id='job0',
+ device=self.qmp_target, sync='full',
+ target=self.qmp_target)
+ self.assert_qmp(result, 'error/class', 'GenericError')
+
test_large_cluster = None
test_image_not_found = None
test_small_buffer2 = None
diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
index c28b392b87..e071d0b261 100644
--- a/tests/qemu-iotests/041.out
+++ b/tests/qemu-iotests/041.out
@@ -1,5 +1,5 @@
-.....................................................................................
+........................................................................................
----------------------------------------------------------------------
-Ran 85 tests
+Ran 88 tests
OK
--
2.13.6
- [Qemu-block] [PULL 00/21] Block layer patches, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 03/21] throttle-groups: Skip the round-robin if a member is being drained, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 01/21] block/qapi: Fix memory leak in qmp_query_blockstats(), Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 04/21] qemu-iotests: Update 093 to improve the draining test, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 02/21] qemu-iotests: Test removing a throttle group member with a pending timer, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 05/21] throttle-groups: Don't allow timers without throttled requests, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 06/21] luks: Allow share-rw=on, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 07/21] block: Remove deprecated -drive geometry options, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 12/21] mirror: Fail gracefully for source == target,
Kevin Wolf <=
- [Qemu-block] [PULL 08/21] block: Remove deprecated -drive option addr, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 09/21] block: Remove deprecated -drive option serial, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 13/21] qemu-img: fix regression copying secrets during convert, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 15/21] block: drop empty .bdrv_close handlers, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 16/21] qdict: Make qdict_extract_subqdict() accept dst = NULL, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 14/21] block: make .bdrv_close optional, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 10/21] block: Remove dead deprecation warning code, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 18/21] block: Simplify bdrv_reopen_abort(), Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 21/21] qapi: block: Remove mentions of error types which were removed, Kevin Wolf, 2018/08/15
- [Qemu-block] [PULL 20/21] block: Simplify append_open_options(), Kevin Wolf, 2018/08/15