From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9wde-0000Mm-5B for qemu-devel@nongnu.org; Fri, 18 Dec 2015 10:08:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9wdc-0004Hw-0I for qemu-devel@nongnu.org; Fri, 18 Dec 2015 10:08:10 -0500 From: Kevin Wolf Date: Fri, 18 Dec 2015 16:07:11 +0100 Message-Id: <1450451274-7472-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1450451274-7472-1-git-send-email-kwolf@redhat.com> References: <1450451274-7472-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 05/48] block: Fix reopen with semantically overlapping options List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org This fixes bdrv_reopen() calls like the following one: qemu-io -c 'open -o overlap-check.template=all /tmp/test.qcow2' \ -c 'reopen -o overlap-check=none' The approach taken so far would result in an options QDict that has both "overlap-check.template=all" and "overlap-check=none", which obviously conflicts. In this case, the old option should be overridden by the newly specified option. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Alberto Garcia --- block.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 9971976..57bf8fc 100644 --- a/block.c +++ b/block.c @@ -624,6 +624,20 @@ static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) } /** + * Combines a QDict of new block driver @options with any missing options taken + * from @old_options, so that leaving out an option defaults to its old value. + */ +static void bdrv_join_options(BlockDriverState *bs, QDict *options, + QDict *old_options) +{ + if (bs->drv && bs->drv->bdrv_join_options) { + bs->drv->bdrv_join_options(options, old_options); + } else { + qdict_join(options, old_options, false); + } +} + +/** * Set open flags for a given discard mode * * Return 0 on success, -1 if the discard mode was invalid. @@ -1663,7 +1677,7 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, } old_options = qdict_clone_shallow(bs->options); - qdict_join(options, old_options, false); + bdrv_join_options(bs, options, old_options); QDECREF(old_options); /* bdrv_open() masks this flag out */ -- 1.8.3.1