From patchwork Fri Mar 18 18:21:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8622961 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 DEA559F6E1 for ; Fri, 18 Mar 2016 18:26:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05BB9201FE for ; Fri, 18 Mar 2016 18:26:28 +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 EEBDF201F5 for ; Fri, 18 Mar 2016 18:26:26 +0000 (UTC) Received: from localhost ([::1]:45590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz6P-0003W4-Vc for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Mar 2016 14:26:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz23-00041g-LI for qemu-devel@nongnu.org; Fri, 18 Mar 2016 14:21:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agz22-00077X-8c for qemu-devel@nongnu.org; Fri, 18 Mar 2016 14:21:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55016) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agz1y-00074H-Ou; Fri, 18 Mar 2016 14:21:51 -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 7782D1F586; Fri, 18 Mar 2016 18:21:50 +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 u2IILZNx021202; Fri, 18 Mar 2016 14:21:48 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 18 Mar 2016 19:21:17 +0100 Message-Id: <1458325289-17848-9-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 08/20] block: Always set writeback mode in blk_new_open() 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 All callers of blk_new_open() either don't rely on the WCE bit set after blk_new_open() because they explicitly set it anyway, or they pass BDRV_O_CACHE_WB unconditionally. This patch changes blk_new_open() so that it always enables writeback mode and asserts that BDRV_O_CACHE_WB is clear. For those callers that used to pass BDRV_O_CACHE_WB unconditionally, the flag is removed now. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/block-backend.c | 4 ++++ block/parallels.c | 3 +-- block/qcow.c | 3 +-- block/qcow2.c | 9 +++------ block/qed.c | 3 +-- block/sheepdog.c | 5 ++--- block/vdi.c | 3 +-- block/vhdx.c | 3 +-- block/vmdk.c | 8 +++----- block/vpc.c | 3 +-- blockdev.c | 1 + 11 files changed, 19 insertions(+), 26 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index dca21d1..ffa5856 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -147,6 +147,8 @@ BlockBackend *blk_new_open(const char *filename, const char *reference, BlockBackend *blk; int ret; + assert((flags & BDRV_O_CACHE_WB) == 0); + blk = blk_new_with_bs(errp); if (!blk) { QDECREF(options); @@ -159,6 +161,8 @@ BlockBackend *blk_new_open(const char *filename, const char *reference, return NULL; } + blk_set_enable_write_cache(blk, true); + return blk; } diff --git a/block/parallels.c b/block/parallels.c index b322d05..fc18bd7 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -479,8 +479,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp) } file = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - &local_err); + BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (file == NULL) { error_propagate(errp, local_err); return -EIO; diff --git a/block/qcow.c b/block/qcow.c index 73cf8a7..07dd867 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -794,8 +794,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) } qcow_blk = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - &local_err); + BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (qcow_blk == NULL) { error_propagate(errp, local_err); ret = -EIO; diff --git a/block/qcow2.c b/block/qcow2.c index 5f4fea6..4363f78 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2160,8 +2160,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, } blk = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - &local_err); + BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (blk == NULL) { error_propagate(errp, local_err); return -EIO; @@ -2225,8 +2224,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, options = qdict_new(); qdict_put(options, "driver", qstring_from_str("qcow2")); blk = blk_new_open(filename, NULL, options, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, - &local_err); + BDRV_O_RDWR | BDRV_O_NO_FLUSH, &local_err); if (blk == NULL) { error_propagate(errp, local_err); ret = -EIO; @@ -2287,8 +2285,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, options = qdict_new(); qdict_put(options, "driver", qstring_from_str("qcow2")); blk = blk_new_open(filename, NULL, options, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING, - &local_err); + BDRV_O_RDWR | BDRV_O_NO_BACKING, &local_err); if (blk == NULL) { error_propagate(errp, local_err); ret = -EIO; diff --git a/block/qed.c b/block/qed.c index 5b24a97..091d207 100644 --- a/block/qed.c +++ b/block/qed.c @@ -575,8 +575,7 @@ static int qed_create(const char *filename, uint32_t cluster_size, } blk = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - &local_err); + BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (blk == NULL) { error_propagate(errp, local_err); return -EIO; diff --git a/block/sheepdog.c b/block/sheepdog.c index a3aeae4..4b1bfc9 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1647,8 +1647,7 @@ static int sd_prealloc(const char *filename, Error **errp) int ret; blk = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - errp); + BDRV_O_RDWR | BDRV_O_PROTOCOL, errp); if (blk == NULL) { ret = -EIO; goto out_with_err_set; @@ -1844,7 +1843,7 @@ static int sd_create(const char *filename, QemuOpts *opts, } blk = blk_new_open(backing_file, NULL, NULL, - BDRV_O_PROTOCOL | BDRV_O_CACHE_WB, errp); + BDRV_O_PROTOCOL, errp); if (blk == NULL) { ret = -EIO; goto out; diff --git a/block/vdi.c b/block/vdi.c index df9fa47..1791f22 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -769,8 +769,7 @@ static int vdi_create(const char *filename, QemuOpts *opts, Error **errp) } blk = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - &local_err); + BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (blk == NULL) { error_propagate(errp, local_err); ret = -EIO; diff --git a/block/vhdx.c b/block/vhdx.c index 78fe56c..7d1bddc 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1839,8 +1839,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) } blk = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - &local_err); + BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (blk == NULL) { error_propagate(errp, local_err); ret = -EIO; diff --git a/block/vmdk.c b/block/vmdk.c index 80f0338..60f4d79 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1662,8 +1662,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, } blk = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - &local_err); + BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (blk == NULL) { error_propagate(errp, local_err); ret = -EIO; @@ -1947,7 +1946,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) } blk = blk_new_open(full_backing, NULL, NULL, - BDRV_O_NO_BACKING | BDRV_O_CACHE_WB, errp); + BDRV_O_NO_BACKING, errp); g_free(full_backing); if (blk == NULL) { ret = -EIO; @@ -2019,8 +2018,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) } new_blk = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - &local_err); + BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (new_blk == NULL) { error_propagate(errp, local_err); ret = -EIO; diff --git a/block/vpc.c b/block/vpc.c index 8435205..0429528 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -889,8 +889,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) } blk = blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, - &local_err); + BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (blk == NULL) { error_propagate(errp, local_err); ret = -EIO; diff --git a/blockdev.c b/blockdev.c index 70c3add..10eefda 100644 --- a/blockdev.c +++ b/blockdev.c @@ -596,6 +596,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_WB, writethrough ? "off" : "on"); qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_DIRECT, "off"); qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, "off"); + assert((bdrv_flags & BDRV_O_CACHE_MASK) == 0); if (runstate_check(RUN_STATE_INMIGRATE)) { bdrv_flags |= BDRV_O_INACTIVE;