aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
Diffstat (limited to 'block.c')
-rw-r--r--block.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/block.c b/block.c
index d050c4bb58..4158a3a36f 100644
--- a/block.c
+++ b/block.c
@@ -975,6 +975,13 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
/* Apply cache mode options */
update_flags_from_options(&bs->open_flags, opts);
+
+ if (!bs->blk && (bs->open_flags & BDRV_O_CACHE_WB) == 0) {
+ error_setg(errp, "Can't set writethrough mode except for the root");
+ ret = -EINVAL;
+ goto free_and_fail;
+ }
+
bdrv_set_enable_write_cache(bs, bs->open_flags & BDRV_O_CACHE_WB);
/* Open the image, either directly or using a protocol */