提交 1662d4d4 编写于 作者: K Kevin Wolf 提交者: Michael Roth

mirror: Fail gracefully for source == target

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: qemu-stable@nongnu.org
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
(cherry picked from commit 86fae10c)
Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
上级 c89985ba
......@@ -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. */
......
......@@ -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
......
.....................................................................................
........................................................................................
----------------------------------------------------------------------
Ran 85 tests
Ran 88 tests
OK
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册