[Libguestfs] [PATCH libnbd v3 2/2] lib: Remove nbd_add_close_callback.

Richard W.M. Jones rjones at redhat.com
Thu Jul 25 13:07:42 UTC 2019


We previously needed nbd_add_close_callback to do cleanup from
language bindings.  However now we have closure lifetimes this is no
longer needed and can be removed.

See also:
https://www.redhat.com/archives/libguestfs/2019-July/msg00213.html
---
 generator/generator | 18 ------------------
 lib/handle.c        | 35 -----------------------------------
 lib/internal.h      | 10 ----------
 3 files changed, 63 deletions(-)

diff --git a/generator/generator b/generator/generator
index 7aad57c..92a1aae 100755
--- a/generator/generator
+++ b/generator/generator
@@ -3055,7 +3055,6 @@ let generate_lib_libnbd_syms () =
 
   pr "{\n";
   pr "  global:\n";
-  pr "    nbd_add_close_callback;\n";
   pr "    nbd_create;\n";
   pr "    nbd_close;\n";
   pr "    nbd_get_errno;\n";
@@ -3255,11 +3254,6 @@ let generate_include_libnbd_h () =
   pr "extern int nbd_get_errno (void);\n";
   pr "#define LIBNBD_HAVE_NBD_GET_ERRNO 1\n";
   pr "\n";
-  pr "extern int nbd_add_close_callback (struct nbd_handle *h,\n";
-  pr "                                   nbd_close_callback cb,\n";
-  pr "                                   void *user_data);\n";
-  pr "#define LIBNBD_HAVE_NBD_ADD_CLOSE_CALLBACK 1\n";
-  pr "\n";
   List.iter (
     fun (name, { args; ret }) -> print_extern_and_define name args ret
   ) handle_calls;
@@ -3536,18 +3530,6 @@ errors have corresponding errnos, so even if there has been an error
 this may return C<0>.  Error codes are the standard ones from
 C<E<lt>errno.hE<gt>>.
 
-=head1 CLOSE CALLBACKS
-
-You can register close callbacks with the handle.  These are
-called when C<nbd_close> is called.  The order in which they
-are called is not defined.  This API is only available
-from C and is designed to help when writing bindings to libnbd
-from other programming languages.
-
- typedef void (*nbd_close_callback) (void *user_data);
- int nbd_add_close_callback (struct nbd_handle *nbd,
-                             nbd_close_callback cb, void *user_data);
-
 ";
 
   pr "=head1 API CALLS\n";
diff --git a/lib/handle.c b/lib/handle.c
index 6f5a4d6..840702a 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -90,7 +90,6 @@ nbd_create (void)
 void
 nbd_close (struct nbd_handle *h)
 {
-  struct close_callback *cc, *cc_next;
   struct meta_context *m, *m_next;
 
   if (h == NULL)
@@ -100,12 +99,6 @@ nbd_close (struct nbd_handle *h)
   if (h->debug_fn)
     h->debug_fn (LIBNBD_CALLBACK_FREE, h->debug_data, NULL, NULL);
 
-  for (cc = h->close_callbacks; cc != NULL; cc = cc_next) {
-    cc_next = cc->next;
-    cc->cb (cc->user_data);
-    free (cc);
-  }
-
   free (h->bs_entries);
   for (m = h->meta_contexts; m != NULL; m = m_next) {
     m_next = m->next;
@@ -202,34 +195,6 @@ nbd_unlocked_add_meta_context (struct nbd_handle *h, const char *name)
   return 0;
 }
 
-/* This is not generated because we don't want to offer it to other
- * programming languages.
- */
-int
-nbd_add_close_callback (struct nbd_handle *h,
-                        nbd_close_callback cb, void *user_data)
-{
-  int ret;
-  struct close_callback *cc;
-
-  pthread_mutex_lock (&h->lock);
-  cc = malloc (sizeof *cc);
-  if (cc == NULL) {
-    set_error (errno, "malloc");
-    ret = -1;
-    goto out;
-  }
-  cc->next = h->close_callbacks;
-  cc->cb = cb;
-  cc->user_data = user_data;
-  h->close_callbacks = cc;
-
-  ret = 0;
- out:
-  pthread_mutex_unlock (&h->lock);
-  return ret;
-}
-
 const char *
 nbd_unlocked_get_package_name (struct nbd_handle *h)
 {
diff --git a/lib/internal.h b/lib/internal.h
index 75f1b89..14d2ef0 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -45,7 +45,6 @@
 #define MAX_REQUEST_SIZE (64 * 1024 * 1024)
 
 struct meta_context;
-struct close_callback;
 struct socket;
 struct command;
 typedef int (*debug_fn) (unsigned, void *, const char *, const char *);
@@ -84,9 +83,6 @@ struct nbd_handle {
   debug_fn debug_fn;
   void *debug_data;
 
-  /* Linked list of close callbacks. */
-  struct close_callback *close_callbacks;
-
   /* State machine.
    *
    * The actual current state is ‘state’.  ‘public_state’ is updated
@@ -226,12 +222,6 @@ struct meta_context {
   uint32_t context_id;          /* Context ID negotiated with the server. */
 };
 
-struct close_callback {
-  struct close_callback *next;  /* Linked list. */
-  nbd_close_callback cb;        /* Function. */
-  void *user_data;              /* Data. */
-};
-
 struct socket_ops {
   ssize_t (*recv) (struct nbd_handle *h,
                    struct socket *sock, void *buf, size_t len);
-- 
2.22.0




More information about the Libguestfs mailing list