[Libguestfs] [nbdkit PATCH v3 04/16] server: Rename struct handle to struct context

Eric Blake eblake at redhat.com
Fri Mar 5 23:31:08 UTC 2021


Reduce the confusion between the user's (filter or plugin) void
*handle, and the extra context information we need to utilize that
handle.  This will also make it easier for an upcoming patch to update
the signature of various backend_* functions called from
nbdkit_next_ops.  Also delete the nr_handles field, which was unused
and always reflected 'top->i+1'.  The HANDLE_* enum values are left
unchanged, as they represent what we know about the user's handle, and
therefore what user cleanup functions we still need to call.
---
 server/internal.h    |  22 ++--
 server/backend.c     | 270 +++++++++++++++++++++----------------------
 server/connections.c |  13 +--
 3 files changed, 151 insertions(+), 154 deletions(-)

diff --git a/server/internal.h b/server/internal.h
index 1f37703f..5e382fe0 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
@@ -192,12 +192,12 @@ typedef int (*connection_send_function) (const void *buf, size_t len,
   __attribute__((__nonnull__ (1)));
 typedef void (*connection_close_function) (void);

-/* struct handle stores data per connection and backend.  Primarily
+/* struct context stores data per connection and backend.  Primarily
  * this is the filter or plugin handle, but other state is also stored
  * here.
  *
- * Use get_handle (conn, 0) to return the struct handle for the
- * plugin, and get_handle (conn, b->i) to return the struct handle for
+ * Use get_context (conn, 0) to return the struct context for the
+ * plugin, and get_context (conn, b->i) to return the struct context for
  * the i'th backend (if b->i >= 1 then for a filter).
  */
 enum {
@@ -206,7 +206,7 @@ enum {
   HANDLE_FAILED = 4,    /* Set if .finalize failed */
 };

-struct handle {
+struct context {
   void *handle;         /* Plugin or filter handle. */

   unsigned char state;  /* Bitmask of HANDLE_* values */
@@ -225,7 +225,7 @@ struct handle {
 };

 static inline void
-reset_handle (struct handle *h)
+reset_context (struct context *h)
 {
   h->handle = NULL;
   h->state = 0;
@@ -254,9 +254,7 @@ struct connection {
   void *crypto_session;
   int nworkers;

-  struct handle *handles;       /* One per plugin and filter. */
-  size_t nr_handles;
-
+  struct context *contexts;     /* One per plugin and filter. */
   char **default_exportname;    /* One per plugin and filter. */

   uint32_t cflags;
@@ -276,10 +274,10 @@ struct connection {
   connection_close_function close;
 };

-static inline struct handle *
-get_handle (struct connection *conn, int i)
+static inline struct context *
+get_context (struct connection *conn, int i)
 {
-  return &conn->handles[i];
+  return &conn->contexts[i];
 }

 extern void handle_single_connection (int sockin, int sockout);
diff --git a/server/backend.c b/server/backend.c
index d08a2b6b..0a67e8be 100644
--- a/server/backend.c
+++ b/server/backend.c
@@ -163,14 +163,14 @@ backend_list_exports (struct backend *b, int readonly,
                       struct nbdkit_exports *exports)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   size_t count;

   controlpath_debug ("%s: list_exports readonly=%d tls=%d",
                      b->name, readonly, conn->using_tls);

-  assert (h->handle == NULL);
-  assert ((h->state & HANDLE_OPEN) == 0);
+  assert (c->handle == NULL);
+  assert ((c->state & HANDLE_OPEN) == 0);

   if (b->list_exports (b, readonly, conn->using_tls, exports) == -1 ||
       exports_resolve_default (exports, b, readonly) == -1) {
@@ -187,15 +187,15 @@ const char *
 backend_default_export (struct backend *b, int readonly)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   const char *s;

   controlpath_debug ("%s: default_export readonly=%d tls=%d",
                      b->name, readonly, conn->using_tls);

   if (conn->default_exportname[b->i] == NULL) {
-    assert (h->handle == NULL);
-    assert ((h->state & HANDLE_OPEN) == 0);
+    assert (c->handle == NULL);
+    assert ((c->state & HANDLE_OPEN) == 0);
     s = b->default_export (b, readonly, conn->using_tls);
     /* Ignore over-length strings. XXX Also ignore non-UTF8? */
     if (s && strnlen (s, NBD_MAX_STRING + 1) > NBD_MAX_STRING) {
@@ -217,16 +217,16 @@ int
 backend_open (struct backend *b, int readonly, const char *exportname)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

   controlpath_debug ("%s: open readonly=%d exportname=\"%s\" tls=%d",
                      b->name, readonly, exportname, conn->using_tls);

-  assert (h->handle == NULL);
-  assert ((h->state & HANDLE_OPEN) == 0);
-  assert (h->can_write == -1);
+  assert (c->handle == NULL);
+  assert ((c->state & HANDLE_OPEN) == 0);
+  assert (c->can_write == -1);
   if (readonly)
-    h->can_write = 0;
+    c->can_write = 0;

   /* Determine the canonical name for default export */
   if (!*exportname) {
@@ -240,16 +240,16 @@ backend_open (struct backend *b, int readonly, const char *exportname)
   /* Most filters will call next_open first, resulting in
    * inner-to-outer ordering.
    */
-  h->handle = b->open (b, readonly, exportname, conn->using_tls);
-  controlpath_debug ("%s: open returned handle %p", b->name, h->handle);
+  c->handle = b->open (b, readonly, exportname, conn->using_tls);
+  controlpath_debug ("%s: open returned handle %p", b->name, c->handle);

-  if (h->handle == NULL) {
+  if (c->handle == NULL) {
     if (b->i) /* Do not strand backend if this layer failed */
       backend_close (b->next);
     return -1;
   }

-  h->state |= HANDLE_OPEN;
+  c->state |= HANDLE_OPEN;
   return 0;
 }

@@ -257,24 +257,24 @@ int
 backend_prepare (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

-  assert (h->handle);
-  assert ((h->state & (HANDLE_OPEN | HANDLE_CONNECTED)) == HANDLE_OPEN);
+  assert (c->handle);
+  assert ((c->state & (HANDLE_OPEN | HANDLE_CONNECTED)) == HANDLE_OPEN);

   /* Call these in order starting from the filter closest to the
    * plugin, similar to typical .open order.  But remember that
    * a filter may skip opening its backend.
    */
-  if (b->i && get_handle (conn, b->i-1)->handle != NULL &&
+  if (b->i && get_context (conn, b->i-1)->handle != NULL &&
       backend_prepare (b->next) == -1)
     return -1;

-  controlpath_debug ("%s: prepare readonly=%d", b->name, h->can_write == 0);
+  controlpath_debug ("%s: prepare readonly=%d", b->name, c->can_write == 0);

-  if (b->prepare (b, h->handle, h->can_write == 0) == -1)
+  if (b->prepare (b, c->handle, c->can_write == 0) == -1)
     return -1;
-  h->state |= HANDLE_CONNECTED;
+  c->state |= HANDLE_CONNECTED;
   return 0;
 }

@@ -282,21 +282,21 @@ int
 backend_finalize (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

   /* Call these in reverse order to .prepare above, starting from the
    * filter furthest away from the plugin, and matching .close order.
    */

   /* Once finalize fails, we can do nothing further on this connection */
-  if (h->state & HANDLE_FAILED)
+  if (c->state & HANDLE_FAILED)
     return -1;

-  if (h->state & HANDLE_CONNECTED) {
-    assert (h->state & HANDLE_OPEN && h->handle);
+  if (c->state & HANDLE_CONNECTED) {
+    assert (c->state & HANDLE_OPEN && c->handle);
     controlpath_debug ("%s: finalize", b->name);
-    if (b->finalize (b, h->handle) == -1) {
-      h->state |= HANDLE_FAILED;
+    if (b->finalize (b, c->handle) == -1) {
+      c->state |= HANDLE_FAILED;
       return -1;
     }
   }
@@ -310,18 +310,18 @@ void
 backend_close (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

   /* outer-to-inner order, opposite .open */

-  if (h->handle) {
-    assert (h->state & HANDLE_OPEN);
+  if (c->handle) {
+    assert (c->state & HANDLE_OPEN);
     controlpath_debug ("%s: close", b->name);
-    b->close (b, h->handle);
+    b->close (b, c->handle);
   }
   else
-    assert (! (h->state & HANDLE_OPEN));
-  reset_handle (h);
+    assert (! (c->state & HANDLE_OPEN));
+  reset_context (c);
   if (b->i)
     backend_close (b->next);
 }
@@ -330,11 +330,11 @@ bool
 backend_valid_range (struct backend *b, uint64_t offset, uint32_t count)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

-  assert (h->exportsize <= INT64_MAX); /* Guaranteed by negotiation phase */
-  return count > 0 && offset <= h->exportsize &&
-    offset + count <= h->exportsize;
+  assert (c->exportsize <= INT64_MAX); /* Guaranteed by negotiation phase */
+  return count > 0 && offset <= c->exportsize &&
+    offset + count <= c->exportsize;
 }

 /* Core functionality of nbdkit_backend_reopen for retry filter */
@@ -366,14 +366,14 @@ const char *
 backend_export_description (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   const char *s;

   controlpath_debug ("%s: export_description", b->name);

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
   /* Caching is not useful for this value. */
-  s = b->export_description (b, h->handle);
+  s = b->export_description (b, c->handle);

   /* Ignore over-length strings. XXX Also ignore non-UTF8? */
   if (s && strnlen (s, NBD_MAX_STRING + 1) > NBD_MAX_STRING) {
@@ -388,178 +388,178 @@ int64_t
 backend_get_size (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->exportsize == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->exportsize == -1) {
     controlpath_debug ("%s: get_size", b->name);
-    h->exportsize = b->get_size (b, h->handle);
+    c->exportsize = b->get_size (b, c->handle);
   }
-  return h->exportsize;
+  return c->exportsize;
 }

 int
 backend_can_write (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->can_write == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->can_write == -1) {
     controlpath_debug ("%s: can_write", b->name);
-    h->can_write = b->can_write (b, h->handle);
+    c->can_write = b->can_write (b, c->handle);
   }
-  return h->can_write;
+  return c->can_write;
 }

 int
 backend_can_flush (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->can_flush == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->can_flush == -1) {
     controlpath_debug ("%s: can_flush", b->name);
-    h->can_flush = b->can_flush (b, h->handle);
+    c->can_flush = b->can_flush (b, c->handle);
   }
-  return h->can_flush;
+  return c->can_flush;
 }

 int
 backend_is_rotational (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->is_rotational == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->is_rotational == -1) {
     controlpath_debug ("%s: is_rotational", b->name);
-    h->is_rotational = b->is_rotational (b, h->handle);
+    c->is_rotational = b->is_rotational (b, c->handle);
   }
-  return h->is_rotational;
+  return c->is_rotational;
 }

 int
 backend_can_trim (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->can_trim == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->can_trim == -1) {
     controlpath_debug ("%s: can_trim", b->name);
     r = backend_can_write (b);
     if (r != 1) {
-      h->can_trim = 0;
+      c->can_trim = 0;
       return r;
     }
-    h->can_trim = b->can_trim (b, h->handle);
+    c->can_trim = b->can_trim (b, c->handle);
   }
-  return h->can_trim;
+  return c->can_trim;
 }

 int
 backend_can_zero (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->can_zero == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->can_zero == -1) {
     controlpath_debug ("%s: can_zero", b->name);
     r = backend_can_write (b);
     if (r != 1) {
-      h->can_zero = NBDKIT_ZERO_NONE;
+      c->can_zero = NBDKIT_ZERO_NONE;
       return r; /* Relies on 0 == NBDKIT_ZERO_NONE */
     }
-    h->can_zero = b->can_zero (b, h->handle);
+    c->can_zero = b->can_zero (b, c->handle);
   }
-  return h->can_zero;
+  return c->can_zero;
 }

 int
 backend_can_fast_zero (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->can_fast_zero == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->can_fast_zero == -1) {
     controlpath_debug ("%s: can_fast_zero", b->name);
     r = backend_can_zero (b);
     if (r < NBDKIT_ZERO_EMULATE) {
-      h->can_fast_zero = 0;
+      c->can_fast_zero = 0;
       return r; /* Relies on 0 == NBDKIT_ZERO_NONE */
     }
-    h->can_fast_zero = b->can_fast_zero (b, h->handle);
+    c->can_fast_zero = b->can_fast_zero (b, c->handle);
   }
-  return h->can_fast_zero;
+  return c->can_fast_zero;
 }

 int
 backend_can_extents (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->can_extents == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->can_extents == -1) {
     controlpath_debug ("%s: can_extents", b->name);
-    h->can_extents = b->can_extents (b, h->handle);
+    c->can_extents = b->can_extents (b, c->handle);
   }
-  return h->can_extents;
+  return c->can_extents;
 }

 int
 backend_can_fua (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->can_fua == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->can_fua == -1) {
     controlpath_debug ("%s: can_fua", b->name);
     r = backend_can_write (b);
     if (r != 1) {
-      h->can_fua = NBDKIT_FUA_NONE;
+      c->can_fua = NBDKIT_FUA_NONE;
       return r; /* Relies on 0 == NBDKIT_FUA_NONE */
     }
-    h->can_fua = b->can_fua (b, h->handle);
+    c->can_fua = b->can_fua (b, c->handle);
   }
-  return h->can_fua;
+  return c->can_fua;
 }

 int
 backend_can_multi_conn (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->can_multi_conn == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->can_multi_conn == -1) {
     controlpath_debug ("%s: can_multi_conn", b->name);
-    h->can_multi_conn = b->can_multi_conn (b, h->handle);
+    c->can_multi_conn = b->can_multi_conn (b, c->handle);
   }
-  return h->can_multi_conn;
+  return c->can_multi_conn;
 }

 int
 backend_can_cache (struct backend *b)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  if (h->can_cache == -1) {
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  if (c->can_cache == -1) {
     controlpath_debug ("%s: can_cache", b->name);
-    h->can_cache = b->can_cache (b, h->handle);
+    c->can_cache = b->can_cache (b, c->handle);
   }
-  return h->can_cache;
+  return c->can_cache;
 }

 int
@@ -568,16 +568,16 @@ backend_pread (struct backend *b,
                uint32_t flags, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
   assert (backend_valid_range (b, offset, count));
   assert (flags == 0);
   datapath_debug ("%s: pread count=%" PRIu32 " offset=%" PRIu64,
                   b->name, count, offset);

-  r = b->pread (b, h->handle, buf, count, offset, flags, err);
+  r = b->pread (b, c->handle, buf, count, offset, flags, err);
   if (r == -1)
     assert (*err);
   return r;
@@ -589,20 +589,20 @@ backend_pwrite (struct backend *b,
                 uint32_t flags, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   bool fua = !!(flags & NBDKIT_FLAG_FUA);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  assert (h->can_write == 1);
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  assert (c->can_write == 1);
   assert (backend_valid_range (b, offset, count));
   assert (!(flags & ~NBDKIT_FLAG_FUA));
   if (fua)
-    assert (h->can_fua > NBDKIT_FUA_NONE);
+    assert (c->can_fua > NBDKIT_FUA_NONE);
   datapath_debug ("%s: pwrite count=%" PRIu32 " offset=%" PRIu64 " fua=%d",
                   b->name, count, offset, fua);

-  r = b->pwrite (b, h->handle, buf, count, offset, flags, err);
+  r = b->pwrite (b, c->handle, buf, count, offset, flags, err);
   if (r == -1)
     assert (*err);
   return r;
@@ -613,15 +613,15 @@ backend_flush (struct backend *b,
                uint32_t flags, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  assert (h->can_flush == 1);
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  assert (c->can_flush == 1);
   assert (flags == 0);
   datapath_debug ("%s: flush", b->name);

-  r = b->flush (b, h->handle, flags, err);
+  r = b->flush (b, c->handle, flags, err);
   if (r == -1)
     assert (*err);
   return r;
@@ -633,21 +633,21 @@ backend_trim (struct backend *b,
               int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   bool fua = !!(flags & NBDKIT_FLAG_FUA);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  assert (h->can_write == 1);
-  assert (h->can_trim == 1);
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  assert (c->can_write == 1);
+  assert (c->can_trim == 1);
   assert (backend_valid_range (b, offset, count));
   assert (!(flags & ~NBDKIT_FLAG_FUA));
   if (fua)
-    assert (h->can_fua > NBDKIT_FUA_NONE);
+    assert (c->can_fua > NBDKIT_FUA_NONE);
   datapath_debug ("%s: trim count=%" PRIu32 " offset=%" PRIu64 " fua=%d",
                   b->name, count, offset, fua);

-  r = b->trim (b, h->handle, count, offset, flags, err);
+  r = b->trim (b, c->handle, count, offset, flags, err);
   if (r == -1)
     assert (*err);
   return r;
@@ -659,27 +659,27 @@ backend_zero (struct backend *b,
               int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   bool fua = !!(flags & NBDKIT_FLAG_FUA);
   bool fast = !!(flags & NBDKIT_FLAG_FAST_ZERO);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  assert (h->can_write == 1);
-  assert (h->can_zero > NBDKIT_ZERO_NONE);
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  assert (c->can_write == 1);
+  assert (c->can_zero > NBDKIT_ZERO_NONE);
   assert (backend_valid_range (b, offset, count));
   assert (!(flags & ~(NBDKIT_FLAG_MAY_TRIM | NBDKIT_FLAG_FUA |
                       NBDKIT_FLAG_FAST_ZERO)));
   if (fua)
-    assert (h->can_fua > NBDKIT_FUA_NONE);
+    assert (c->can_fua > NBDKIT_FUA_NONE);
   if (fast)
-    assert (h->can_fast_zero == 1);
+    assert (c->can_fast_zero == 1);
   datapath_debug ("%s: zero count=%" PRIu32 " offset=%" PRIu64
                   " may_trim=%d fua=%d fast=%d",
                   b->name, count, offset,
                   !!(flags & NBDKIT_FLAG_MAY_TRIM), fua, fast);

-  r = b->zero (b, h->handle, count, offset, flags, err);
+  r = b->zero (b, c->handle, count, offset, flags, err);
   if (r == -1) {
     assert (*err);
     if (!fast)
@@ -694,17 +694,17 @@ backend_extents (struct backend *b,
                  struct nbdkit_extents *extents, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  assert (h->can_extents >= 0);
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  assert (c->can_extents >= 0);
   assert (backend_valid_range (b, offset, count));
   assert (!(flags & ~NBDKIT_FLAG_REQ_ONE));
   datapath_debug ("%s: extents count=%" PRIu32 " offset=%" PRIu64 " req_one=%d",
                   b->name, count, offset, !!(flags & NBDKIT_FLAG_REQ_ONE));

-  if (h->can_extents == 0) {
+  if (c->can_extents == 0) {
     /* By default it is safe assume that everything in the range is
      * allocated.
      */
@@ -713,7 +713,7 @@ backend_extents (struct backend *b,
       *err = errno;
     return r;
   }
-  r = b->extents (b, h->handle, count, offset, flags, extents, err);
+  r = b->extents (b, c->handle, count, offset, flags, extents, err);
   if (r == -1)
     assert (*err);
   return r;
@@ -725,17 +725,17 @@ backend_cache (struct backend *b,
                uint32_t flags, int *err)
 {
   GET_CONN;
-  struct handle *h = get_handle (conn, b->i);
+  struct context *c = get_context (conn, b->i);
   int r;

-  assert (h->handle && (h->state & HANDLE_CONNECTED));
-  assert (h->can_cache > NBDKIT_CACHE_NONE);
+  assert (c->handle && (c->state & HANDLE_CONNECTED));
+  assert (c->can_cache > NBDKIT_CACHE_NONE);
   assert (backend_valid_range (b, offset, count));
   assert (flags == 0);
   datapath_debug ("%s: cache count=%" PRIu32 " offset=%" PRIu64,
                   b->name, count, offset);

-  if (h->can_cache == NBDKIT_CACHE_EMULATE) {
+  if (c->can_cache == NBDKIT_CACHE_EMULATE) {
     static char buf[MAX_REQUEST_SIZE]; /* data sink, never read */
     uint32_t limit;

@@ -747,7 +747,7 @@ backend_cache (struct backend *b,
     }
     return 0;
   }
-  r = b->cache (b, h->handle, count, offset, flags, err);
+  r = b->cache (b, c->handle, count, offset, flags, err);
   if (r == -1)
     assert (*err);
   return r;
diff --git a/server/connections.c b/server/connections.c
index b56f89f8..87db2d80 100644
--- a/server/connections.c
+++ b/server/connections.c
@@ -254,20 +254,19 @@ new_connection (int sockin, int sockout, int nworkers)
   pthread_mutex_init (&conn->write_lock, NULL);
   pthread_mutex_init (&conn->status_lock, NULL);

-  conn->handles = calloc (top->i + 1, sizeof *conn->handles);
-  if (conn->handles == NULL) {
+  conn->contexts = calloc (top->i + 1, sizeof *conn->contexts);
+  if (conn->contexts == NULL) {
     perror ("malloc");
     goto error1;
   }
-  conn->nr_handles = top->i + 1;
   for_each_backend (b)
-    reset_handle (get_handle (conn, b->i));
+    reset_context (get_context (conn, b->i));

   conn->default_exportname = calloc (top->i + 1,
                                      sizeof *conn->default_exportname);
   if (conn->default_exportname == NULL) {
     perror ("malloc");
-    free (conn->handles);
+    free (conn->contexts);
     goto error1;
   }

@@ -337,7 +336,7 @@ new_connection (int sockin, int sockout, int nworkers)
     close (conn->status_pipe[0]);
   if (conn->status_pipe[1] >= 0)
     close (conn->status_pipe[1]);
-  free (conn->handles);
+  free (conn->contexts);
   free (conn->default_exportname);

  error1:
@@ -385,7 +384,7 @@ free_connection (struct connection *conn)
   for_each_backend (b)
     free (conn->default_exportname[b->i]);
   free (conn->default_exportname);
-  free (conn->handles);
+  free (conn->contexts);

   free (conn);
   threadlocal_set_conn (NULL);
-- 
2.30.1




More information about the Libguestfs mailing list