From patchwork Fri Mar 18 18:21:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8622871 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 DA99AC0554 for ; Fri, 18 Mar 2016 18:22:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3C2CF201FE for ; Fri, 18 Mar 2016 18:22:09 +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 7C5842034F for ; Fri, 18 Mar 2016 18:22:08 +0000 (UTC) Received: from localhost ([::1]:45535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz2F-0003sr-BL for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Mar 2016 14:22:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz1u-0003gX-1I for qemu-devel@nongnu.org; Fri, 18 Mar 2016 14:21:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agz1s-00070O-U8 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 14:21:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45681) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz1q-0006xc-MB; Fri, 18 Mar 2016 14:21:42 -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 612307F080; Fri, 18 Mar 2016 18:21:42 +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 u2IILZNs021202; Fri, 18 Mar 2016 14:21:41 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 18 Mar 2016 19:21:12 +0100 Message-Id: <1458325289-17848-4-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-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Subject: [Qemu-devel] [PATCH 03/20] qemu-io: Call blk_set_enable_write_cache() explicitly 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 Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- qemu-io.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index d7c2f26..260b024 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -50,7 +50,7 @@ static const cmdinfo_t close_cmd = { .oneline = "close the current open file", }; -static int openfile(char *name, int flags, QDict *opts) +static int openfile(char *name, int flags, bool writethrough, QDict *opts) { Error *local_err = NULL; BlockDriverState *bs; @@ -82,6 +82,7 @@ static int openfile(char *name, int flags, QDict *opts) } } + blk_set_enable_write_cache(qemuio_blk, !writethrough); return 0; @@ -136,6 +137,7 @@ static int open_f(BlockBackend *blk, int argc, char **argv) { int flags = 0; int readonly = 0; + bool writethrough = true; int c; QemuOpts *qopts; QDict *opts; @@ -146,7 +148,8 @@ static int open_f(BlockBackend *blk, int argc, char **argv) flags |= BDRV_O_SNAPSHOT; break; case 'n': - flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; + flags |= BDRV_O_NOCACHE; + writethrough = false; break; case 'r': readonly = 1; @@ -184,9 +187,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv) qemu_opts_reset(&empty_opts); if (optind == argc - 1) { - return openfile(argv[optind], flags, opts); + return openfile(argv[optind], flags, writethrough, opts); } else if (optind == argc) { - return openfile(NULL, flags, opts); + return openfile(NULL, flags, writethrough, opts); } else { QDECREF(opts); return qemuio_command_usage(&open_cmd); @@ -427,6 +430,7 @@ int main(int argc, char **argv) int c; int opt_index = 0; int flags = BDRV_O_UNMAP; + bool writethrough = true; Error *local_error = NULL; QDict *opts = NULL; const char *format = NULL; @@ -448,7 +452,8 @@ int main(int argc, char **argv) flags |= BDRV_O_SNAPSHOT; break; case 'n': - flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; + flags |= BDRV_O_NOCACHE; + writethrough = false; break; case 'd': if (bdrv_parse_discard_flags(optarg, &flags) < 0) { @@ -472,7 +477,7 @@ int main(int argc, char **argv) flags |= BDRV_O_NATIVE_AIO; break; case 't': - if (bdrv_parse_cache_flags(optarg, &flags) < 0) { + if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); exit(1); } @@ -554,13 +559,13 @@ int main(int argc, char **argv) exit(1); } opts = qemu_opts_to_qdict(qopts, NULL); - openfile(NULL, flags, opts); + openfile(NULL, flags, writethrough, opts); } else { if (format) { opts = qdict_new(); qdict_put(opts, "driver", qstring_from_str(format)); } - openfile(argv[optind], flags, opts); + openfile(argv[optind], flags, writethrough, opts); } } command_loop();