[Libguestfs] [nbdkit PATCH v2 2/6] Revert "filters: Remove most next_* wrappers"

Eric Blake eblake at redhat.com
Thu Feb 25 20:59:43 UTC 2021


This reverts commit 2b29d6115d67e1cc6e96c1cb17e8a7fd1b10b336.

It turns out the next_* wrappers are going to be important after all
in order to implement the multi-conn filter, as well as our eventual
goal of allowing filters to open up a background handle into the
plugin that can be shared among multiple connections into the filter.
The reason is that void *nxdata will need to track the struct handle*
associated with a given entry into the next layer.

The backport is more complex than the original patch, due to the
addition of new callbacks, as well as several filters that used the
typedef nbdkit_backend instead of void*.  Still, it's fairly
mechanical.
---
 docs/nbdkit-filter.pod          |   4 +-
 include/nbdkit-filter.h         | 145 +++++++++----------
 server/internal.h               |   1 -
 server/extents.c                |   7 +-
 server/filters.c                | 247 ++++++++++++++++++++++++++++----
 filters/checkwrite/checkwrite.c |   2 +-
 filters/exitlast/exitlast.c     |   2 +-
 filters/exitwhen/exitwhen.c     |   2 +-
 filters/gzip/gzip.c             |   2 +-
 filters/limit/limit.c           |   6 +-
 filters/log/log.c               |   2 +-
 filters/tar/tar.c               |   2 +-
 12 files changed, 298 insertions(+), 124 deletions(-)

diff --git a/docs/nbdkit-filter.pod b/docs/nbdkit-filter.pod
index 98a08ca4..0f1ef8b6 100644
--- a/docs/nbdkit-filter.pod
+++ b/docs/nbdkit-filter.pod
@@ -865,7 +865,7 @@ extents covering the region C<[offset..offset+count-1]>.

  struct nbdkit_extents *nbdkit_extents_full (
                              struct nbdkit_next_ops *next_ops,
-                             nbdkit_backend *nxdata,
+                             void *nxdata,
                              uint32_t count, uint64_t offset,
                              uint32_t flags, int *err);

@@ -885,7 +885,7 @@ A convenience function is provided to filters only which makes it
 easier to ensure that the client only encounters aligned extents.

  int nbdkit_extents_aligned (struct nbdkit_next_ops *next_ops,
-                             nbdkit_backend *nxdata,
+                             void *nxdata,
                              uint32_t count, uint64_t offset,
                              uint32_t flags, uint32_t align,
                              struct nbdkit_extents *extents, int *err);
diff --git a/include/nbdkit-filter.h b/include/nbdkit-filter.h
index 0964c6e7..62efca07 100644
--- a/include/nbdkit-filter.h
+++ b/include/nbdkit-filter.h
@@ -1,5 +1,5 @@
 /* nbdkit
- * Copyright (C) 2013-2020 Red Hat Inc.
+ * Copyright (C) 2013-2021 Red Hat Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -49,65 +49,56 @@ extern "C" {
 #define NBDKIT_ZERO_EMULATE  1
 #define NBDKIT_ZERO_NATIVE   2

-#ifdef NBDKIT_INTERNAL
-/* Opaque type encapsulating all information needed for calling into
- * the next filter or plugin.
- */
-typedef struct backend nbdkit_backend;
-#else
-typedef void nbdkit_backend;
-#endif
-
 /* Next ops. */
-typedef int nbdkit_next_config (nbdkit_backend *nxdata,
+typedef int nbdkit_next_config (void *nxdata,
                                 const char *key, const char *value);
-typedef int nbdkit_next_config_complete (nbdkit_backend *nxdata);
-typedef int nbdkit_next_get_ready (nbdkit_backend *nxdata);
-typedef int nbdkit_next_after_fork (nbdkit_backend *nxdata);
-typedef int nbdkit_next_preconnect (nbdkit_backend *nxdata, int readonly);
-typedef int nbdkit_next_list_exports (nbdkit_backend *nxdata, int readonly,
+typedef int nbdkit_next_config_complete (void *nxdata);
+typedef int nbdkit_next_get_ready (void *nxdata);
+typedef int nbdkit_next_after_fork (void *nxdata);
+typedef int nbdkit_next_preconnect (void *nxdata, int readonly);
+typedef int nbdkit_next_list_exports (void *nxdata, int readonly,
                                       struct nbdkit_exports *exports);
-typedef const char *nbdkit_next_default_export (nbdkit_backend *nxdata,
+typedef const char *nbdkit_next_default_export (void *nxdata,
                                                 int readonly);
-typedef int nbdkit_next_open (nbdkit_backend *nxdata,
+typedef int nbdkit_next_open (void *nxdata,
                               int readonly, const char *exportname);

 struct nbdkit_next_ops {
   /* Performs close + open on the underlying chain.
    * Used by the retry filter.
    */
-  int (*reopen) (nbdkit_backend *nxdata, int readonly, const char *exportname);
+  int (*reopen) (void *nxdata, int readonly, const char *exportname);

   /* The rest of the next ops are the same as normal plugin operations. */
-  int64_t (*get_size) (nbdkit_backend *nxdata);
-  const char * (*export_description) (nbdkit_backend *nxdata);
+  int64_t (*get_size) (void *nxdata);
+  const char * (*export_description) (void *nxdata);

-  int (*can_write) (nbdkit_backend *nxdata);
-  int (*can_flush) (nbdkit_backend *nxdata);
-  int (*is_rotational) (nbdkit_backend *nxdata);
-  int (*can_trim) (nbdkit_backend *nxdata);
-  int (*can_zero) (nbdkit_backend *nxdata);
-  int (*can_fast_zero) (nbdkit_backend *nxdata);
-  int (*can_extents) (nbdkit_backend *nxdata);
-  int (*can_fua) (nbdkit_backend *nxdata);
-  int (*can_multi_conn) (nbdkit_backend *nxdata);
-  int (*can_cache) (nbdkit_backend *nxdata);
+  int (*can_write) (void *nxdata);
+  int (*can_flush) (void *nxdata);
+  int (*is_rotational) (void *nxdata);
+  int (*can_trim) (void *nxdata);
+  int (*can_zero) (void *nxdata);
+  int (*can_fast_zero) (void *nxdata);
+  int (*can_extents) (void *nxdata);
+  int (*can_fua) (void *nxdata);
+  int (*can_multi_conn) (void *nxdata);
+  int (*can_cache) (void *nxdata);

-  int (*pread) (nbdkit_backend *nxdata,
+  int (*pread) (void *nxdata,
                 void *buf, uint32_t count, uint64_t offset,
                 uint32_t flags, int *err);
-  int (*pwrite) (nbdkit_backend *nxdata,
+  int (*pwrite) (void *nxdata,
                  const void *buf, uint32_t count, uint64_t offset,
                  uint32_t flags, int *err);
-  int (*flush) (nbdkit_backend *nxdata, uint32_t flags, int *err);
-  int (*trim) (nbdkit_backend *nxdata, uint32_t count, uint64_t offset,
-               uint32_t flags, int *err);
-  int (*zero) (nbdkit_backend *nxdata, uint32_t count, uint64_t offset,
-               uint32_t flags, int *err);
-  int (*extents) (nbdkit_backend *nxdata, uint32_t count, uint64_t offset,
-                  uint32_t flags, struct nbdkit_extents *extents, int *err);
-  int (*cache) (nbdkit_backend *nxdata, uint32_t count, uint64_t offset,
-                uint32_t flags, int *err);
+  int (*flush) (void *nxdata, uint32_t flags, int *err);
+  int (*trim) (void *nxdata, uint32_t count, uint64_t offset, uint32_t flags,
+               int *err);
+  int (*zero) (void *nxdata, uint32_t count, uint64_t offset, uint32_t flags,
+               int *err);
+  int (*extents) (void *nxdata, uint32_t count, uint64_t offset, uint32_t flags,
+                  struct nbdkit_extents *extents, int *err);
+  int (*cache) (void *nxdata, uint32_t count, uint64_t offset, uint32_t flags,
+                int *err);
 };

 /* Extent functions. */
@@ -117,7 +108,7 @@ struct nbdkit_extent {
   uint32_t type;
 };

-NBDKIT_EXTERN_DECL (struct nbdkit_extents *,nbdkit_extents_new,
+NBDKIT_EXTERN_DECL (struct nbdkit_extents *, nbdkit_extents_new,
                     (uint64_t start, uint64_t end));
 NBDKIT_EXTERN_DECL (void, nbdkit_extents_free, (struct nbdkit_extents *));
 NBDKIT_EXTERN_DECL (size_t, nbdkit_extents_count,
@@ -126,12 +117,12 @@ NBDKIT_EXTERN_DECL (struct nbdkit_extent, nbdkit_get_extent,
                     (const struct nbdkit_extents *, size_t));
 NBDKIT_EXTERN_DECL (struct nbdkit_extents *, nbdkit_extents_full,
                     (struct nbdkit_next_ops *next_ops,
-                     nbdkit_backend *nxdata,
+                     void *nxdata,
                      uint32_t count, uint64_t offset,
                      uint32_t flags, int *err));
 NBDKIT_EXTERN_DECL (int, nbdkit_extents_aligned,
                     (struct nbdkit_next_ops *next_ops,
-                     nbdkit_backend *nxdata,
+                     void *nxdata,
                      uint32_t count, uint64_t offset,
                      uint32_t flags, uint32_t align,
                      struct nbdkit_extents *extents, int *err));
@@ -172,78 +163,78 @@ struct nbdkit_filter {
   void (*load) (void);
   void (*unload) (void);

-  int (*config) (nbdkit_next_config *next, nbdkit_backend *nxdata,
+  int (*config) (nbdkit_next_config *next, void *nxdata,
                  const char *key, const char *value);
-  int (*config_complete) (nbdkit_next_config_complete *next,
-                          nbdkit_backend *nxdata);
+  int (*config_complete) (nbdkit_next_config_complete *next, void *nxdata);
   const char *config_help;
   int (*thread_model) (void);
-  int (*get_ready) (nbdkit_next_get_ready *next, nbdkit_backend *nxdata,
+  int (*get_ready) (nbdkit_next_get_ready *next, void *nxdata,
                     int thread_model);
-  int (*after_fork) (nbdkit_next_after_fork *next, nbdkit_backend *nxdata);
-  int (*preconnect) (nbdkit_next_preconnect *next, nbdkit_backend *nxdata,
+  int (*after_fork) (nbdkit_next_after_fork *next, void *nxdata);
+  int (*preconnect) (nbdkit_next_preconnect *next, void *nxdata,
                      int readonly);
-  int (*list_exports) (nbdkit_next_list_exports *next, nbdkit_backend *nxdata,
+  int (*list_exports) (nbdkit_next_list_exports *next, void *nxdata,
                        int readonly, int is_tls,
                        struct nbdkit_exports *exports);
   const char * (*default_export) (nbdkit_next_default_export *next,
-                                  nbdkit_backend *nxdata,
+                                  void *nxdata,
                                   int readonly, int is_tls);

-  void * (*open) (nbdkit_next_open *next, nbdkit_backend *nxdata,
+  void * (*open) (nbdkit_next_open *next, void *nxdata,
                   int readonly, const char *exportname, int is_tls);
   void (*close) (void *handle);

-  int (*prepare) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*prepare) (struct nbdkit_next_ops *next_ops, void *nxdata,
                   void *handle, int readonly);
-  int (*finalize) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*finalize) (struct nbdkit_next_ops *next_ops, void *nxdata,
                    void *handle);

-  int64_t (*get_size) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int64_t (*get_size) (struct nbdkit_next_ops *next_ops, void *nxdata,
                        void *handle);
   const char * (*export_description) (struct nbdkit_next_ops *next_ops,
-                                      nbdkit_backend *nxdata, void *handle);
+                                      void *nxdata, void *handle);

-  int (*can_write) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*can_write) (struct nbdkit_next_ops *next_ops, void *nxdata,
                     void *handle);
-  int (*can_flush) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*can_flush) (struct nbdkit_next_ops *next_ops, void *nxdata,
                     void *handle);
   int (*is_rotational) (struct nbdkit_next_ops *next_ops,
-                        nbdkit_backend *nxdata, void *handle);
-  int (*can_trim) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+                        void *nxdata,
+                        void *handle);
+  int (*can_trim) (struct nbdkit_next_ops *next_ops, void *nxdata,
                    void *handle);
-  int (*can_zero) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*can_zero) (struct nbdkit_next_ops *next_ops, void *nxdata,
                    void *handle);
-  int (*can_fast_zero) (struct nbdkit_next_ops *next_ops,
-                        nbdkit_backend *nxdata, void *handle);
-  int (*can_extents) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*can_fast_zero) (struct nbdkit_next_ops *next_ops, void *nxdata,
+                        void *handle);
+  int (*can_extents) (struct nbdkit_next_ops *next_ops, void *nxdata,
                       void *handle);
-  int (*can_fua) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*can_fua) (struct nbdkit_next_ops *next_ops, void *nxdata,
                   void *handle);
-  int (*can_multi_conn) (struct nbdkit_next_ops *next_ops,
-                         nbdkit_backend *nxdata, void *handle);
-  int (*can_cache) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*can_multi_conn) (struct nbdkit_next_ops *next_ops, void *nxdata,
+                         void *handle);
+  int (*can_cache) (struct nbdkit_next_ops *next_ops, void *nxdata,
                     void *handle);

-  int (*pread) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*pread) (struct nbdkit_next_ops *next_ops, void *nxdata,
                 void *handle, void *buf, uint32_t count, uint64_t offset,
                 uint32_t flags, int *err);
-  int (*pwrite) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*pwrite) (struct nbdkit_next_ops *next_ops, void *nxdata,
                  void *handle,
                  const void *buf, uint32_t count, uint64_t offset,
                  uint32_t flags, int *err);
-  int (*flush) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*flush) (struct nbdkit_next_ops *next_ops, void *nxdata,
                 void *handle, uint32_t flags, int *err);
-  int (*trim) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*trim) (struct nbdkit_next_ops *next_ops, void *nxdata,
                void *handle, uint32_t count, uint64_t offset, uint32_t flags,
                int *err);
-  int (*zero) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*zero) (struct nbdkit_next_ops *next_ops, void *nxdata,
                void *handle, uint32_t count, uint64_t offset, uint32_t flags,
                int *err);
-  int (*extents) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*extents) (struct nbdkit_next_ops *next_ops, void *nxdata,
                   void *handle, uint32_t count, uint64_t offset, uint32_t flags,
                   struct nbdkit_extents *extents, int *err);
-  int (*cache) (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+  int (*cache) (struct nbdkit_next_ops *next_ops, void *nxdata,
                 void *handle, uint32_t count, uint64_t offset, uint32_t flags,
                 int *err);
 };
diff --git a/server/internal.h b/server/internal.h
index b999b856..06105d79 100644
--- a/server/internal.h
+++ b/server/internal.h
@@ -43,7 +43,6 @@
 #endif

 #define NBDKIT_API_VERSION 2
-#define NBDKIT_INTERNAL
 #include "nbdkit-plugin.h"
 #include "nbdkit-filter.h"
 #include "cleanup.h"
diff --git a/server/extents.c b/server/extents.c
index cbc0f0dd..a509bc94 100644
--- a/server/extents.c
+++ b/server/extents.c
@@ -1,5 +1,5 @@
 /* nbdkit
- * Copyright (C) 2019-2020 Red Hat Inc.
+ * Copyright (C) 2019-2021 Red Hat Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -212,8 +212,7 @@ nbdkit_add_extent (struct nbdkit_extents *exts,

 /* Compute aligned extents on behalf of a filter. */
 int
-nbdkit_extents_aligned (struct nbdkit_next_ops *next_ops,
-                        nbdkit_backend *nxdata,
+nbdkit_extents_aligned (struct nbdkit_next_ops *next_ops, void *nxdata,
                         uint32_t count, uint64_t offset,
                         uint32_t flags, uint32_t align,
                         struct nbdkit_extents *exts, int *err)
@@ -298,7 +297,7 @@ nbdkit_extents_aligned (struct nbdkit_next_ops *next_ops,
  * covering the region [offset..offset+count-1].
  */
 struct nbdkit_extents *
-nbdkit_extents_full (struct nbdkit_next_ops *next_ops, nbdkit_backend *nxdata,
+nbdkit_extents_full (struct nbdkit_next_ops *next_ops, void *nxdata,
                      uint32_t count, uint64_t offset, uint32_t flags,
                      int *err)
 {
diff --git a/server/filters.c b/server/filters.c
index 54abf9a4..f4dbfea7 100644
--- a/server/filters.c
+++ b/server/filters.c
@@ -1,5 +1,5 @@
 /* nbdkit
- * Copyright (C) 2013-2020 Red Hat Inc.
+ * Copyright (C) 2013-2021 Red Hat Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -127,8 +127,9 @@ filter_dump_fields (struct backend *b)
 }

 static int
-next_config (struct backend *b, const char *key, const char *value)
+next_config (void *nxdata, const char *key, const char *value)
 {
+  struct backend *b = nxdata;
   b->config (b, key, value);
   return 0;
 }
@@ -150,8 +151,9 @@ filter_config (struct backend *b, const char *key, const char *value)
 }

 static int
-next_config_complete (struct backend *b)
+next_config_complete (void *nxdata)
 {
+  struct backend *b = nxdata;
   b->config_complete (b);
   return 0;
 }
@@ -172,9 +174,10 @@ filter_config_complete (struct backend *b)
 }

 static int
-next_get_ready (struct backend *b)
+next_get_ready (void *nxdata)
 {
-  b->get_ready (b);
+  struct backend *b_next = nxdata;
+  b_next->get_ready (b_next);
   return 0;
 }

@@ -194,9 +197,10 @@ filter_get_ready (struct backend *b)
 }

 static int
-next_after_fork (struct backend *b)
+next_after_fork (void *nxdata)
 {
-  b->after_fork (b);
+  struct backend *b_next = nxdata;
+  b_next->after_fork (b_next);
   return 0;
 }

@@ -215,6 +219,13 @@ filter_after_fork (struct backend *b)
     b->next->after_fork (b->next);
 }

+static int
+next_preconnect (void *nxdata, int readonly)
+{
+  struct backend *b_next = nxdata;
+  return b_next->preconnect (b_next, readonly);
+}
+
 static int
 filter_preconnect (struct backend *b, int readonly)
 {
@@ -223,7 +234,7 @@ filter_preconnect (struct backend *b, int readonly)
   debug ("%s: preconnect", b->name);

   if (f->filter.preconnect)
-    return f->filter.preconnect (b->next->preconnect, b->next, readonly);
+    return f->filter.preconnect (next_preconnect, b->next, readonly);
   else
     return b->next->preconnect (b->next, readonly);
 }
@@ -237,6 +248,13 @@ plugin_magic_config_key (struct backend *b)
   return b->next->magic_config_key (b->next);
 }

+static int
+next_list_exports (void *nxdata, int readonly, struct  nbdkit_exports *exports)
+{
+  struct backend *b_next = nxdata;
+  return backend_list_exports (b_next, readonly, exports);
+}
+
 static int
 filter_list_exports (struct backend *b, int readonly, int is_tls,
                      struct nbdkit_exports *exports)
@@ -244,22 +262,37 @@ filter_list_exports (struct backend *b, int readonly, int is_tls,
   struct backend_filter *f = container_of (b, struct backend_filter, backend);

   if (f->filter.list_exports)
-    return f->filter.list_exports (backend_list_exports, b->next,
+    return f->filter.list_exports (next_list_exports, b->next,
                                    readonly, is_tls, exports);
   return backend_list_exports (b->next, readonly, exports);
 }

+static const char *
+next_default_export (void *nxdata, int readonly)
+{
+  struct backend *b_next = nxdata;
+  return backend_default_export (b_next, readonly);
+}
+
 static const char *
 filter_default_export (struct backend *b, int readonly, int is_tls)
 {
   struct backend_filter *f = container_of (b, struct backend_filter, backend);

   if (f->filter.default_export)
-    return f->filter.default_export (backend_default_export, b->next,
+    return f->filter.default_export (next_default_export, b->next,
                                      readonly, is_tls);
   return backend_default_export (b->next, readonly);
 }

+static int
+next_open (void *nxdata, int readonly, const char *exportname)
+{
+  struct backend *b_next = nxdata;
+
+  return backend_open (b_next, readonly, exportname);
+}
+
 static void *
 filter_open (struct backend *b, int readonly, const char *exportname,
              int is_tls)
@@ -271,7 +304,7 @@ filter_open (struct backend *b, int readonly, const char *exportname,
    * inner-to-outer ordering.
    */
   if (f->filter.open)
-    handle = f->filter.open (backend_open, b->next, readonly, exportname,
+    handle = f->filter.open (next_open, b->next, readonly, exportname,
                              is_tls);
   else if (backend_open (b->next, readonly, exportname) == -1)
     handle = NULL;
@@ -289,27 +322,179 @@ filter_close (struct backend *b, void *handle)
     f->filter.close (handle);
 }

+/* The next_functions structure contains pointers to backend
+ * functions.  These are only needed for type safety (nxdata is void
+ * pointer, backend_* functions expect a struct backend * parameter).
+ * nxdata is a pointer to the next backend in the linked list.
+ */
+
+static int
+next_reopen (void *nxdata, int readonly, const char *exportname)
+{
+  struct backend *b_next = nxdata;
+  return backend_reopen (b_next, readonly, exportname);
+}
+
+static int64_t
+next_get_size (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_get_size (b_next);
+}
+
+static const char *
+next_export_description (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_export_description (b_next);
+}
+
+static int
+next_can_write (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_can_write (b_next);
+}
+
+static int
+next_can_flush (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_can_flush (b_next);
+}
+
+static int
+next_is_rotational (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_is_rotational (b_next);
+}
+
+static int
+next_can_trim (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_can_trim (b_next);
+}
+
+static int
+next_can_zero (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_can_zero (b_next);
+}
+
+static int
+next_can_fast_zero (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_can_fast_zero (b_next);
+}
+
+static int
+next_can_extents (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_can_extents (b_next);
+}
+
+static int
+next_can_fua (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_can_fua (b_next);
+}
+
+static int
+next_can_multi_conn (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_can_multi_conn (b_next);
+}
+
+static int
+next_can_cache (void *nxdata)
+{
+  struct backend *b_next = nxdata;
+  return backend_can_cache (b_next);
+}
+
+static int
+next_pread (void *nxdata, void *buf, uint32_t count, uint64_t offset,
+            uint32_t flags, int *err)
+{
+  struct backend *b_next = nxdata;
+  return backend_pread (b_next, buf, count, offset, flags, err);
+}
+
+static int
+next_pwrite (void *nxdata, const void *buf, uint32_t count, uint64_t offset,
+             uint32_t flags, int *err)
+{
+  struct backend *b_next = nxdata;
+  return backend_pwrite (b_next, buf, count, offset, flags, err);
+}
+
+static int
+next_flush (void *nxdata, uint32_t flags, int *err)
+{
+  struct backend *b_next = nxdata;
+  return backend_flush (b_next, flags, err);
+}
+
+static int
+next_trim (void *nxdata, uint32_t count, uint64_t offset, uint32_t flags,
+           int *err)
+{
+  struct backend *b_next = nxdata;
+  return backend_trim (b_next, count, offset, flags, err);
+}
+
+static int
+next_zero (void *nxdata, uint32_t count, uint64_t offset, uint32_t flags,
+           int *err)
+{
+  struct backend *b_next = nxdata;
+  return backend_zero (b_next, count, offset, flags, err);
+}
+
+static int
+next_extents (void *nxdata, uint32_t count, uint64_t offset, uint32_t flags,
+              struct nbdkit_extents *extents, int *err)
+{
+  struct backend *b_next = nxdata;
+  return backend_extents (b_next, count, offset, flags, extents, err);
+}
+
+static int
+next_cache (void *nxdata, uint32_t count, uint64_t offset,
+            uint32_t flags, int *err)
+{
+  struct backend *b_next = nxdata;
+  return backend_cache (b_next, count, offset, flags, err);
+}
+
 static struct nbdkit_next_ops next_ops = {
-  .reopen = backend_reopen,
-  .export_description = backend_export_description,
-  .get_size = backend_get_size,
-  .can_write = backend_can_write,
-  .can_flush = backend_can_flush,
-  .is_rotational = backend_is_rotational,
-  .can_trim = backend_can_trim,
-  .can_zero = backend_can_zero,
-  .can_fast_zero = backend_can_fast_zero,
-  .can_extents = backend_can_extents,
-  .can_fua = backend_can_fua,
-  .can_multi_conn = backend_can_multi_conn,
-  .can_cache = backend_can_cache,
-  .pread = backend_pread,
-  .pwrite = backend_pwrite,
-  .flush = backend_flush,
-  .trim = backend_trim,
-  .zero = backend_zero,
-  .extents = backend_extents,
-  .cache = backend_cache,
+  .reopen = next_reopen,
+  .export_description = next_export_description,
+  .get_size = next_get_size,
+  .can_write = next_can_write,
+  .can_flush = next_can_flush,
+  .is_rotational = next_is_rotational,
+  .can_trim = next_can_trim,
+  .can_zero = next_can_zero,
+  .can_fast_zero = next_can_fast_zero,
+  .can_extents = next_can_extents,
+  .can_fua = next_can_fua,
+  .can_multi_conn = next_can_multi_conn,
+  .can_cache = next_can_cache,
+  .pread = next_pread,
+  .pwrite = next_pwrite,
+  .flush = next_flush,
+  .trim = next_trim,
+  .zero = next_zero,
+  .extents = next_extents,
+  .cache = next_cache,
 };

 static int
diff --git a/filters/checkwrite/checkwrite.c b/filters/checkwrite/checkwrite.c
index bbd7f1cd..99ba2845 100644
--- a/filters/checkwrite/checkwrite.c
+++ b/filters/checkwrite/checkwrite.c
@@ -44,7 +44,7 @@
 #include "minmax.h"

 static void *
-checkwrite_open (nbdkit_next_open *next, nbdkit_backend *nxdata,
+checkwrite_open (nbdkit_next_open *next, void *nxdata,
                  int readonly, const char *exportname, int is_tls)
 {
   /* Ignore readonly flag passed in, open the plugin readonly. */
diff --git a/filters/exitlast/exitlast.c b/filters/exitlast/exitlast.c
index 4c879cc9..c16b3948 100644
--- a/filters/exitlast/exitlast.c
+++ b/filters/exitlast/exitlast.c
@@ -50,7 +50,7 @@
 static _Atomic unsigned connections;

 static void *
-exitlast_open (nbdkit_next_open *next, nbdkit_backend *nxdata,
+exitlast_open (nbdkit_next_open *next, void *nxdata,
                int readonly, const char *exportname, int is_tls)
 {
   if (next (nxdata, readonly, exportname) == -1)
diff --git a/filters/exitwhen/exitwhen.c b/filters/exitwhen/exitwhen.c
index ca199a8c..bd1a4082 100644
--- a/filters/exitwhen/exitwhen.c
+++ b/filters/exitwhen/exitwhen.c
@@ -482,7 +482,7 @@ exitwhen_preconnect (nbdkit_next_preconnect *next, void *nxdata, int readonly)
 }

 static void *
-exitwhen_open (nbdkit_next_open *next, nbdkit_backend *nxdata,
+exitwhen_open (nbdkit_next_open *next, void *nxdata,
                int readonly, const char *exportname, int is_tls)
 {
   if (next (nxdata, readonly, exportname) == -1)
diff --git a/filters/gzip/gzip.c b/filters/gzip/gzip.c
index 03e023e5..71c703e6 100644
--- a/filters/gzip/gzip.c
+++ b/filters/gzip/gzip.c
@@ -75,7 +75,7 @@ gzip_thread_model (void)
 }

 static void *
-gzip_open (nbdkit_next_open *next, nbdkit_backend *nxdata,
+gzip_open (nbdkit_next_open *next, void *nxdata,
            int readonly, const char *exportname, int is_tls)
 {
   /* Always pass readonly=1 to the underlying plugin. */
diff --git a/filters/limit/limit.c b/filters/limit/limit.c
index fb862df7..f750b235 100644
--- a/filters/limit/limit.c
+++ b/filters/limit/limit.c
@@ -49,7 +49,7 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 static unsigned limit = 1;

 static int
-limit_config (nbdkit_next_config *next, nbdkit_backend *nxdata,
+limit_config (nbdkit_next_config *next, void *nxdata,
               const char *key, const char *value)
 {
   if (strcmp (key, "limit") == 0) {
@@ -73,7 +73,7 @@ too_many_clients_error (void)
  * out between preconnect and open.
  */
 static int
-limit_preconnect (nbdkit_next_preconnect *next, nbdkit_backend *nxdata,
+limit_preconnect (nbdkit_next_preconnect *next, void *nxdata,
                   int readonly)
 {
   if (next (nxdata, readonly) == -1)
@@ -90,7 +90,7 @@ limit_preconnect (nbdkit_next_preconnect *next, nbdkit_backend *nxdata,
 }

 static void *
-limit_open (nbdkit_next_open *next, nbdkit_backend *nxdata,
+limit_open (nbdkit_next_open *next, void *nxdata,
             int readonly, const char *exportname, int is_tls)
 {
   if (next (nxdata, readonly, exportname) == -1)
diff --git a/filters/log/log.c b/filters/log/log.c
index 7b81a8f1..8930fff3 100644
--- a/filters/log/log.c
+++ b/filters/log/log.c
@@ -187,7 +187,7 @@ log_list_exports (nbdkit_next_list_exports *next, void *nxdata,
 }

 static int
-log_preconnect (nbdkit_next_preconnect *next, nbdkit_backend *nxdata,
+log_preconnect (nbdkit_next_preconnect *next, void *nxdata,
                 int readonly)
 {
   static log_id_t id;
diff --git a/filters/tar/tar.c b/filters/tar/tar.c
index fa4b61dc..e4c5913e 100644
--- a/filters/tar/tar.c
+++ b/filters/tar/tar.c
@@ -112,7 +112,7 @@ struct handle {
 };

 static void *
-tar_open (nbdkit_next_open *next, nbdkit_backend *nxdata,
+tar_open (nbdkit_next_open *next, void *nxdata,
           int readonly, const char *exportname, int is_tls)
 {
   struct handle *h;
-- 
2.30.1




More information about the Libguestfs mailing list