From patchwork Wed Mar 6 18:11:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 10841569 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 341261575 for ; Wed, 6 Mar 2019 18:18:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EF5E2E6F8 for ; Wed, 6 Mar 2019 18:18:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 103A82E7D9; Wed, 6 Mar 2019 18:18:47 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 79CF52E6F8 for ; Wed, 6 Mar 2019 18:18:46 +0000 (UTC) Received: from localhost ([127.0.0.1]:37261 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1b7t-0001AJ-HC for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Mar 2019 13:18:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1b2H-0004mX-Hz for qemu-devel@nongnu.org; Wed, 06 Mar 2019 13:12:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1b2C-0006TL-Mm for qemu-devel@nongnu.org; Wed, 06 Mar 2019 13:12:57 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:59316) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1b1x-0005fy-Ng; Wed, 06 Mar 2019 13:12:43 -0500 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=2w/dfCXO56I+543st7s2VP1+ZUBY92zlgsV00GI9R4o=; b=JU23kt3tKuJewbgZVKuAen5vQ5cDIOPUWDbBoNU2u/V06q8YOAM+AaBUYM+8Kwu0GquERUFbjkRFn3ImvI5S/c8Rq/6CwgZplyjy0sgSrEgcLx/Y6Ys8Ly2VudwoQIva5nj5RIGKSMYYvgRPJAnFqwzE4wmGFr3MmEwJuhtf3Xq1O/NCf3iH5VPYCoq6KLT/AMReQCzxTLSztaP8iu3cP7Mcn7pTCvJJIsUxynWBnded6fkvjq8xwx3IiI1Zxm9aE2jBdZ9NENXd488SXPPD93C7EwJKPBucR8cdAtJ1JUd2C+s5M20YaHnlxRToVqgW4vLIjOOQ8E50A631yzV2sw==; Received: from 87-92-21-153.bb.dnainternet.fi ([87.92.21.153] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1h1b10-0004r5-Te; Wed, 06 Mar 2019 19:11:39 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1h1b0m-0005Oh-GY; Wed, 06 Mar 2019 20:11:24 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 20:11:12 +0200 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 v2 12/13] block: Add an 'x-blockdev-reopen' QMP command 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 This command allows reopening an arbitrary BlockDriverState with a new set of options. Some options (e.g node-name) cannot be changed and some block drivers don't allow reopening, but otherwise this command is modelled after 'blockdev-add' and the state of the reopened BlockDriverState should generally be the same as if it had just been added by 'blockdev-add' with the same set of options. One notable exception is the 'backing' option: 'x-blockdev-reopen' requires that it is always present unless the BlockDriverState in question doesn't have a current or default backing file. This command allows reconfiguring the graph by using the appropriate options to change the children of a node. At the moment it's possible to change a backing file by setting the 'backing' option to the name of the new node, but it should also be possible to add a similar functionality to other block drivers (e.g. Quorum, blkverify). Although the API is unlikely to change, this command is marked experimental for the time being so there's room to see if the semantics need changes. Signed-off-by: Alberto Garcia --- blockdev.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/blockdev.c b/blockdev.c index 7e6bf9955c..42510a959a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4285,6 +4285,53 @@ fail: visit_free(v); } +void qmp_x_blockdev_reopen(BlockdevOptions *options, Error **errp) +{ + BlockDriverState *bs; + AioContext *ctx; + QObject *obj; + Visitor *v = qobject_output_visitor_new(&obj); + Error *local_err = NULL; + BlockReopenQueue *queue; + QDict *qdict; + + /* Check for the selected node name */ + if (!options->has_node_name) { + error_setg(errp, "Node name not specified"); + goto fail; + } + + bs = bdrv_find_node(options->node_name); + if (!bs) { + error_setg(errp, "Cannot find node named '%s'", options->node_name); + goto fail; + } + + /* Put all options in a QDict and flatten it */ + visit_type_BlockdevOptions(v, NULL, &options, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto fail; + } + + visit_complete(v, &obj); + qdict = qobject_to(QDict, obj); + + qdict_flatten(qdict); + + /* Perform the reopen operation */ + ctx = bdrv_get_aio_context(bs); + aio_context_acquire(ctx); + bdrv_subtree_drained_begin(bs); + queue = bdrv_reopen_queue(NULL, bs, qdict, false); + bdrv_reopen_multiple(queue, errp); + bdrv_subtree_drained_end(bs); + aio_context_release(ctx); + +fail: + visit_free(v); +} + void qmp_blockdev_del(const char *node_name, Error **errp) { AioContext *aio_context; diff --git a/qapi/block-core.json b/qapi/block-core.json index 2b8afbb924..05577a22f6 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3982,6 +3982,48 @@ { 'command': 'blockdev-add', 'data': 'BlockdevOptions', 'boxed': true } ## +# @x-blockdev-reopen: +# +# Reopens a block device using the given set of options. Any option +# not specified will be reset to its default value regardless of its +# previous status. If an option cannot be changed or a particular +# driver does not support reopening then the command will return an +# error. +# +# The top-level @node-name option (from BlockdevOptions) must be +# specified and is used to select the block device to be reopened. +# Other @node-name options must be either omitted or set to the +# current name of the appropriate node. This command won't change any +# node name and any attempt to do it will result in an error. +# +# In the case of options that refer to child nodes, the behavior of +# this command depends on the value: +# +# 1) A set of options (BlockdevOptions): the child is reopened with +# the specified set of options. +# +# 2) A reference to the current child: the child is reopened using +# its existing set of options. +# +# 3) A reference to a different node: the current child is replaced +# with the specified one. +# +# 4) NULL: the current child (if any) is detached. +# +# Options (1) and (2) are supported in all cases, but at the moment +# only @backing allows replacing or detaching an existing child. +# +# Unlike with blockdev-add, the @backing option must always be present +# unless the node being reopened does not have a backing file and its +# image does not have a default backing file name as part of its +# metadata. +# +# Since: 4.0 +## +{ 'command': 'x-blockdev-reopen', + 'data': 'BlockdevOptions', 'boxed': true } + +## # @blockdev-del: # # Deletes a block device that has been added using blockdev-add.