From 73ac451f3435910433900d7d01a1cac6ccb401e6 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 14 Mar 2016 15:46:03 +0100 Subject: block: Reject writethrough mode except at the root Writethrough mode is going to become a BlockBackend feature rather than a BDS one, so forbid it in places where we won't be able to support it when the code finally matches the envisioned design. We only allowed setting the cache mode of non-root nodes after the 2.5 release, so we're still free to make this change. The target of block jobs is now always opened in a writeback mode because it doesn't have a BlockBackend attached. This makes more sense anyway because block jobs know when to flush. If the graph is modified on job completion, the original cache mode moves to the new root, so for the guest device writethough always stays enabled if it was configured this way. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'block.c') 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 */ -- cgit v1.2.3