summaryrefslogtreecommitdiff
path: root/blockdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/blockdev.c b/blockdev.c
index 91a21eb0b8..d8e3e31975 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1773,6 +1773,12 @@ static void external_snapshot_prepare(BlkActionState *common,
flags |= BDRV_O_NO_BACKING;
}
+ /* There is no BB attached during bdrv_open(), so we can't set a
+ * writethrough mode. bdrv_append() will swap the WCE setting so that the
+ * backing file becomes unconditionally writeback (which is what backing
+ * files should always be) and the new overlay gets the original setting. */
+ flags |= BDRV_O_CACHE_WB;
+
assert(state->new_bs == NULL);
ret = bdrv_open(&state->new_bs, new_image_file, snapshot_ref, options,
flags, errp);
@@ -2517,6 +2523,7 @@ void qmp_blockdev_change_medium(const char *device, const char *filename,
BlockBackend *blk;
BlockDriverState *medium_bs = NULL;
int bdrv_flags, ret;
+ bool writethrough;
QDict *options = NULL;
Error *err = NULL;
@@ -2535,6 +2542,12 @@ void qmp_blockdev_change_medium(const char *device, const char *filename,
bdrv_flags &= ~(BDRV_O_TEMPORARY | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING |
BDRV_O_PROTOCOL);
+ /* Must open the image in writeback mode as long as no BlockBackend is
+ * attached. The right mode can be set as the final step after changing the
+ * medium. */
+ writethrough = !(bdrv_flags & BDRV_O_CACHE_WB);
+ bdrv_flags |= BDRV_O_CACHE_WB;
+
if (!has_read_only) {
read_only = BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN;
}
@@ -2592,6 +2605,8 @@ void qmp_blockdev_change_medium(const char *device, const char *filename,
goto fail;
}
+ bdrv_set_enable_write_cache(medium_bs, !writethrough);
+
qmp_blockdev_close_tray(device, errp);
fail:
@@ -3217,7 +3232,7 @@ static void do_drive_backup(const char *device, const char *target,
goto out;
}
- flags = bs->open_flags | BDRV_O_RDWR;
+ flags = bs->open_flags | BDRV_O_CACHE_WB | BDRV_O_RDWR;
/* See if we have a backing HD we can use to create our new image
* on top of. */
@@ -3512,7 +3527,7 @@ void qmp_drive_mirror(const char *device, const char *target,
format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;
}
- flags = bs->open_flags | BDRV_O_RDWR;
+ flags = bs->open_flags | BDRV_O_CACHE_WB | BDRV_O_RDWR;
source = backing_bs(bs);
if (!source && sync == MIRROR_SYNC_MODE_TOP) {
sync = MIRROR_SYNC_MODE_FULL;