summaryrefslogtreecommitdiffstats
path: root/blockdev.c
diff options
context:
space:
mode:
authorMax Reitz2016-06-10 20:57:47 +0200
committerMax Reitz2016-06-16 15:20:37 +0200
commit274fccee2bf63702b34e3923b1e50a49147a7918 (patch)
tree782a35d358d03ba3970b0894c3f1fd60a7d3f940 /blockdev.c
parentblock: Allow replacement of a BDS by its overlay (diff)
downloadqemu-274fccee2bf63702b34e3923b1e50a49147a7918.tar.gz
qemu-274fccee2bf63702b34e3923b1e50a49147a7918.tar.xz
qemu-274fccee2bf63702b34e3923b1e50a49147a7918.zip
block/mirror: Fix target backing BDS
Currently, we are trying to move the backing BDS from the source to the target in bdrv_replace_in_backing_chain() which is called from mirror_exit(). However, mirror_complete() already tries to open the target's backing chain with a call to bdrv_open_backing_file(). First, we should only set the target's backing BDS once. Second, the mirroring block job has a better idea of what to set it to than the generic code in bdrv_replace_in_backing_chain() (in fact, the latter's conditions on when to move the backing BDS from source to target are not really correct). Therefore, remove that code from bdrv_replace_in_backing_chain() and leave it to mirror_complete(). Depending on what kind of mirroring is performed, we furthermore want to use different strategies to open the target's backing chain: - If blockdev-mirror is used, we can assume the user made sure that the target already has the correct backing chain. In particular, we should not try to open a backing file if the target does not have any yet. - If drive-mirror with mode=absolute-paths is used, we can and should reuse the already existing chain of nodes that the source BDS is in. In case of sync=full, no backing BDS is required; with sync=top, we just link the source's backing BDS to the target, and with sync=none, we use the source BDS as the target's backing BDS. We should not try to open these backing files anew because this would lead to two BDSs existing per physical file in the backing chain, and we would like to avoid such concurrent access. - If drive-mirror with mode=existing is used, we have to use the information provided in the physical image file which means opening the target's backing chain completely anew, just as it has been done already. If the target's backing chain shares images with the source, this may lead to multiple BDSs per physical image file. But since we cannot reliably ascertain this case, there is nothing we can do about it. Signed-off-by: Max Reitz <mreitz@redhat.com> Message-id: 20160610185750.30956-3-mreitz@redhat.com Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/blockdev.c b/blockdev.c
index 1d498c7b19..c9a0068cd6 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3426,6 +3426,7 @@ static void blockdev_mirror_common(BlockDriverState *bs,
BlockDriverState *target,
bool has_replaces, const char *replaces,
enum MirrorSyncMode sync,
+ BlockMirrorBackingMode backing_mode,
bool has_speed, int64_t speed,
bool has_granularity, uint32_t granularity,
bool has_buf_size, int64_t buf_size,
@@ -3483,7 +3484,7 @@ static void blockdev_mirror_common(BlockDriverState *bs,
*/
mirror_start(bs, target,
has_replaces ? replaces : NULL,
- speed, granularity, buf_size, sync,
+ speed, granularity, buf_size, sync, backing_mode,
on_source_error, on_target_error, unmap,
block_job_cb, bs, errp);
}
@@ -3506,6 +3507,7 @@ void qmp_drive_mirror(const char *device, const char *target,
BlockBackend *blk;
BlockDriverState *source, *target_bs;
AioContext *aio_context;
+ BlockMirrorBackingMode backing_mode;
Error *local_err = NULL;
QDict *options = NULL;
int flags;
@@ -3579,6 +3581,12 @@ void qmp_drive_mirror(const char *device, const char *target,
}
}
+ if (mode == NEW_IMAGE_MODE_ABSOLUTE_PATHS) {
+ backing_mode = MIRROR_SOURCE_BACKING_CHAIN;
+ } else {
+ backing_mode = MIRROR_OPEN_BACKING_CHAIN;
+ }
+
if ((sync == MIRROR_SYNC_MODE_FULL || !source)
&& mode != NEW_IMAGE_MODE_EXISTING)
{
@@ -3627,7 +3635,7 @@ void qmp_drive_mirror(const char *device, const char *target,
bdrv_set_aio_context(target_bs, aio_context);
blockdev_mirror_common(bs, target_bs,
- has_replaces, replaces, sync,
+ has_replaces, replaces, sync, backing_mode,
has_speed, speed,
has_granularity, granularity,
has_buf_size, buf_size,
@@ -3659,6 +3667,7 @@ void qmp_blockdev_mirror(const char *device, const char *target,
BlockBackend *blk;
BlockDriverState *target_bs;
AioContext *aio_context;
+ BlockMirrorBackingMode backing_mode = MIRROR_LEAVE_BACKING_CHAIN;
Error *local_err = NULL;
blk = blk_by_name(device);
@@ -3684,7 +3693,7 @@ void qmp_blockdev_mirror(const char *device, const char *target,
bdrv_set_aio_context(target_bs, aio_context);
blockdev_mirror_common(bs, target_bs,
- has_replaces, replaces, sync,
+ has_replaces, replaces, sync, backing_mode,
has_speed, speed,
has_granularity, granularity,
has_buf_size, buf_size,