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        void nbd_close (struct nbd_handle *nbd);
16        const char *nbd_get_error (void);
17        int nbd_get_errno (void);
18

EXAMPLE

20        #include <libnbd.h>
21
22        main ()
23        {
24          struct nbd_handle *nbd;
25
26          nbd = nbd_create ();
27          if (nbd == NULL) {
28            fprintf (stderr, "%s\n", nbd_get_error ());
29            nbd_close (nbd);
30            exit (EXIT_FAILURE);
31          }
32          nbd_close (nbd);
33          exit (EXIT_SUCCESS);
34        }
35
36        cc prog.c -o prog -lnbd
37       or:
38        cc prog.c -o prog `pkg-config libnbd --cflags --libs`
39

DESCRIPTION

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

SEE ALSO

78       libnbd(3).
79

AUTHORS

81       Eric Blake
82
83       Richard W.M. Jones
84
86       Copyright (C) 2019 Red Hat Inc.
87

LICENSE

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