Provided by: libnbd-dev_1.14.2-1_amd64
NAME
nbd_create, nbd_close, nbd_get_error, nbd_get_errno - create libnbd handles and fetch errors
SYNOPSIS
#include <libnbd.h> struct nbd_handle *nbd; struct nbd_handle *nbd_create (void); void nbd_close (struct nbd_handle *nbd); const char *nbd_get_error (void); int nbd_get_errno (void);
DESCRIPTION
struct nbd_handle is an opaque structure which describes an NBD client handle and the connection to an NBD server. Creating a libnbd handle nbd_create creates a new handle. It returns a pointer to the opaque handle structure. On error this returns "NULL". See "ERROR HANDLING" in libnbd(3) for how to get further details of the error. Closing a handle nbd_close closes the handle, closing and freeing any associated resources. The final status of any command that has not been retired (whether by nbd_aio_command_completed(3) or by a low-level completion callback returning 1) is lost. This function is not safe to call while any other thread is still using any "nbd_*" API on the same handle. This function can block in the case where we wait for a subprocess (eg. one created with nbd_connect_command(3)). Getting the latest error message in the thread 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 "NULL" provided there was an error returned from the immediately preceding libnbd call in the current thread. nbd_get_errno returns the most recent "errno" in the current thread. Not all errors have corresponding errnos, so even if there has been an error this may return 0. Error codes are the standard ones from "<errno.h>". See "ERROR HANDLING" in libnbd(3) for more discussion of how error handling works in libnbd.
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); }
VERSION
These functions were all present in libnbd 1.0.
SEE ALSO
libnbd(3).
AUTHORS
Eric Blake Richard W.M. Jones
COPYRIGHT
Copyright (C) 2019-2021 Red Hat Inc.
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