From patchwork Fri Mar 18 18:21:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8622991 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C311B9F6E1 for ; Fri, 18 Mar 2016 18:28:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08EEC2026C for ; Fri, 18 Mar 2016 18:28:16 +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 2F85E201F5 for ; Fri, 18 Mar 2016 18:28:15 +0000 (UTC) Received: from localhost ([::1]:45606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz8A-0007Fd-Ep for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Mar 2016 14:28:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz2I-0004Ye-G3 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 14:22:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agz2H-0007Gf-Bo for qemu-devel@nongnu.org; Fri, 18 Mar 2016 14:22:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40093) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz2C-0007DD-36; Fri, 18 Mar 2016 14:22:04 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id C2A6664387; Fri, 18 Mar 2016 18:22:03 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-83.ams2.redhat.com [10.36.116.83]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2IILZO8021202; Fri, 18 Mar 2016 14:22:02 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 18 Mar 2016 19:21:26 +0100 Message-Id: <1458325289-17848-18-git-send-email-kwolf@redhat.com> In-Reply-To: <1458325289-17848-1-git-send-email-kwolf@redhat.com> References: <1458325289-17848-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 18 Mar 2016 18:22:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Subject: [Qemu-devel] [PATCH 17/20] qemu-io: Use bdrv_parse_cache_mode() in reopen_f() 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 We must forbid changing the WCE flag in bdrv_reopen() in the same patch, as otherwise the behaviour would change so that the flag takes precedence over the explicitly specified option. The correct value of the WCE flag depends on the BlockBackend user (e.g. guest device) and isn't a decision that the QMP client makes, so this change is what we want. Signed-off-by: Kevin Wolf --- block.c | 18 ++++++------------ qemu-io-cmds.c | 14 +++++++++++++- tests/qemu-iotests/142 | 2 +- tests/qemu-iotests/142.out | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index 4e95d01..3775e65 100644 --- a/block.c +++ b/block.c @@ -2028,18 +2028,12 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, update_flags_from_options(&reopen_state->flags, opts); - /* If a guest device is attached, it owns WCE */ - if (reopen_state->bs->blk && blk_get_attached_dev(reopen_state->bs->blk)) { - bool old_wce = bdrv_enable_write_cache(reopen_state->bs); - bool new_wce = (reopen_state->flags & BDRV_O_CACHE_WB); - if (old_wce != new_wce) { - error_setg(errp, "Cannot change cache.writeback: Device attached"); - ret = -EINVAL; - goto error; - } - } - if (!reopen_state->bs->blk && !(reopen_state->flags & BDRV_O_CACHE_WB)) { - error_setg(errp, "Cannot disable cache.writeback: No BlockBackend"); + /* WCE is a BlockBackend level option, can't change it */ + bool old_wce = bdrv_enable_write_cache(reopen_state->bs); + bool new_wce = (reopen_state->flags & BDRV_O_CACHE_WB); + + if (old_wce != new_wce) { + error_setg(errp, "Cannot change cache.writeback"); ret = -EINVAL; goto error; } diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index e929d24..7de3754 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2104,6 +2104,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) QDict *opts; int c; int flags = bs->open_flags; + bool writethrough = !blk_enable_write_cache(blk); BlockReopenQueue *brq; Error *local_err = NULL; @@ -2111,7 +2112,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) while ((c = getopt(argc, argv, "c:o:r")) != -1) { switch (c) { case 'c': - if (bdrv_parse_cache_flags(optarg, &flags) < 0) { + if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); return 0; } @@ -2136,14 +2137,25 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) return qemuio_command_usage(&reopen_cmd); } + if (writethrough != blk_enable_write_cache(blk) && + blk_get_attached_dev(blk)) + { + error_report("Cannot change cache.writeback: Device attached"); + qemu_opts_reset(&reopen_opts); + return 0; + } + qopts = qemu_opts_find(&reopen_opts, NULL); opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL; qemu_opts_reset(&reopen_opts); + flags |= blk_enable_write_cache(blk) ? BDRV_O_CACHE_WB : 0; brq = bdrv_reopen_queue(NULL, bs, opts, flags); bdrv_reopen_multiple(brq, &local_err); if (local_err) { error_report_err(local_err); + } else { + blk_set_enable_write_cache(blk, !writethrough); } return 0; diff --git a/tests/qemu-iotests/142 b/tests/qemu-iotests/142 index 8bbbfde..a035747 100755 --- a/tests/qemu-iotests/142 +++ b/tests/qemu-iotests/142 @@ -216,7 +216,7 @@ echo # BDS initialised with the json: pseudo-protocol, but still have it inherit # options from its parent node. -hmp_cmds="qemu-io none0 \"reopen -o cache.writeback=off,cache.direct=on,cache.no-flush=on\" +hmp_cmds="qemu-io none0 \"reopen -o cache.direct=on,cache.no-flush=on\" info block none0 info block image info block blkdebug diff --git a/tests/qemu-iotests/142.out b/tests/qemu-iotests/142.out index c922490..3d5ef5f 100644 --- a/tests/qemu-iotests/142.out +++ b/tests/qemu-iotests/142.out @@ -414,7 +414,7 @@ cache.no-flush=on on backing-file --- Change cache mode in parent, child has explicit option in JSON --- - Cache mode: writethrough, direct, ignore flushes + Cache mode: writeback, direct, ignore flushes Cache mode: writeback, direct, ignore flushes Cache mode: writeback, direct, ignore flushes Cache mode: writeback, ignore flushes