[Libguestfs] [nbdkit PATCH v3 13/15] null: Wire up FUA flag support

Eric Blake eblake at redhat.com
Thu Mar 8 23:03:09 UTC 2018


Since the null plugin already does nothing during writes, it can be
argued that those writes have already landed on persistent storage
(we know that we will read back zeros without any further delays).
Instead of advertising that the client cannot flush or FUA, we can
enable a few more callbacks to get instant native FUA support.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 plugins/null/null.c | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/plugins/null/null.c b/plugins/null/null.c
index d469963..905cc64 100644
--- a/plugins/null/null.c
+++ b/plugins/null/null.c
@@ -1,5 +1,5 @@
 /* nbdkit
- * Copyright (C) 2017 Red Hat Inc.
+ * Copyright (C) 2017-2018 Red Hat Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -39,6 +39,8 @@
 #include <string.h>
 #include <errno.h>

+#define NBDKIT_API_VERSION 2
+
 #include <nbdkit-plugin.h>

 /* The size of disk in bytes (initialized by size=<SIZE> parameter). */
@@ -111,7 +113,8 @@ null_get_size (void *handle)

 /* Read data. */
 static int
-null_pread (void *handle, void *buf, uint32_t count, uint64_t offset)
+null_pread (void *handle, void *buf, uint32_t count, uint64_t offset,
+            uint32_t flags)
 {
   memset (buf, 0, count);
   return 0;
@@ -119,7 +122,16 @@ null_pread (void *handle, void *buf, uint32_t count, uint64_t offset)

 /* Write data. */
 static int
-null_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset)
+null_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset,
+             uint32_t flags)
+{
+  /* nothing */
+  return 0;
+}
+
+/* Write zeros. */
+static int
+null_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
 {
   /* nothing */
   return 0;
@@ -133,14 +145,28 @@ null_can_write (void *handle)
   return !h->readonly;
 }

-/* Write zeroes - very efficient! */
+/* Flush is a no-op, so advertise native FUA support */
 static int
-null_zero (void *handle, uint32_t count, uint64_t offset, int may_trim)
+null_can_fua (void *handle)
+{
+  return NBDKIT_FUA_NATIVE;
+}
+
+/* Trim. */
+static int
+null_trim (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
 {
   /* nothing */
   return 0;
 }

+/* Nothing is persistent, so flush is trivially supported */
+static int
+null_flush (void *handle, uint32_t flags)
+{
+  return 0;
+}
+
 static struct nbdkit_plugin plugin = {
   .name              = "null",
   .version           = PACKAGE_VERSION,
@@ -152,7 +178,11 @@ static struct nbdkit_plugin plugin = {
   .pread             = null_pread,
   .pwrite            = null_pwrite,
   .can_write         = null_can_write,
-  .zero              = null_zero,
+  .zero              = null_trim,
+  .trim              = null_zero,
+  .can_trim          = null_can_write,
+  .can_fua           = null_can_fua,
+  .flush             = null_flush,
   /* In this plugin, errno is preserved properly along error return
    * paths from failed system calls.
    */
-- 
2.14.3




More information about the Libguestfs mailing list