From patchwork Sun Aug 26 14:09:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 10576277 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D1591803 for ; Sun, 26 Aug 2018 14:15:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4802E292C4 for ; Sun, 26 Aug 2018 14:15:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C0F329323; Sun, 26 Aug 2018 14:15:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D88362930E for ; Sun, 26 Aug 2018 14:15:23 +0000 (UTC) Received: from localhost ([::1]:49231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftvp5-0001Ye-5B for patchwork-qemu-devel@patchwork.kernel.org; Sun, 26 Aug 2018 10:15:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftvl9-00082i-Eu for qemu-devel@nongnu.org; Sun, 26 Aug 2018 10:11:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftvl6-0006zR-E1 for qemu-devel@nongnu.org; Sun, 26 Aug 2018 10:11:19 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:59585) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ftvl4-0006U9-2I; Sun, 26 Aug 2018 10:11:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ACMtwbSt2i1Xmj4oR28oj+uWW/Ab0UCbj/0GhWb/EC4=; b=nGrm3cRT1NDBkgJFu3RlXZW9xHIPrzKqh78EQicOBDXVvdG1/tXNE3buOMoWZmoGr1tyP6dKwU0fL8ChJ9fYQe7XU3THlNbG9VPkcla0TuwI8iEy4NovheRBCe/yw7pDKkmPq64KMXZSltIIBOeonXoVCj63Qg7IVmbXFlqd2bLIrhbVj/ILAWJDRsixCxBshCS2juXhUkmqww+N7MS+7eJOhwDAGYsvrXjGxiK4cOFAMSBsR11EtIr+vvaBSyu+t47NAfdTgDu+yCN1hbdYJXIvR49sVVwA7tBijE0oVv6dPrYNgy6+tqgmN4EB8iUEQOMqgj0W3+zRt5p/TzyvWg==; Received: from 85-76-74-234-nat.elisa-mobile.fi ([85.76.74.234] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ftvkQ-0004AI-JV; Sun, 26 Aug 2018 16:10:34 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ftvkB-0004mO-7l; Sun, 26 Aug 2018 17:10:19 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Sun, 26 Aug 2018 17:09:36 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 5/9] block: Allow child references on reopen 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In the previous patches we removed all child references from bs->{options,explicit_options} because keeping them is useless and wrong. Because of this, any attempt to reopen a BlockDriverState using a child reference as one of its options would result in a failure, because bdrv_reopen_prepare() would detect that there's a new option (the child reference) that wasn't present in bs->options. But passing child references on reopen can be useful. It's a way to specify a BDS's child without having to pass recursively all of the child's options, and if the reference points to a different BDS then this can allow us to replace the child. However, replacing the child is something that needs to be implemented case by case and only when it makes sense. For now, this patch allows passing a child reference as long as it points to the current child of the BlockDriverState. It's also important to remember that, as a consequence of the previous patches, this child reference will be removed from bs->{options,explicit_options} after the reopening has been completed. Signed-off-by: Alberto Garcia --- block.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/block.c b/block.c index 92afb3dcce..804d557608 100644 --- a/block.c +++ b/block.c @@ -3241,6 +3241,25 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, QObject *new = entry->value; QObject *old = qdict_get(reopen_state->bs->options, entry->key); + /* We allow child references 'child_name'='value' + * if 'child_name' is an existing child of the BDS + * and 'value' is the child's node name (a string). */ + if (qobject_type(new) == QTYPE_QSTRING) { + BdrvChild *child; + QLIST_FOREACH(child, &reopen_state->bs->children, next) { + if (!strcmp(child->name, entry->key)) { + break; + } + } + + if (child) { + const char *str = qobject_get_try_str(new); + if (!strcmp(child->bs->node_name, str)) { + continue; /* Found child with this name, skip option */ + } + } + } + /* * TODO: When using -drive to specify blockdev options, all values * will be strings; however, when using -blockdev, blockdev-add or