From 0ebd24e0a203cf2852c310b59fbe050190dc6c8c Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 19 Sep 2013 15:12:18 +0200 Subject: blockdev: Don't disable COR automatically with blockdev-add If a read-only device is configured with copy-on-read=on, the old code only prints a warning and automatically disables copy on read. Make it a real error for blockdev-add. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'block.c') diff --git a/block.c b/block.c index 84c0eac671..fd05a8008a 100644 --- a/block.c +++ b/block.c @@ -778,8 +778,13 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, } assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */ - if (!bs->read_only && (flags & BDRV_O_COPY_ON_READ)) { - bdrv_enable_copy_on_read(bs); + if (flags & BDRV_O_COPY_ON_READ) { + if (!bs->read_only) { + bdrv_enable_copy_on_read(bs); + } else { + error_setg(errp, "Can't use copy-on-read on read-only device"); + return -EINVAL; + } } if (filename != NULL) { -- cgit v1.2.1