From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqlzU-0003B5-Rl for qemu-devel@nongnu.org; Fri, 08 May 2015 13:23:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqlzT-0004wJ-K5 for qemu-devel@nongnu.org; Fri, 08 May 2015 13:23:12 -0400 From: Kevin Wolf Date: Fri, 8 May 2015 19:21:58 +0200 Message-Id: <1431105726-3682-27-git-send-email-kwolf@redhat.com> In-Reply-To: <1431105726-3682-1-git-send-email-kwolf@redhat.com> References: <1431105726-3682-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 26/34] block: reopen: Document option precedence and refactor accordingly 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, armbru@redhat.com, mreitz@redhat.com The interesting part of reopening an image is from which sources the effective options should be taken, i.e. which options take precedence over which other options. This patch documents the precedence that will be implemented in the following patches. It also refactors bdrv_reopen_queue(), so that the top-level reopened node is handled the same way as children are. Option/flag inheritance from the parent becomes just one item in the list and is done at the beginning of the function, similar to how the other items are/will be handled. Signed-off-by: Kevin Wolf --- block.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 8a31d62..1e5625f 100644 --- a/block.c +++ b/block.c @@ -1617,9 +1617,13 @@ typedef struct BlockReopenQueueEntry { * bs_queue, or the existing bs_queue being used. * */ -BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, - BlockDriverState *bs, - QDict *options, int flags) +static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, + BlockDriverState *bs, + QDict *options, + int flags, + const BdrvChildRole *role, + QDict *parent_options, + int parent_flags) { assert(bs != NULL); @@ -1636,6 +1640,22 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, options = qdict_new(); } + /* + * Precedence of options: + * 1. Explicitly passed in options (highest) + * 2. TODO Set in flags (only for top level) + * 3. TODO Retained from explicitly set options of bs + * 4. TODO Inherited from parent node + * 5. Retained from effective options of bs + */ + + /* Inherit from parent node */ + if (parent_options) { + assert(!flags); + flags = role->inherit_flags(parent_flags); + } + + /* Old values are used for options that aren't set yet */ old_options = qdict_clone_shallow(bs->options); qdict_join(options, old_options, false); QDECREF(old_options); @@ -1646,7 +1666,6 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, QLIST_FOREACH(child, &bs->children, next) { QDict *new_child_options; char *child_key_dot; - int child_flags; /* reopen can only change the options of block devices that were * implicitly created and inherited options. For other (referenced) @@ -1659,8 +1678,8 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, qdict_extract_subqdict(options, &new_child_options, child_key_dot); g_free(child_key_dot); - child_flags = child->role->inherit_flags(flags); - bdrv_reopen_queue(bs_queue, child->bs, new_child_options, child_flags); + bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, 0, + child->role, options, flags); } bs_entry = g_new0(BlockReopenQueueEntry, 1); @@ -1673,6 +1692,14 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, return bs_queue; } +BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, + BlockDriverState *bs, + QDict *options, int flags) +{ + return bdrv_reopen_queue_child(bs_queue, bs, options, flags, + NULL, NULL, 0); +} + /* * Reopen multiple BlockDriverStates atomically & transactionally. * -- 1.8.3.1