From patchwork Fri Apr 24 11:40:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 464203 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 8ED3814018C for ; Fri, 24 Apr 2015 21:47:38 +1000 (AEST) Received: from localhost ([::1]:44332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ylc50-0006kT-RP for incoming@patchwork.ozlabs.org; Fri, 24 Apr 2015 07:47:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlbzP-000534-Q5 for qemu-devel@nongnu.org; Fri, 24 Apr 2015 07:41:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YlbzL-0008MK-P6 for qemu-devel@nongnu.org; Fri, 24 Apr 2015 07:41:47 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:46859 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlbzL-0008L2-EB; Fri, 24 Apr 2015 07:41:43 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlUGAGErOlVbdWOb/2dsb2JhbABbgwyBLrRWAQEBAQEBBQGBApg9AoE9TAEBAQEBAYELhCEBAQQnUhBRPBsZiC8By30BAQEHIoYWiiUHhC0FhjyFFJAvlUsjYIEnHIFUOzGBBCSBHAEBAQ X-IPAS-Result: AlUGAGErOlVbdWOb/2dsb2JhbABbgwyBLrRWAQEBAQEBBQGBApg9AoE9TAEBAQEBAYELhCEBAQQnUhBRPBsZiC8By30BAQEHIoYWiiUHhC0FhjyFFJAvlUsjYIEnHIFUOzGBBCSBHAEBAQ X-IronPort-AV: E=Sophos;i="5.11,639,1422918000"; d="scan'208";a="349787593" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 24 Apr 2015 13:41:39 +0200 Received: from maestria.local.igalia.com ([192.168.10.14] helo=mail.igalia.com) by fanzine.igalia.com with esmtps (Cipher TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim) id 1YlbzH-00034g-6W; Fri, 24 Apr 2015 13:41:39 +0200 Received: from fanzine.local.igalia.com ([192.168.10.13] helo=perseus.local) by mail.igalia.com with esmtps (Cipher TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim) id 1YlbzG-0000pe-2f; Fri, 24 Apr 2015 13:41:38 +0200 Received: from berto by perseus.local with local (Exim 4.84) (envelope-from ) id 1YlbzE-0001sI-Qx; Fri, 24 Apr 2015 14:41:36 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 24 Apr 2015 14:40:49 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 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 05/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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- blockdev.c | 20 ++++++++++---------- qapi/block-core.json | 10 +++++++--- tests/qemu-iotests/030 | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/blockdev.c b/blockdev.c index 677432f..d62e548 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2104,8 +2104,7 @@ void qmp_block_stream(const char *device, bool has_on_error, BlockdevOnError on_error, Error **errp) { - BlockBackend *blk; - BlockDriverState *bs; + BlockDriverState *bs, *iter; BlockDriverState *base_bs = NULL; AioContext *aio_context; Error *local_err = NULL; @@ -2115,20 +2114,14 @@ void qmp_block_stream(const char *device, on_error = BLOCKDEV_ON_ERROR_REPORT; } - blk = blk_by_name(device); - if (!blk) { - error_set(errp, QERR_DEVICE_NOT_FOUND, device); + bs = bdrv_lookup_bs(device, device, errp); + if (!bs) { return; } - bs = blk_bs(blk); aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_STREAM, errp)) { - goto out; - } - if (has_base) { base_bs = bdrv_find_backing_image(bs, base); if (base_bs == NULL) { @@ -2139,6 +2132,13 @@ void qmp_block_stream(const char *device, base_name = base; } + /* Check for op blockers in the whole chain between bs and base */ + for (iter = bs; iter && iter != base_bs; iter = iter->backing_hd) { + if (bdrv_op_is_blocked(iter, 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) { diff --git a/qapi/block-core.json b/qapi/block-core.json index 5126ae0..befc5ce 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1014,6 +1014,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 @@ -1022,12 +1026,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 952a524..7ca9b25 100755 --- a/tests/qemu-iotests/030 +++ b/tests/qemu-iotests/030 @@ -107,7 +107,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):