1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
=head1 NAME
nbd_create, nbd_close, nbd_get_error, nbd_get_errno - create libnbd
handles and fetch errors
=head1 SYNOPSIS
#include <libnbd.h>
=for paragraph
struct nbd_handle *nbd;
=for paragraph
struct nbd_handle *nbd_create (void);
=for paragraph
void nbd_close (struct nbd_handle *nbd);
=for paragraph
const char *nbd_get_error (void);
=for paragraph
int nbd_get_errno (void);
=head1 DESCRIPTION
B<struct nbd_handle> is an opaque structure which describes an NBD
client handle and the connection to an NBD server.
=head2 Creating a libnbd handle
B<nbd_create> creates a new handle. It returns a pointer to the
opaque handle structure.
On error this returns C<NULL>. See L<libnbd(3)/ERROR HANDLING>
for how to get further details of the error.
=head2 Closing a handle
B<nbd_close> closes the handle, closing and freeing any associated
resources.
The final status of any command that has not been retired (whether by
L<nbd_aio_command_completed(3)> or by a low-level completion callback
returning C<1>) is lost.
This function is not safe to call while any other thread is still
using any C<nbd_*> API on the same handle. This function can block in
the case where we wait for a subprocess (eg. one created with
L<nbd_connect_command(3)>).
=head2 Getting the latest error message in the thread
B<nbd_get_error> returns the most recent error message in the current
thread. The error message is only valid if called immediately after
the failing call, from the same thread. The error string returned
will be freed up next time any libnbd API is called from the same
thread, so if you need to keep it you must make a copy.
This should never return C<NULL> provided there was an error
returned from the immediately preceding libnbd call in the
current thread.
B<nbd_get_errno> returns the most recent C<errno> in the current
thread. Not all 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>>.
See L<libnbd(3)/ERROR HANDLING> for more discussion of how error
handling works in libnbd.
=head1 EXAMPLE
#include <libnbd.h>
main ()
{
struct nbd_handle *nbd;
nbd = nbd_create ();
if (nbd == NULL) {
fprintf (stderr, "%s\n", nbd_get_error ());
nbd_close (nbd);
exit (EXIT_FAILURE);
}
nbd_close (nbd);
exit (EXIT_SUCCESS);
}
=head1 VERSION
These functions were all present in libnbd 1.0.
=head1 SEE ALSO
L<nbd_shutdown(3)>,
L<libnbd(3)>.
=head1 AUTHORS
Eric Blake
Richard W.M. Jones
=head1 COPYRIGHT
Copyright Red Hat
|