From patchwork Thu Sep 15 14:53:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 670469 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sZhTQ1gVDz9s2Q for ; Fri, 16 Sep 2016 01:02:02 +1000 (AEST) Received: from localhost ([::1]:35331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkYAp-0005T2-P8 for incoming@patchwork.ozlabs.org; Thu, 15 Sep 2016 11:01:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkY30-0006eS-CF for qemu-devel@nongnu.org; Thu, 15 Sep 2016 10:53:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkY2x-0003TD-4a for qemu-devel@nongnu.org; Thu, 15 Sep 2016 10:53:53 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:61950 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkY2w-0003Q9-SL; Thu, 15 Sep 2016 10:53:51 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2BHAwBotdpX/5tjdVtcHAYMgzwBAQEBAR5XfKMmAQEBAQEBBQGBEgGPWYIugg+CAxyGAgKBWzgUAQIBAQEBAQEBXieEYgIEJ1IQPxI8GxmITgHBcgEwhWmCSYdahRAFjyGKR4YlgwKGMoI8jSlIkBEeNoIugQKBOm2HAQEBAQ X-IPAS-Result: A2BHAwBotdpX/5tjdVtcHAYMgzwBAQEBAR5XfKMmAQEBAQEBBQGBEgGPWYIugg+CAxyGAgKBWzgUAQIBAQEBAQEBXieEYgIEJ1IQPxI8GxmITgHBcgEwhWmCSYdahRAFjyGKR4YlgwKGMoI8jSlIkBEeNoIugQKBOm2HAQEBAQ X-IronPort-AV: E=Sophos;i="5.30,339,1470693600"; d="scan'208";a="189830359" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 15 Sep 2016 16:53:24 +0200 Received: from a88-114-146-42.elisa-laajakaista.fi ([88.114.146.42] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim) id 1bkY2V-0007dJ-MU; Thu, 15 Sep 2016 16:53:24 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bkY2I-00009d-8V; Thu, 15 Sep 2016 17:53:10 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 15 Sep 2016 17:53:03 +0300 Message-Id: <92169437c4935cb07f407256663c0f65c6eda26a.1473950317.git.berto@igalia.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.51.32.191 Subject: [Qemu-devel] [PATCH v2 5/7] block: Don't queue the same BDS twice in bdrv_reopen_queue_child() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" bdrv_reopen_queue_child() assumes that a BlockDriverState is never added twice to BlockReopenQueue. That's however not the case: commit_start() adds 'base' (and its children) to a new reopen queue, and then 'overlay_bs' (and its children, which include 'base') to the same queue. The effect of this is that the first set of options is ignored and overriden by the second. We fixed this by swapping the order in which both BDSs were added to the queue in 3db2bd5508c86a1605258bc77c9672d93b5c350e. This patch checks if a BDS is already in the reopen queue and keeps its options. Signed-off-by: Alberto Garcia Reviewed-by: Kevin Wolf --- block.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 663104e..1e9d66b 100644 --- a/block.c +++ b/block.c @@ -1877,6 +1877,13 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, options = qdict_new(); } + /* Check if this BlockDriverState is already in the queue */ + QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { + if (bs == bs_entry->state.bs) { + break; + } + } + /* * Precedence of options: * 1. Explicitly passed in options (highest) @@ -1897,7 +1904,11 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, } /* Old explicitly set values (don't overwrite by inherited value) */ - old_options = qdict_clone_shallow(bs->explicit_options); + if (bs_entry) { + old_options = qdict_clone_shallow(bs_entry->state.explicit_options); + } else { + old_options = qdict_clone_shallow(bs->explicit_options); + } bdrv_join_options(bs, options, old_options); QDECREF(old_options); @@ -1936,8 +1947,13 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, child->role, options, flags); } - bs_entry = g_new0(BlockReopenQueueEntry, 1); - QSIMPLEQ_INSERT_TAIL(bs_queue, bs_entry, entry); + if (!bs_entry) { + bs_entry = g_new0(BlockReopenQueueEntry, 1); + QSIMPLEQ_INSERT_TAIL(bs_queue, bs_entry, entry); + } else { + QDECREF(bs_entry->state.options); + QDECREF(bs_entry->state.explicit_options); + } bs_entry->state.bs = bs; bs_entry->state.options = options;