From patchwork Wed Jun 13 15:47:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Plotnikov X-Patchwork-Id: 10462599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 98D1F60329 for ; Wed, 13 Jun 2018 15:49:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 783AB28CE2 for ; Wed, 13 Jun 2018 15:49:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D10A28D12; Wed, 13 Jun 2018 15:49:15 +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.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 8DDA628CE2 for ; Wed, 13 Jun 2018 15:49:14 +0000 (UTC) Received: from localhost ([::1]:35262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT81J-0003jQ-HQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Jun 2018 11:49:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT7zf-0002br-5z for qemu-devel@nongnu.org; Wed, 13 Jun 2018 11:47:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fT7ze-0000Ah-80 for qemu-devel@nongnu.org; Wed, 13 Jun 2018 11:47:31 -0400 Received: from relay.sw.ru ([195.214.232.25]:41052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fT7zb-0008S9-HM; Wed, 13 Jun 2018 11:47:27 -0400 Received: from msk-vpn.virtuozzo.com ([195.214.232.6] helo=dptest2.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fT7zS-0006RM-Gh; Wed, 13 Jun 2018 18:47:18 +0300 From: Denis Plotnikov To: qemu-block@nongnu.org Date: Wed, 13 Jun 2018 18:47:11 +0300 Message-Id: <20180613154711.12977-3-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180613154711.12977-1-dplotnikov@virtuozzo.com> References: <20180613154711.12977-1-dplotnikov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v0 2/2] qmp: add block-set-copy-on-read 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: kwolf@redhat.com, famz@redhat.com, den@virtuozzo.com, qemu-devel@nongnu.org, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com, rkagan@virtuozzo.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The command enables/disables copy-on-read mode for VM's disk while VM is running. This is needed when using external disk readers to shape access pattern to the disk backend. Signed-off-by: Denis Plotnikov --- blockdev.c | 38 ++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 20 ++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/blockdev.c b/blockdev.c index 4862323012..4a297dabef 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4276,6 +4276,44 @@ out: aio_context_release(aio_context); } +void qmp_block_set_copy_on_read(const char *device, bool enable, Error **errp) +{ + Error *local_err = NULL; + AioContext *aio_context; + BlockDriverState *bs = bdrv_lookup_bs(device, device, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + aio_context = bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + + if (enable) { + if (bs->open_flags & BDRV_O_COPY_ON_READ) { + error_setg(errp, "Can't enable copy-on-read for the device. " + "Copy-on-read is already enabled."); + } else { + if (bdrv_enable_copy_on_read(bs)) { + bs->open_flags |= BDRV_O_COPY_ON_READ; + } else { + error_setg(errp, "Can't enable copy-on-read. " + "The device is read-only."); + } + } + } else { + if (bs->open_flags & BDRV_O_COPY_ON_READ) { + bs->open_flags &= ~BDRV_O_COPY_ON_READ; + bdrv_disable_copy_on_read(bs); + } else { + error_setg(errp, "Can't disable copy-on-read for the device. " + "Copy-on-read is already disabled."); + } + } + + aio_context_release(aio_context); +} + static BdrvChild *bdrv_find_child(BlockDriverState *parent_bs, const char *child_name) { diff --git a/qapi/block-core.json b/qapi/block-core.json index fff23fc82b..7369a13009 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4701,6 +4701,26 @@ { 'command': 'block-set-write-threshold', 'data': { 'node-name': 'str', 'write-threshold': 'uint64' } } +## +# @block-set-copy-on-read: +# +# Enables and disables the copy-on-read property of a block device. +# +# @device: device or graph node name on which copy-on-read must be set. +# +# Since: 2.12 +# +# Example: +# +# -> { "execute": "block-set-copy-on-read", +# "arguments": { "device": "scsi0-0-0-0", +# "enable": true } } +# <- { "return": {} } +# +## +{ 'command': 'block-set-copy-on-read', + 'data': { 'device': 'str', 'enable': 'bool' } } + ## # @x-blockdev-change: #