diff options
author | Kevin Wolf <kwolf@redhat.com> | 2018-08-14 11:52:25 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2018-08-15 12:50:39 +0200 |
commit | 86fae10c64d642256cf019e6829929fa0d259c7a (patch) | |
tree | 00b6eb0df7a2de3d00cb1ccc2b3a5d92da5688b6 /block | |
parent | dbfdf6cb3625c68d0ea84ace4a786406cf43d4f3 (diff) |
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: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/mirror.c | 5 |
1 files changed, 5 insertions, 0 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. */ |