NAME

nbd_add_close_callback - add a callback which is called on close

SYNOPSIS

 #include <libnbd.h>

 typedef struct {
   int (*callback) (void *user_data);
   void *user_data;
   void (*free) (void *user_data);
 } nbd_close_callback;

 int nbd_add_close_callback (
       struct nbd_handle *h,
       nbd_close_callback close_callback
     );

DESCRIPTION

libnbd handles maintain a list of callbacks which are called when the handle is closed. This adds a callback to this list.

Callbacks cannot be removed from the list once added. Callbacks might not necessarily be called in all circumstances (eg. if the program crashes).

The callback function is declared like this (in the C bindings):

 int callback (void *user_data);

where the parameter is the user_data passed to this function, and an int is returned. The return value is ignored because nbd_close(3) returns void and cannot be cancelled.

The callback should not call nbd_* APIs on the same handle since it can be called while holding the handle lock and will cause a deadlock.

If there are multiple close callbacks the order in which they are called is not defined. But all the callbacks are called first followed by all the free functions.

RETURN VALUE

If the call is successful the function returns 0.

ERRORS

On error -1 is returned.

Refer to "ERROR HANDLING" in libnbd(3) for how to get further details of the error.

The following parameters must not be NULL: h. For more information see "Non-NULL parameters" in libnbd(3).

VERSION

This function first appeared in libnbd 1.26.

If you need to test if this function is available at compile time check if the following macro is defined:

 #define LIBNBD_HAVE_NBD_ADD_CLOSE_CALLBACK 1

SEE ALSO

nbd_close(3), nbd_create(3), nbd_set_private_data(3), libnbd(3), atexit(3).

AUTHORS

Eric Blake

Richard W.M. Jones

COPYRIGHT

Copyright Red Hat

LICENSE

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA