From patchwork Wed Jun 25 19:43:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 364135 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DDE5B14009E for ; Thu, 26 Jun 2014 05:46:08 +1000 (EST) Received: from localhost ([::1]:40729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wzt8x-0002rV-5y for incoming@patchwork.ozlabs.org; Wed, 25 Jun 2014 15:46:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wzt6S-0000lb-SD for qemu-devel@nongnu.org; Wed, 25 Jun 2014 15:43:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wzt6L-00021B-C8 for qemu-devel@nongnu.org; Wed, 25 Jun 2014 15:43:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wzt6K-00020x-T3 for qemu-devel@nongnu.org; Wed, 25 Jun 2014 15:43:25 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5PJhNub023346 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Jun 2014 15:43:23 -0400 Received: from localhost ([10.3.112.8]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5PJhL3G011713 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Wed, 25 Jun 2014 15:43:22 -0400 From: Jeff Cody To: qemu-devel@nongnu.org Date: Wed, 25 Jun 2014 15:43:13 -0400 Message-Id: <6edf2f721e66ce1186973aaaceab29f61771bf62.1403723862.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, benoit.canet@irqsave.net, pkrempa@redhat.com, famz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v7 for 2.1 2/4] block: Accept node-name arguments for block-commit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This modifies the block operation block-commit so that it will accept node-name arguments for either 'top' or 'base' BDS. The filename and node-name are mutually exclusive to each other; i.e.: "top" and "top-node-name" are mutually exclusive (enforced) "base" and "base-node-name" are mutually exclusive (enforced) The preferred and recommended method now of using block-commit is to specify the BDS to operate on via their node-name arguments. This also adds an explicit check that base_bs is in the chain of top_bs, because if they are referenced by their unique node-name arguments, the discovery process does not intrinsically verify they are in the same chain. Reviewed-by: Eric Blake Signed-off-by: Jeff Cody --- blockdev.c | 54 ++++++++++++++++++++++++++++++++++++++++++++-------- qapi/block-core.json | 40 ++++++++++++++++++++++++++++---------- qmp-commands.hx | 31 ++++++++++++++++++++++-------- 3 files changed, 99 insertions(+), 26 deletions(-) diff --git a/blockdev.c b/blockdev.c index c2fafd1..cb50c18 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1924,13 +1924,16 @@ void qmp_block_stream(const char *device, void qmp_block_commit(const char *device, bool has_base, const char *base, + bool has_base_node_name, const char *base_node_name, bool has_top, const char *top, + bool has_top_node_name, const char *top_node_name, bool has_backing_file, const char *backing_file, bool has_speed, int64_t speed, Error **errp) { - BlockDriverState *bs; - BlockDriverState *base_bs, *top_bs; + BlockDriverState *bs = NULL; + BlockDriverState *base_bs = NULL; + BlockDriverState *top_bs = NULL; Error *local_err = NULL; /* This will be part of the QMP command, if/when the * BlockdevOnError change for blkmirror makes it in @@ -1944,6 +1947,16 @@ void qmp_block_commit(const char *device, /* drain all i/o before commits */ bdrv_drain_all(); + /* argument combination validation */ + if (has_base && has_base_node_name) { + error_setg(errp, "'base' and 'base-node-name' are mutually exclusive"); + return; + } + if (has_top && has_top_node_name) { + error_setg(errp, "'top' and 'top-node-name' are mutually exclusive"); + return; + } + /* Important Note: * libvirt relies on the DeviceNotFound error class in order to probe for * live commit feature versions; for this to work, we must make sure to @@ -1955,14 +1968,16 @@ void qmp_block_commit(const char *device, return; } - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT, errp)) { - return; - } - /* default top_bs is the active layer */ top_bs = bs; - if (has_top && top) { + if (has_top_node_name) { + top_bs = bdrv_lookup_bs(NULL, top_node_name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } else if (has_top && top) { if (strcmp(bs->filename, top) != 0) { top_bs = bdrv_find_backing_image(bs, top); } @@ -1973,7 +1988,13 @@ void qmp_block_commit(const char *device, return; } - if (has_base && base) { + if (has_base_node_name) { + base_bs = bdrv_lookup_bs(NULL, base_node_name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } else if (has_base && base) { base_bs = bdrv_find_backing_image(top_bs, base); } else { base_bs = bdrv_find_base(top_bs); @@ -1990,6 +2011,23 @@ void qmp_block_commit(const char *device, return; } + /* Verify that 'base' is in the same chain as 'top' */ + if (!bdrv_chain_contains(top_bs, base_bs)) { + error_setg(errp, "'base' and 'top' are not in the same chain"); + return; + } + + /* This should technically be caught in commit_start, but + * check here for validation completeness */ + if (!bdrv_chain_contains(bs, top_bs)) { + error_setg(errp, "'%s' and 'top' are not in the same chain", device); + return; + } + + if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT, errp)) { + return; + } + if (top_bs == bs) { if (has_backing_file) { error_setg(errp, "'backing-file' specified," diff --git a/qapi/block-core.json b/qapi/block-core.json index ede27f0..9949add 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -745,14 +745,29 @@ # Live commit of data from overlay image nodes into backing nodes - i.e., # writes data between 'top' and 'base' into 'base'. # -# @device: the name of the device +# @device: The name of the device. # -# @base: #optional The file name of the backing image to write data into. -# If not specified, this is the deepest backing image +# For 'base', either @base or @base-node-name may be set but not both. If +# neither is specified, this is the deepest backing image. # -# @top: #optional The file name of the backing image within the image chain, -# which contains the topmost data to be committed down. If -# not specified, this is the active layer. +# @base: #optional The file name of the backing image to write data +# into. +# +# @base-node-name #optional The name of the block driver state node of the +# backing image to write data into. +# (Since 2.1) +# +# For 'top', either @top or @top-node-name must be set but not both. If +# neither is specified, this is the active layer. +# +# @top: #optional The file name of the backing image within the image +# chain, which contains the topmost data to be +# committed down. +# +# @top-node-name: #optional The block driver state node name of the backing +# image within the image chain, which contains the +# topmost data to be committed down. +# (Since 2.1) # # @backing-file: #optional The backing file string to write into the overlay # image of 'top'. If 'top' is the active layer, @@ -787,17 +802,22 @@ # # Returns: Nothing on success # If commit or stream is already active on this device, DeviceInUse -# If @device does not exist, DeviceNotFound +# If @device does not exist or cannot be determined, DeviceNotFound # If image commit is not supported by this device, NotSupported -# If @base or @top is invalid, a generic error is returned +# If @base, @top, @base-node-name, @top-node-name invalid, GenericError # If @speed is invalid, InvalidParameter +# If both @base and @base-node-name are specified, GenericError +# If both @top and @top-node-name are specified, GenericError +# If @top or @top-node-name is the active layer, and @backing-file is +# specified, GenericError # # Since: 1.3 # ## { 'command': 'block-commit', - 'data': { 'device': 'str', '*base': 'str', '*top': 'str', - '*backing-file': 'str', '*speed': 'int' } } + 'data': { 'device': 'str', '*base': 'str', '*base-node-name': 'str', + '*top': 'str', '*top-node-name': 'str', '*backing-file': 'str', + '*speed': 'int' } } ## # @drive-backup diff --git a/qmp-commands.hx b/qmp-commands.hx index ffd40d3..3db8167 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -985,7 +985,7 @@ EQMP { .name = "block-commit", - .args_type = "device:B,base:s?,top:s?,backing-file:s?,speed:o?", + .args_type = "device:B,base:s?,base-node-name:s?,top:s?,top-node-name:s?,backing-file:s?,speed:o?", .mhandler.cmd_new = qmp_marshal_input_block_commit, }, @@ -998,13 +998,28 @@ data between 'top' and 'base' into 'base'. Arguments: -- "device": The device's ID, must be unique (json-string) -- "base": The file name of the backing image to write data into. - If not specified, this is the deepest backing image - (json-string, optional) -- "top": The file name of the backing image within the image chain, - which contains the topmost data to be committed down. If - not specified, this is the active layer. (json-string, optional) +- "device": The device's ID, must be unique (json-string) + +For 'base', either base or base-node-name may be set but not both. If +neither is specified, this is the deepest backing image + +- "base": The file name of the backing image to write data into. + (json-string, optional) +- "base-node-name": The name of the block driver state node of the + backing image to write data into. + (json-string, optional) (Since 2.1) + +For 'top', either top or top-node-name must be set but not both. If +neither is specified, this is the active layer + +- "top": The file name of the backing image within the image chain, + which contains the topmost data to be committed down. + (json-string, optional) + +- "top-node-name": The block driver state node name of the backing + image within the image chain, which contains the + topmost data to be committed down. + (json-string, optional) (Since 2.1) - backing-file: The backing file string to write into the overlay image of 'top'. If 'top' is the active layer,