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 5d5c267..9a15916 100755
--- a/generator/generator
+++ b/generator/generator
@@ -3139,7 +3139,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";
@@ -3339,11 +3338,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;
@@ -3617,18 +3611,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 9c643d8..78e72c5 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -90,18 +90,11 @@ 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)
return;
- 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;
@@ -198,34 +191,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 1790d01..d534243 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;
@@ -83,9 +82,6 @@ struct nbd_handle {
int (*debug_fn) (int, void *, const char *, const char *);
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
@@ -225,12 +221,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