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

[Libguestfs] [nbdkit PATCH v2 1/6] backend: Split out new backend_handle_* functions



This partially reverts the refactoring work of 91023f269d4 (server:
Remove explicit connection parameter, use TLS instead); but differs in
that it only needs struct handle* instead of the larger struct
connection*.  This patch lays the groundwork for an upcoming patch to
add the multi-conn filter, which wants to operate on more than one
handle into a plugin from a single connection from the client.  While
most callers will continue to get handle from TLS, now filters.c will
be able to go back to storing the handle per nxdata opaque pointer
passed to the filter.
---
 server/internal.h |  59 ++++++++++++++++++-
 server/backend.c  | 147 +++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 183 insertions(+), 23 deletions(-)

diff --git a/server/internal.h b/server/internal.h
index 906f0690..b999b856 100644
--- a/server/internal.h
+++ b/server/internal.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
@@ -441,8 +441,6 @@ extern int backend_list_exports (struct backend *b, int readonly,
   __attribute__((__nonnull__ (1, 3)));
 extern const char *backend_default_export (struct backend *b, int readonly)
   __attribute__((__nonnull__ (1)));
-extern const char *backend_export_description (struct backend *b)
-  __attribute__((__nonnull__ (1)));
 /* exportname is only valid for this call and almost certainly will be
  * freed on return of this function, so backends must save the
  * exportname if they need to refer to it later.
@@ -465,54 +463,109 @@ extern int backend_reopen (struct backend *b,
   __attribute__((__nonnull__ (1, 3)));
 extern int64_t backend_get_size (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int64_t backend_handle_get_size (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
+extern const char *backend_export_description (struct backend *b)
+  __attribute__((__nonnull__ (1)));
+extern const char *backend_handle_export_description (struct backend *b,
+                                                      struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_can_write (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_can_write (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_can_flush (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_can_flush (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_is_rotational (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_is_rotational (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_can_trim (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_can_trim (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_can_zero (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_can_zero (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_can_fast_zero (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_can_fast_zero (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_can_extents (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_can_extents (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_can_fua (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_can_fua (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_can_multi_conn (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_can_multi_conn (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));
 extern int backend_can_cache (struct backend *b)
   __attribute__((__nonnull__ (1)));
+extern int backend_handle_can_cache (struct backend *b, struct handle *h)
+  __attribute__((__nonnull__ (1, 2)));

 extern int backend_pread (struct backend *b,
                           void *buf, uint32_t count, uint64_t offset,
                           uint32_t flags, int *err)
   __attribute__((__nonnull__ (1, 2, 6)));
+extern int backend_handle_pread (struct backend *b, struct handle *h,
+                                 void *buf, uint32_t count, uint64_t offset,
+                                 uint32_t flags, int *err)
+  __attribute__((__nonnull__ (1, 2, 3, 7)));
 extern int backend_pwrite (struct backend *b,
                            const void *buf, uint32_t count, uint64_t offset,
                            uint32_t flags, int *err)
   __attribute__((__nonnull__ (1, 2, 6)));
+extern int backend_handle_pwrite (struct backend *b, struct handle *h,
+                                  const void *buf, uint32_t count,
+                                  uint64_t offset, uint32_t flags, int *err)
+  __attribute__((__nonnull__ (1, 2, 3, 7)));
 extern int backend_flush (struct backend *b,
                           uint32_t flags, int *err)
   __attribute__((__nonnull__ (1, 3)));
+extern int backend_handle_flush (struct backend *b, struct handle *h,
+                                 uint32_t flags, int *err)
+  __attribute__((__nonnull__ (1, 2, 4)));
 extern int backend_trim (struct backend *b,
                          uint32_t count, uint64_t offset, uint32_t flags,
                          int *err)
   __attribute__((__nonnull__ (1, 5)));
+extern int backend_handle_trim (struct backend *b, struct handle *h,
+                                uint32_t count, uint64_t offset,
+                                uint32_t flags, int *err)
+  __attribute__((__nonnull__ (1, 2, 6)));
 extern int backend_zero (struct backend *b,
                          uint32_t count, uint64_t offset, uint32_t flags,
                          int *err)
   __attribute__((__nonnull__ (1, 5)));
+extern int backend_handle_zero (struct backend *b, struct handle *h,
+                                uint32_t count, uint64_t offset,
+                                uint32_t flags, int *err)
+  __attribute__((__nonnull__ (1, 2, 6)));
 extern int backend_extents (struct backend *b,
                             uint32_t count, uint64_t offset, uint32_t flags,
                             struct nbdkit_extents *extents, int *err)
   __attribute__((__nonnull__ (1, 5, 6)));
+extern int backend_handle_extents (struct backend *b, struct handle *h,
+                                   uint32_t count, uint64_t offset,
+                                   uint32_t flags,
+                                   struct nbdkit_extents *extents, int *err)
+  __attribute__((__nonnull__ (1, 2, 6, 7)));
 extern int backend_cache (struct backend *b,
                           uint32_t count, uint64_t offset,
                           uint32_t flags, int *err)
   __attribute__((__nonnull__ (1, 5)));
+extern int backend_handle_cache (struct backend *b, struct handle *h,
+                                 uint32_t count, uint64_t offset,
+                                 uint32_t flags, int *err)
+  __attribute__((__nonnull__ (1, 2, 6)));

 /* plugins.c */
 extern struct backend *plugin_register (size_t index, const char *filename,
diff --git a/server/backend.c b/server/backend.c
index 3630163b..2b42ff9c 100644
--- a/server/backend.c
+++ b/server/backend.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
@@ -364,7 +364,12 @@ const char *
 backend_export_description (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_export_description (b, get_handle (conn, b->i));
+}
+
+const char *
+backend_handle_export_description (struct backend *b, struct handle *h)
+{
   const char *s;

   controlpath_debug ("%s: export_description", b->name);
@@ -386,8 +391,12 @@ int64_t
 backend_get_size (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_get_size (b, get_handle (conn, b->i));
+}

+int64_t
+backend_handle_get_size (struct backend *b, struct handle *h)
+{
   assert (h->handle && (h->state & HANDLE_CONNECTED));
   if (h->exportsize == -1) {
     controlpath_debug ("%s: get_size", b->name);
@@ -400,8 +409,12 @@ int
 backend_can_write (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_can_write (b, get_handle (conn, b->i));
+}

+int
+backend_handle_can_write (struct backend *b, struct handle *h)
+{
   assert (h->handle && (h->state & HANDLE_CONNECTED));
   if (h->can_write == -1) {
     controlpath_debug ("%s: can_write", b->name);
@@ -414,8 +427,12 @@ int
 backend_can_flush (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_can_flush (b, get_handle (conn, b->i));
+}

+int
+backend_handle_can_flush (struct backend *b, struct handle *h)
+{
   assert (h->handle && (h->state & HANDLE_CONNECTED));
   if (h->can_flush == -1) {
     controlpath_debug ("%s: can_flush", b->name);
@@ -428,8 +445,12 @@ int
 backend_is_rotational (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_is_rotational (b, get_handle (conn, b->i));
+}

+int
+backend_handle_is_rotational (struct backend *b, struct handle *h)
+{
   assert (h->handle && (h->state & HANDLE_CONNECTED));
   if (h->is_rotational == -1) {
     controlpath_debug ("%s: is_rotational", b->name);
@@ -442,7 +463,12 @@ int
 backend_can_trim (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_can_trim (b, get_handle (conn, b->i));
+}
+
+int
+backend_handle_can_trim (struct backend *b, struct handle *h)
+{
   int r;

   assert (h->handle && (h->state & HANDLE_CONNECTED));
@@ -462,7 +488,12 @@ int
 backend_can_zero (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_can_zero (b, get_handle (conn, b->i));
+}
+
+int
+backend_handle_can_zero (struct backend *b, struct handle *h)
+{
   int r;

   assert (h->handle && (h->state & HANDLE_CONNECTED));
@@ -482,7 +513,12 @@ int
 backend_can_fast_zero (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_can_fast_zero (b, get_handle (conn, b->i));
+}
+
+int
+backend_handle_can_fast_zero (struct backend *b, struct handle *h)
+{
   int r;

   assert (h->handle && (h->state & HANDLE_CONNECTED));
@@ -502,8 +538,12 @@ int
 backend_can_extents (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_can_extents (b, get_handle (conn, b->i));
+}

+int
+backend_handle_can_extents (struct backend *b, struct handle *h)
+{
   assert (h->handle && (h->state & HANDLE_CONNECTED));
   if (h->can_extents == -1) {
     controlpath_debug ("%s: can_extents", b->name);
@@ -516,7 +556,12 @@ int
 backend_can_fua (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_can_fua (b, get_handle (conn, b->i));
+}
+
+int
+backend_handle_can_fua (struct backend *b, struct handle *h)
+{
   int r;

   assert (h->handle && (h->state & HANDLE_CONNECTED));
@@ -536,8 +581,12 @@ int
 backend_can_multi_conn (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_can_multi_conn (b, get_handle (conn, b->i));
+}

+int
+backend_handle_can_multi_conn (struct backend *b, struct handle *h)
+{
   assert (h->handle && (h->state & HANDLE_CONNECTED));
   if (h->can_multi_conn == -1) {
     controlpath_debug ("%s: can_multi_conn", b->name);
@@ -550,8 +599,12 @@ int
 backend_can_cache (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_can_cache (b, get_handle (conn, b->i));
+}

+int
+backend_handle_can_cache (struct backend *b, struct handle *h)
+{
   assert (h->handle && (h->state & HANDLE_CONNECTED));
   if (h->can_cache == -1) {
     controlpath_debug ("%s: can_cache", b->name);
@@ -566,7 +619,15 @@ backend_pread (struct backend *b,
                uint32_t flags, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_pread (b, get_handle (conn, b->i), buf, count, offset,
+                               flags, err);
+}
+
+int
+backend_handle_pread (struct backend *b, struct handle *h,
+                      void *buf, uint32_t count, uint64_t offset,
+                      uint32_t flags, int *err)
+{
   int r;

   assert (h->handle && (h->state & HANDLE_CONNECTED));
@@ -587,7 +648,15 @@ backend_pwrite (struct backend *b,
                 uint32_t flags, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_pwrite (b, get_handle (conn, b->i), buf, count,
+                                offset, flags, err);
+}
+
+int
+backend_handle_pwrite (struct backend *b, struct handle *h,
+                       const void *buf, uint32_t count, uint64_t offset,
+                       uint32_t flags, int *err)
+{
   bool fua = !!(flags & NBDKIT_FLAG_FUA);
   int r;

@@ -611,7 +680,13 @@ backend_flush (struct backend *b,
                uint32_t flags, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_flush (b, get_handle (conn, b->i), flags, err);
+}
+
+int
+backend_handle_flush (struct backend *b, struct handle *h,
+                      uint32_t flags, int *err)
+{
   int r;

   assert (h->handle && (h->state & HANDLE_CONNECTED));
@@ -631,7 +706,15 @@ backend_trim (struct backend *b,
               int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_trim (b, get_handle (conn, b->i), count, offset,
+                              flags, err);
+}
+
+int
+backend_handle_trim (struct backend *b, struct handle *h,
+                     uint32_t count, uint64_t offset, uint32_t flags,
+                     int *err)
+{
   bool fua = !!(flags & NBDKIT_FLAG_FUA);
   int r;

@@ -657,7 +740,15 @@ backend_zero (struct backend *b,
               int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_zero (b, get_handle (conn, b->i), count, offset,
+                              flags, err);
+}
+
+int
+backend_handle_zero (struct backend *b, struct handle *h,
+                     uint32_t count, uint64_t offset, uint32_t flags,
+                     int *err)
+{
   bool fua = !!(flags & NBDKIT_FLAG_FUA);
   bool fast = !!(flags & NBDKIT_FLAG_FAST_ZERO);
   int r;
@@ -692,7 +783,15 @@ backend_extents (struct backend *b,
                  struct nbdkit_extents *extents, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_extents (b, get_handle (conn, b->i), count, offset,
+                                 flags, extents, err);
+}
+
+int
+backend_handle_extents (struct backend *b, struct handle *h,
+                        uint32_t count, uint64_t offset, uint32_t flags,
+                        struct nbdkit_extents *extents, int *err)
+{
   int r;

   assert (h->handle && (h->state & HANDLE_CONNECTED));
@@ -723,7 +822,15 @@ backend_cache (struct backend *b,
                uint32_t flags, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  return backend_handle_cache (b, get_handle (conn, b->i), count, offset,
+                               flags, err);
+}
+
+int
+backend_handle_cache (struct backend *b, struct handle *h,
+                      uint32_t count, uint64_t offset,
+                      uint32_t flags, int *err)
+{
   int r;

   assert (h->handle && (h->state & HANDLE_CONNECTED));
-- 
2.30.1


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