Patchwork block: clarify the meaning of BDRV_O_NOCACHE

login
register
mail settings
Submitter Christoph Hellwig
Date May 17, 2011, 4:04 p.m.
Message ID <20110517160406.GA28196@lst.de>
Download mbox | patch
Permalink /patch/95952/
State New
Headers show

Comments

Christoph Hellwig - May 17, 2011, 4:04 p.m.
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 <hch@lst.de>
Kevin Wolf - May 24, 2011, 3:02 p.m.
Am 17.05.2011 18:04, schrieb Christoph Hellwig:
> 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 <hch@lst.de>

Thanks, applied to the block branch.

Changing bdrv_pwrite_sync wouldn't hurt, but it's harmless, so we can do
it on top.

Kevin

Patch

Index: qemu/block.c
===================================================================
--- qemu.orig/block.c	2011-05-17 17:49:12.398089706 +0200
+++ qemu/block.c	2011-05-17 17:50:30.590590280 +0200
@@ -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-04-21 09:57:20.727842564 +0200
+++ qemu/block/raw-posix.c	2011-05-17 17:50:30.594593138 +0200
@@ -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-04-21 09:57:20.741175824 +0200
+++ qemu/block/raw-win32.c	2011-05-17 17:50:30.594593138 +0200
@@ -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-04-21 09:57:43.614385242 +0200
+++ qemu/blockdev.c	2011-05-17 17:50:30.598590965 +0200
@@ -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-04-21 09:57:20.771175661 +0200
+++ qemu/qemu-io.c	2011-05-17 17:50:30.602624947 +0200
@@ -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-04-21 09:57:20.784508924 +0200
+++ qemu/qemu-nbd.c	2011-05-17 17:50:30.602624947 +0200
@@ -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;
Index: qemu/block/qcow2.c
===================================================================
--- qemu.orig/block/qcow2.c	2011-05-17 17:52:34.879589377 +0200
+++ qemu/block/qcow2.c	2011-05-17 17:54:01.966091025 +0200
@@ -229,7 +229,7 @@  static int qcow2_open(BlockDriverState *
     }
 
     /* alloc L2 table/refcount block cache */
-    writethrough = ((flags & BDRV_O_CACHE_MASK) == 0);
+    writethrough = ((flags & BDRV_O_CACHE_WB) == 0);
     s->l2_table_cache = qcow2_cache_create(bs, L2_CACHE_SIZE, writethrough);
     s->refcount_block_cache = qcow2_cache_create(bs, REFCOUNT_CACHE_SIZE,
         writethrough);