1nbd_create(3)                       LIBNBD                       nbd_create(3)
2
3
4

NAME

6       nbd_create, nbd_close, nbd_get_error, nbd_get_errno - create libnbd
7       handles and fetch errors
8

SYNOPSIS

10        #include <libnbd.h>
11
12        struct nbd_handle *nbd;
13
14        struct nbd_handle *nbd_create (void);
15
16        void nbd_close (struct nbd_handle *nbd);
17
18        const char *nbd_get_error (void);
19
20        int nbd_get_errno (void);
21

DESCRIPTION

23       struct nbd_handle is an opaque structure which describes an NBD client
24       handle and the connection to an NBD server.
25
26   Creating a libnbd handle
27       nbd_create creates a new handle.  It returns a pointer to the opaque
28       handle structure.
29
30       On error this returns "NULL".  See "ERROR HANDLING" in libnbd(3) for
31       how to get further details of the error.
32
33   Closing a handle
34       nbd_close closes the handle, closing and freeing any associated
35       resources.
36
37       The final status of any command that has not been retired (whether by
38       nbd_aio_command_completed(3) or by a low-level completion callback
39       returning 1) is lost.
40
41       This function is not safe to call while any other thread is still using
42       any "nbd_*" API on the same handle.  This function can block in the
43       case where we wait for a subprocess (eg. one created with
44       nbd_connect_command(3)).
45
46   Getting the latest error message in the thread
47       nbd_get_error returns the most recent error message in the current
48       thread.  The error message is only valid if called immediately after
49       the failing call, from the same thread.  The error string returned will
50       be freed up next time any libnbd API is called from the same thread, so
51       if you need to keep it you must make a copy.
52
53       This should never return "NULL" provided there was an error returned
54       from the immediately preceding libnbd call in the current thread.
55
56       nbd_get_errno returns the most recent "errno" in the current thread.
57       Not all errors have corresponding errnos, so even if there has been an
58       error this may return 0.  Error codes are the standard ones from
59       "<errno.h>".
60
61       See "ERROR HANDLING" in libnbd(3) for more discussion of how error
62       handling works in libnbd.
63

EXAMPLE

65        #include <libnbd.h>
66
67        main ()
68        {
69          struct nbd_handle *nbd;
70
71          nbd = nbd_create ();
72          if (nbd == NULL) {
73            fprintf (stderr, "%s\n", nbd_get_error ());
74            nbd_close (nbd);
75            exit (EXIT_FAILURE);
76          }
77          nbd_close (nbd);
78          exit (EXIT_SUCCESS);
79        }
80

VERSION

82       These functions were all present in libnbd 1.0.
83

SEE ALSO

85       libnbd(3).
86

AUTHORS

88       Eric Blake
89
90       Richard W.M. Jones
91
93       Copyright (C) 2019-2021 Red Hat Inc.
94

LICENSE

96       This library is free software; you can redistribute it and/or modify it
97       under the terms of the GNU Lesser General Public License as published
98       by the Free Software Foundation; either version 2 of the License, or
99       (at your option) any later version.
100
101       This library is distributed in the hope that it will be useful, but
102       WITHOUT ANY WARRANTY; without even the implied warranty of
103       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
104       Lesser General Public License for more details.
105
106       You should have received a copy of the GNU Lesser General Public
107       License along with this library; if not, write to the Free Software
108       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
109       02110-1301 USA
110
111
112
113libnbd-1.10.1                     2021-10-25                     nbd_create(3)
Impressum