=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.  For an overview of
the NBD client and NBD handles, see L<libnbd(3)>.

=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
