From patchwork Mon Apr 4 13:43:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 8741201 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3A1A1C0553 for ; Mon, 4 Apr 2016 13:50:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6DCC52024F for ; Mon, 4 Apr 2016 13:50:07 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 7865520166 for ; Mon, 4 Apr 2016 13:50:06 +0000 (UTC) Received: from localhost ([::1]:58776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4tJ-0001tB-0z for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Apr 2016 09:50:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4oh-000207-GO for qemu-devel@nongnu.org; Mon, 04 Apr 2016 09:45:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1an4of-0000Aw-Tg for qemu-devel@nongnu.org; Mon, 04 Apr 2016 09:45:19 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:65131 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4of-0000AC-Na; Mon, 04 Apr 2016 09:45:17 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CSAwCybgJX/5tjdVtdHYMagVCnFQEBAQEBBQGBEQGQZoIPAQ2BcoYNAoEzOBQBAQEBAQEBZSeEQgEBBHAJED8SPBsZiCsBvQcBAQEHIIVYgkWMYgWNTXCJRI4IiTqFVY8aHgEBQoIEGYFNaYZrJYEWAQEB X-IPAS-Result: A2CSAwCybgJX/5tjdVtdHYMagVCnFQEBAQEBBQGBEQGQZoIPAQ2BcoYNAoEzOBQBAQEBAQEBZSeEQgEBBHAJED8SPBsZiCsBvQcBAQEHIIVYgkWMYgWNTXCJRI4IiTqFVY8aHgEBQoIEGYFNaYZrJYEWAQEB X-IronPort-AV: E=Sophos;i="5.24,440,1454972400"; d="scan'208";a="39334344" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 04 Apr 2016 15:44:37 +0200 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim) id 1an4o1-000510-5V; Mon, 04 Apr 2016 15:44:37 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1an4nj-0003vX-3q; Mon, 04 Apr 2016 16:44:19 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 4 Apr 2016 16:43:57 +0300 Message-Id: X-Mailer: git-send-email 2.8.0.rc3 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 Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v9 07/11] block: Add QMP support for streaming to an intermediate layer 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch makes the 'device' parameter of the 'block-stream' command accept a node name as well as a device name. In addition to that, operation blockers will be checked in all intermediate nodes between the top and the base node. Since qmp_block_stream() now uses the error from bdrv_lookup_bs() and no longer returns DeviceNotFound, iotest 030 is updated to expect GenericError instead. Signed-off-by: Alberto Garcia --- blockdev.c | 31 +++++++++++++++++++++++-------- qapi/block-core.json | 10 +++++++--- tests/qemu-iotests/030 | 2 +- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/blockdev.c b/blockdev.c index 2e7712e..bfdc0e3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2989,6 +2989,7 @@ void qmp_block_stream(const char *device, BlockBackend *blk; BlockDriverState *bs; BlockDriverState *base_bs = NULL; + BlockDriverState *active; AioContext *aio_context; Error *local_err = NULL; const char *base_name = NULL; @@ -2997,21 +2998,19 @@ void qmp_block_stream(const char *device, on_error = BLOCKDEV_ON_ERROR_REPORT; } - blk = blk_by_name(device); - if (!blk) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", device); + bs = bdrv_lookup_bs(device, device, errp); + if (!bs) { return; } - aio_context = blk_get_aio_context(blk); + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - if (!blk_is_available(blk)) { + blk = blk_by_name(device); + if (blk && !blk_is_available(blk)) { error_setg(errp, "Device '%s' has no medium", device); goto out; } - bs = blk_bs(blk); if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_STREAM, errp)) { goto out; @@ -3027,6 +3026,22 @@ void qmp_block_stream(const char *device, base_name = base; } + /* Look for the top-level node that contains 'bs' in its chain */ + active = NULL; + do { + active = bdrv_next(active); + } while (active && !bdrv_chain_contains(active, bs)); + + if (active == NULL) { + error_setg(errp, "Cannot find top level node for '%s'", device); + goto out; + } + + /* Check for op blockers in the top-level node too */ + if (bdrv_op_is_blocked(active, BLOCK_OP_TYPE_STREAM, errp)) { + goto out; + } + /* if we are streaming the entire chain, the result will have no backing * file, and specifying one is therefore an error */ if (base_bs == NULL && has_backing_file) { @@ -3038,7 +3053,7 @@ void qmp_block_stream(const char *device, /* backing_file string overrides base bs filename */ base_name = has_backing_file ? backing_file : base_name; - stream_start(bs, NULL, base_bs, base_name, has_speed ? speed : 0, + stream_start(bs, active, base_bs, base_name, has_speed ? speed : 0, on_error, block_job_cb, bs, &local_err); if (local_err) { error_propagate(errp, local_err); diff --git a/qapi/block-core.json b/qapi/block-core.json index 59107ed..e20193a 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1405,6 +1405,10 @@ # with query-block-jobs. The operation can be stopped before it has completed # using the block-job-cancel command. # +# The node that receives the data is called the top image, can be located +# in any part of the whole chain and can be specified using its device +# or node name. +# # If a base file is specified then sectors are not copied from that base file and # its backing chain. When streaming completes the image file will have the base # file as its backing file. This can be used to stream a subset of the backing @@ -1413,12 +1417,12 @@ # On successful completion the image file is updated to drop the backing file # and the BLOCK_JOB_COMPLETED event is emitted. # -# @device: the device name +# @device: the device or node name of the top image # # @base: #optional the common backing file name # -# @backing-file: #optional The backing file string to write into the active -# layer. This filename is not validated. +# @backing-file: #optional The backing file string to write into the top +# image. This filename is not validated. # # If a pathname string is such that it cannot be # resolved by QEMU, that means that subsequent QMP or diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 index 3ac2443..107049b 100755 --- a/tests/qemu-iotests/030 +++ b/tests/qemu-iotests/030 @@ -126,7 +126,7 @@ class TestSingleDrive(iotests.QMPTestCase): def test_device_not_found(self): result = self.vm.qmp('block-stream', device='nonexistent') - self.assert_qmp(result, 'error/class', 'DeviceNotFound') + self.assert_qmp(result, 'error/class', 'GenericError') class TestSmallerBackingFile(iotests.QMPTestCase):