From patchwork Fri Mar 18 18:21:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8622931 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 AA47C9F758 for ; Fri, 18 Mar 2016 18:24:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A54932026C for ; Fri, 18 Mar 2016 18:24:13 +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 6D1E7201F5 for ; Fri, 18 Mar 2016 18:24:12 +0000 (UTC) Received: from localhost ([::1]:45561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz4F-0007pd-Po for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Mar 2016 14:24:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz22-0003zU-Na for qemu-devel@nongnu.org; Fri, 18 Mar 2016 14:21:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agz20-00076F-Hy for qemu-devel@nongnu.org; Fri, 18 Mar 2016 14:21:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36609) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz1t-00070z-Jr; Fri, 18 Mar 2016 14:21:45 -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 4DBEC80E42; Fri, 18 Mar 2016 18:21:45 +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 u2IILZNu021202; Fri, 18 Mar 2016 14:21:44 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 18 Mar 2016 19:21:14 +0100 Message-Id: <1458325289-17848-6-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 05/20] qemu-img: 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-img.c | 79 ++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 839e05b..96b51d4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -245,7 +245,7 @@ static int img_open_password(BlockBackend *blk, const char *filename, static BlockBackend *img_open_opts(const char *optstr, - QemuOpts *opts, int flags, + QemuOpts *opts, int flags, bool writethrough, bool require_io, bool quiet) { QDict *options; @@ -257,6 +257,7 @@ static BlockBackend *img_open_opts(const char *optstr, error_reportf_err(local_err, "Could not open '%s'", optstr); return NULL; } + blk_set_enable_write_cache(blk, !writethrough); if (img_open_password(blk, optstr, require_io, quiet) < 0) { blk_unref(blk); @@ -267,7 +268,8 @@ static BlockBackend *img_open_opts(const char *optstr, static BlockBackend *img_open_file(const char *filename, const char *fmt, int flags, - bool require_io, bool quiet) + bool writethrough, bool require_io, + bool quiet) { BlockBackend *blk; Error *local_err = NULL; @@ -283,6 +285,7 @@ static BlockBackend *img_open_file(const char *filename, error_reportf_err(local_err, "Could not open '%s': ", filename); return NULL; } + blk_set_enable_write_cache(blk, !writethrough); if (img_open_password(blk, filename, require_io, quiet) < 0) { blk_unref(blk); @@ -294,7 +297,7 @@ static BlockBackend *img_open_file(const char *filename, static BlockBackend *img_open(bool image_opts, const char *filename, - const char *fmt, int flags, + const char *fmt, int flags, bool writethrough, bool require_io, bool quiet) { BlockBackend *blk; @@ -309,9 +312,9 @@ static BlockBackend *img_open(bool image_opts, if (!opts) { return NULL; } - blk = img_open_opts(filename, opts, flags, true, quiet); + blk = img_open_opts(filename, opts, flags, writethrough, true, quiet); } else { - blk = img_open_file(filename, fmt, flags, true, quiet); + blk = img_open_file(filename, fmt, flags, writethrough, true, quiet); } return blk; } @@ -589,7 +592,8 @@ static int img_check(int argc, char **argv) BlockBackend *blk; BlockDriverState *bs; int fix = 0; - int flags = BDRV_O_CACHE_WB | BDRV_O_CHECK; + int flags = BDRV_O_CHECK; + bool writethrough; ImageCheck *check; bool quiet = false; Error *local_err = NULL; @@ -598,6 +602,7 @@ static int img_check(int argc, char **argv) fmt = NULL; output = NULL; cache = BDRV_DEFAULT_CACHE; + for(;;) { int option_index = 0; static const struct option long_options[] = { @@ -677,13 +682,13 @@ static int img_check(int argc, char **argv) return 1; } - ret = bdrv_parse_cache_flags(cache, &flags); + ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", cache); return 1; } - blk = img_open(image_opts, filename, fmt, flags, true, quiet); + blk = img_open(image_opts, filename, fmt, flags, writethrough, true, quiet); if (!blk) { return 1; } @@ -793,6 +798,7 @@ static int img_commit(int argc, char **argv) BlockBackend *blk; BlockDriverState *bs, *base_bs; bool progress = false, quiet = false, drop = false; + bool writethrough; Error *local_err = NULL; CommonBlockJobCBInfo cbi; bool image_opts = false; @@ -869,13 +875,13 @@ static int img_commit(int argc, char **argv) } flags = BDRV_O_RDWR | BDRV_O_UNMAP; - ret = bdrv_parse_cache_flags(cache, &flags); + ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid cache option: %s", cache); return 1; } - blk = img_open(image_opts, filename, fmt, flags, true, quiet); + blk = img_open(image_opts, filename, fmt, flags, writethrough, true, quiet); if (!blk) { return 1; } @@ -1119,6 +1125,7 @@ static int img_compare(int argc, char **argv) int ret = 0; /* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false; int flags; + bool writethrough; int64_t total_sectors; int64_t sector_num = 0; int64_t nb_sectors; @@ -1201,21 +1208,23 @@ static int img_compare(int argc, char **argv) /* Initialize before goto out */ qemu_progress_init(progress, 2.0); - flags = BDRV_O_CACHE_WB; - ret = bdrv_parse_cache_flags(cache, &flags); + flags = 0; + ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", cache); ret = 2; goto out3; } - blk1 = img_open(image_opts, filename1, fmt1, flags, true, quiet); + blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, true, + quiet); if (!blk1) { ret = 2; goto out3; } - blk2 = img_open(image_opts, filename2, fmt2, flags, true, quiet); + blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, true, + quiet); if (!blk2) { ret = 2; goto out2; @@ -1709,6 +1718,7 @@ static int img_convert(int argc, char **argv) int c, bs_n, bs_i, compress, cluster_sectors, skip_create; int64_t ret = 0; int progress = 0, flags, src_flags; + bool writethrough, src_writethrough; const char *fmt, *out_fmt, *cache, *src_cache, *out_baseimg, *out_filename; BlockDriver *drv, *proto_drv; BlockBackend **blk = NULL, *out_blk = NULL; @@ -1881,8 +1891,8 @@ static int img_convert(int argc, char **argv) goto out; } - src_flags = BDRV_O_CACHE_WB; - ret = bdrv_parse_cache_flags(src_cache, &src_flags); + src_flags = 0; + ret = bdrv_parse_cache_mode(src_cache, &src_flags, &src_writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", src_cache); goto out; @@ -1897,7 +1907,7 @@ static int img_convert(int argc, char **argv) total_sectors = 0; for (bs_i = 0; bs_i < bs_n; bs_i++) { blk[bs_i] = img_open(image_opts, argv[optind + bs_i], - fmt, src_flags, true, quiet); + fmt, src_flags, src_writethrough, true, quiet); if (!blk[bs_i]) { ret = -1; goto out; @@ -2031,7 +2041,7 @@ static int img_convert(int argc, char **argv) } flags = min_sparse ? (BDRV_O_RDWR | BDRV_O_UNMAP) : BDRV_O_RDWR; - ret = bdrv_parse_cache_flags(cache, &flags); + ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid cache option: %s", cache); goto out; @@ -2042,7 +2052,8 @@ static int img_convert(int argc, char **argv) * the bdrv_create() call which takes different params. * Not critical right now, so fix can wait... */ - out_blk = img_open_file(out_filename, out_fmt, flags, true, quiet); + out_blk = img_open_file(out_filename, out_fmt, flags, writethrough, true, + quiet); if (!out_blk) { ret = -1; goto out; @@ -2234,7 +2245,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts, g_hash_table_insert(filenames, (gpointer)filename, NULL); blk = img_open(image_opts, filename, fmt, - BDRV_O_CACHE_WB | BDRV_O_NO_BACKING, + BDRV_O_NO_BACKING, false, false, false); if (!blk) { goto err; @@ -2565,7 +2576,7 @@ static int img_map(int argc, char **argv) return 1; } - blk = img_open(image_opts, filename, fmt, BDRV_O_CACHE_WB, true, false); + blk = img_open(image_opts, filename, fmt, 0, false, true, false); if (!blk) { return 1; } @@ -2629,7 +2640,7 @@ static int img_snapshot(int argc, char **argv) Error *err = NULL; bool image_opts = false; - bdrv_oflags = BDRV_O_CACHE_WB | BDRV_O_RDWR; + bdrv_oflags = BDRV_O_RDWR; /* Parse commandline parameters */ for(;;) { static const struct option long_options[] = { @@ -2710,7 +2721,7 @@ static int img_snapshot(int argc, char **argv) } /* Open the image */ - blk = img_open(image_opts, filename, NULL, bdrv_oflags, true, quiet); + blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, true, quiet); if (!blk) { return 1; } @@ -2772,6 +2783,7 @@ static int img_rebase(int argc, char **argv) char *filename; const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg; int c, flags, src_flags, ret; + bool writethrough, src_writethrough; int unsafe = 0; int progress = 0; bool quiet = false; @@ -2862,26 +2874,30 @@ static int img_rebase(int argc, char **argv) qemu_progress_print(0, 100); flags = BDRV_O_RDWR | (unsafe ? BDRV_O_NO_BACKING : 0); - ret = bdrv_parse_cache_flags(cache, &flags); + ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid cache option: %s", cache); goto out; } - src_flags = BDRV_O_CACHE_WB; - ret = bdrv_parse_cache_flags(src_cache, &src_flags); + src_flags = 0; + ret = bdrv_parse_cache_mode(src_cache, &src_flags, &src_writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", src_cache); goto out; } + /* The source files are opened read-only, don't care about WCE */ + assert((src_writethrough & BDRV_O_RDWR) == 0); + (void) src_writethrough; + /* * Open the images. * * Ignore the old backing file for unsafe rebase in case we want to correct * the reference to a renamed or moved backing file. */ - blk = img_open(image_opts, filename, fmt, flags, true, quiet); + blk = img_open(image_opts, filename, fmt, flags, true, writethrough, quiet); if (!blk) { ret = -1; goto out; @@ -3219,7 +3235,7 @@ static int img_resize(int argc, char **argv) qemu_opts_del(param); blk = img_open(image_opts, filename, fmt, - BDRV_O_CACHE_WB | BDRV_O_RDWR, true, quiet); + BDRV_O_RDWR, false, true, quiet); if (!blk) { ret = -1; goto out; @@ -3275,6 +3291,7 @@ static int img_amend(int argc, char **argv) QemuOpts *opts = NULL; const char *fmt = NULL, *filename, *cache; int flags; + bool writethrough; bool quiet = false, progress = false; BlockBackend *blk = NULL; BlockDriverState *bs = NULL; @@ -3371,14 +3388,14 @@ static int img_amend(int argc, char **argv) goto out; } - flags = BDRV_O_CACHE_WB | BDRV_O_RDWR; - ret = bdrv_parse_cache_flags(cache, &flags); + flags = BDRV_O_RDWR; + ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid cache option: %s", cache); goto out; } - blk = img_open(image_opts, filename, fmt, flags, true, quiet); + blk = img_open(image_opts, filename, fmt, flags, writethrough, true, quiet); if (!blk) { ret = -1; goto out;