From patchwork Tue Mar 15 14:11:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 86987 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9AED6B700C for ; Wed, 16 Mar 2011 01:16:45 +1100 (EST) Received: from localhost ([127.0.0.1]:33888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzV3C-0006p0-Dp for incoming@patchwork.ozlabs.org; Tue, 15 Mar 2011 10:16:42 -0400 Received: from [140.186.70.92] (port=59964 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzUxj-0004Dz-B3 for qemu-devel@nongnu.org; Tue, 15 Mar 2011 10:11:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzUxh-0002RE-Qe for qemu-devel@nongnu.org; Tue, 15 Mar 2011 10:11:03 -0400 Received: from verein.lst.de ([213.95.11.211]:38234 helo=newverein.lst.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzUxh-0002Qw-Fs for qemu-devel@nongnu.org; Tue, 15 Mar 2011 10:11:01 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id 0A64D13FBC; Tue, 15 Mar 2011 15:11:01 +0100 (CET) Date: Tue, 15 Mar 2011 15:11:01 +0100 From: Christoph Hellwig To: qemu-devel@nongnu.org Message-ID: <20110315141100.GA30710@lst.de> References: <20110315141049.GA30627@lst.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110315141049.GA30627@lst.de> User-Agent: Mutt/1.5.17 (2007-11-01) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 213.95.11.211 Cc: kwolf@redhat.com, stefanha@gmail.com, "prerna@linux.vnet.ibm.com Anthony Liguori" Subject: [Qemu-devel] [PATCH 1/4] block: clarify the meaning of BDRV_O_NOCACHE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Change BDRV_O_NOCACHE to only imply bypassing the host OS file cache, but no writeback semantics. All existing callers are changed to also specify BDRV_O_CACHE_WB to give them writeback semantics. Signed-off-by: Christoph Hellwig Index: qemu/block.c =================================================================== --- qemu.orig/block.c 2011-03-08 20:11:08.188219978 +0100 +++ qemu/block.c 2011-03-08 20:12:44.971718742 +0100 @@ -439,13 +439,7 @@ static int bdrv_open_common(BlockDriverS bs->drv = drv; bs->opaque = qemu_mallocz(drv->instance_size); - /* - * Yes, BDRV_O_NOCACHE aka O_DIRECT means we have to present a - * write cache to the guest. We do need the fdatasync to flush - * out transactions for block allocations, and we maybe have a - * volatile write cache in our backing device to deal with. - */ - if (flags & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE)) + if (flags & BDRV_O_CACHE_WB) bs->enable_write_cache = 1; /* Index: qemu/block/raw-posix.c =================================================================== --- qemu.orig/block/raw-posix.c 2011-03-08 20:11:08.200220692 +0100 +++ qemu/block/raw-posix.c 2011-03-08 20:11:22.229218596 +0100 @@ -154,7 +154,7 @@ static int raw_open_common(BlockDriverSt * and O_DIRECT for no caching. */ if ((bdrv_flags & BDRV_O_NOCACHE)) s->open_flags |= O_DIRECT; - else if (!(bdrv_flags & BDRV_O_CACHE_WB)) + if (!(bdrv_flags & BDRV_O_CACHE_WB)) s->open_flags |= O_DSYNC; s->fd = -1; Index: qemu/block/raw-win32.c =================================================================== --- qemu.orig/block/raw-win32.c 2011-03-08 20:11:08.212218227 +0100 +++ qemu/block/raw-win32.c 2011-03-08 20:11:22.237218180 +0100 @@ -88,9 +88,9 @@ static int raw_open(BlockDriverState *bs } overlapped = FILE_ATTRIBUTE_NORMAL; - if ((flags & BDRV_O_NOCACHE)) - overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; - else if (!(flags & BDRV_O_CACHE_WB)) + if (flags & BDRV_O_NOCACHE) + overlapped |= FILE_FLAG_NO_BUFFERING; + if (!(flags & BDRV_O_CACHE_WB)) overlapped |= FILE_FLAG_WRITE_THROUGH; s->hfile = CreateFile(filename, access_flags, FILE_SHARE_READ, NULL, @@ -349,9 +349,9 @@ static int hdev_open(BlockDriverState *b create_flags = OPEN_EXISTING; overlapped = FILE_ATTRIBUTE_NORMAL; - if ((flags & BDRV_O_NOCACHE)) - overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; - else if (!(flags & BDRV_O_CACHE_WB)) + if (flags & BDRV_O_NOCACHE) + overlapped |= FILE_FLAG_NO_BUFFERING; + if (!(flags & BDRV_O_CACHE_WB)) overlapped |= FILE_FLAG_WRITE_THROUGH; s->hfile = CreateFile(filename, access_flags, FILE_SHARE_READ, NULL, Index: qemu/blockdev.c =================================================================== --- qemu.orig/blockdev.c 2011-03-08 20:11:08.220217606 +0100 +++ qemu/blockdev.c 2011-03-08 20:11:22.237218180 +0100 @@ -326,7 +326,7 @@ DriveInfo *drive_init(QemuOpts *opts, in if ((buf = qemu_opt_get(opts, "cache")) != NULL) { if (!strcmp(buf, "off") || !strcmp(buf, "none")) { - bdrv_flags |= BDRV_O_NOCACHE; + bdrv_flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; } else if (!strcmp(buf, "writeback")) { bdrv_flags |= BDRV_O_CACHE_WB; } else if (!strcmp(buf, "unsafe")) { Index: qemu/qemu-io.c =================================================================== --- qemu.orig/qemu-io.c 2011-03-08 20:11:08.232220650 +0100 +++ qemu/qemu-io.c 2011-03-08 20:11:22.245232398 +0100 @@ -1655,7 +1655,7 @@ open_f(int argc, char **argv) flags |= BDRV_O_SNAPSHOT; break; case 'n': - flags |= BDRV_O_NOCACHE; + flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; break; case 'r': readonly = 1; @@ -1751,7 +1751,7 @@ int main(int argc, char **argv) flags |= BDRV_O_SNAPSHOT; break; case 'n': - flags |= BDRV_O_NOCACHE; + flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; break; case 'c': add_user_command(optarg); Index: qemu/qemu-nbd.c =================================================================== --- qemu.orig/qemu-nbd.c 2011-03-08 20:11:08.244217894 +0100 +++ qemu/qemu-nbd.c 2011-03-08 20:11:22.253267426 +0100 @@ -238,7 +238,7 @@ int main(int argc, char **argv) flags |= BDRV_O_SNAPSHOT; break; case 'n': - flags |= BDRV_O_NOCACHE; + flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; break; case 'b': bindto = optarg;