aboutsummaryrefslogtreecommitdiff
path: root/blockdev.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2016-03-02 12:16:44 +0100
committerKevin Wolf <kwolf@redhat.com>2016-03-14 16:46:43 +0100
commitf86b8b584b114d68036bf576057f51caec7b94ba (patch)
tree3b4395f4a1a9b11831d59aab29a031c6f645ff1d /blockdev.c
parent924e8a2bbc7cc62b3996efe9a2a460f541c04520 (diff)
downloadqemu-f86b8b584b114d68036bf576057f51caec7b94ba.zip
qemu-f86b8b584b114d68036bf576057f51caec7b94ba.tar.gz
qemu-f86b8b584b114d68036bf576057f51caec7b94ba.tar.bz2
blockdev: Snapshotting must not open second instance of old top
Calling bdrv_img_create() with a size of -1 means that it determines the size automatically by opening the backing file. However, in the case of live snapshots, the backing file is already opened and we must avoid opening the same image twice at the same time. Apart from that, just getting the size from the already existing BDS is a lot less overhead than opening a new instance. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Jeff Cody <jcody@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/blockdev.c b/blockdev.c
index 0f20c65..e1c1540 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1732,10 +1732,15 @@ static void external_snapshot_prepare(BlkActionState *common,
/* create new image w/backing file */
mode = s->has_mode ? s->mode : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
if (mode != NEW_IMAGE_MODE_EXISTING) {
+ int64_t size = bdrv_getlength(state->old_bs);
+ if (size < 0) {
+ error_setg_errno(errp, -size, "bdrv_getlength failed");
+ return;
+ }
bdrv_img_create(new_image_file, format,
state->old_bs->filename,
state->old_bs->drv->format_name,
- NULL, -1, flags, &local_err, false);
+ NULL, size, flags, &local_err, false);
if (local_err) {
error_propagate(errp, local_err);
return;