[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH nbdkit 2/2] cow: Ignore flush/FUA requests.



There's no point flushing the overlay - a temporary file which has
been deleted and is discarded as soon as nbdkit exits.  We can gain
some performance by avoiding pointlessly flushing the overlay to disk.

I also changed can_fua to return NBDKIT_FUA_NATIVE so that
NBDKIT_FLAG_FUA is actually being set, rather than nbdkit emulating it
with a call to .flush.
---
 filters/cow/blk.h |  3 ---
 filters/cow/blk.c | 19 ++-----------------
 filters/cow/cow.c | 19 +++++++------------
 3 files changed, 9 insertions(+), 32 deletions(-)

diff --git a/filters/cow/blk.h b/filters/cow/blk.h
index a50b6ca3..28ef3b4a 100644
--- a/filters/cow/blk.h
+++ b/filters/cow/blk.h
@@ -77,7 +77,4 @@ extern int blk_cache (struct nbdkit_next_ops *next_ops, void *nxdata,
 extern int blk_write (uint64_t blknum, const uint8_t *block, int *err)
   __attribute__((__nonnull__ (2, 3)));
 
-/* Flush the overlay to disk. */
-extern int blk_flush (void);
-
 #endif /* NBDKIT_BLK_H */
diff --git a/filters/cow/blk.c b/filters/cow/blk.c
index 10af4a84..9e85920f 100644
--- a/filters/cow/blk.c
+++ b/filters/cow/blk.c
@@ -54,9 +54,8 @@
  * When writing a block we unconditionally write the data to the
  * temporary file, setting the bit in the bitmap.
  *
- * We allow the client to request FUA, and emulate it with a flush
- * (arguably, since the write overlay is temporary, we could ignore
- * FUA altogether).
+ * Since the overlay is a deleted temporary file, we can ignore FUA
+ * and flush commands.
  */
 
 #include <config.h>
@@ -260,17 +259,3 @@ blk_write (uint64_t blknum, const uint8_t *block, int *err)
 
   return 0;
 }
-
-int
-blk_flush (void)
-{
-  /* I think we don't care about file metadata for this temporary
-   * file, so only flush the data.
-   */
-  if (fdatasync (fd) == -1) {
-    nbdkit_error ("fdatasync: %m");
-    return -1;
-  }
-
-  return 0;
-}
diff --git a/filters/cow/cow.c b/filters/cow/cow.c
index cbb072f1..92358375 100644
--- a/filters/cow/cow.c
+++ b/filters/cow/cow.c
@@ -171,7 +171,7 @@ cow_can_flush (struct nbdkit_next_ops *next_ops, void *nxdata, void *handle)
 static int
 cow_can_fua (struct nbdkit_next_ops *next_ops, void *nxdata, void *handle)
 {
-  return NBDKIT_FUA_EMULATE;
+  return NBDKIT_FUA_NATIVE;
 }
 
 static int
@@ -343,8 +343,8 @@ cow_pwrite (struct nbdkit_next_ops *next_ops, void *nxdata,
       return -1;
   }
 
-  if (flags & NBDKIT_FLAG_FUA)
-    return cow_flush (next_ops, nxdata, handle, 0, err);
+  /* flags & NBDKIT_FLAG_FUA is deliberately ignored. */
+
   return 0;
 }
 
@@ -426,8 +426,8 @@ cow_zero (struct nbdkit_next_ops *next_ops, void *nxdata,
       return -1;
   }
 
-  if (flags & NBDKIT_FLAG_FUA)
-    return cow_flush (next_ops, nxdata, handle, 0, err);
+  /* flags & NBDKIT_FLAG_FUA is deliberately ignored. */
+
   return 0;
 }
 
@@ -435,13 +435,8 @@ static int
 cow_flush (struct nbdkit_next_ops *next_ops, void *nxdata, void *handle,
            uint32_t flags, int *err)
 {
-  int r;
-
-  ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lock);
-  r = blk_flush ();
-  if (r == -1)
-    *err = errno;
-  return r;
+  /* Deliberately ignored. */
+  return 0;
 }
 
 static int
-- 
2.29.0.rc2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]