1nbd_can_multi_conn(3)               LIBNBD               nbd_can_multi_conn(3)
2
3
4

NAME

6       nbd_can_multi_conn - does the server support multi-conn?
7

SYNOPSIS

9        #include <libnbd.h>
10
11        int nbd_can_multi_conn (
12              struct nbd_handle *h
13            );
14

DESCRIPTION

16       Returns true if the server supports multi-conn.  Returns false if the
17       server does not.
18
19       It is not safe to open multiple handles connecting to the same server
20       if you will write to the server and the server does not advertise
21       multi-conn support.  The safe way to check for this is to open one
22       connection, check this flag is true, then open further connections as
23       required.
24
25       This call does not block, because it returns data that is saved in the
26       handle from the NBD protocol handshake.
27

RETURN VALUE

29       This call returns a boolean value.
30

ERRORS

32       On error -1 is returned.
33
34       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
35       of the error.
36
37       The following parameters must not be NULL: "h".  For more information
38       see "Non-NULL parameters" in libnbd(3).
39

HANDLE STATE

41       The handle must be negotiating, or connected with the server, or shut
42       down, otherwise this call will return an error.
43

VERSION

45       This function first appeared in libnbd 1.0.
46
47       If you need to test if this function is available at compile time check
48       if the following macro is defined:
49
50        #define LIBNBD_HAVE_NBD_CAN_MULTI_CONN 1
51

EXAMPLE

53       This example is also available as examples/server-flags.c in the libnbd
54       source code.
55
56        /* This example shows how to connect to an NBD
57         * server and print the export flags.
58         *
59         * You can test it with nbdkit like this:
60         *
61         * nbdkit -U - memory 1M \
62         *   --run './server-flags $unixsocket'
63         */
64
65        #include <stdio.h>
66        #include <stdlib.h>
67
68        #include <libnbd.h>
69
70        int
71        main (int argc, char *argv[])
72        {
73          struct nbd_handle *nbd;
74          char *str;
75          int flag;
76
77          if (argc != 2) {
78            fprintf (stderr, "%s socket\n", argv[0]);
79            exit (EXIT_FAILURE);
80          }
81
82          /* Create the libnbd handle. */
83          nbd = nbd_create ();
84          if (nbd == NULL) {
85            fprintf (stderr, "%s\n", nbd_get_error ());
86            exit (EXIT_FAILURE);
87          }
88
89          /* Request full information. */
90        #if LIBNBD_HAVE_NBD_SET_FULL_INFO /* Added in 1.4 */
91          if (nbd_set_full_info (nbd, true) == -1) {
92            fprintf (stderr, "%s\n", nbd_get_error ());
93            exit (EXIT_FAILURE);
94          }
95        #endif
96
97          /* Connect to the NBD server over a
98           * Unix domain socket.
99           */
100          if (nbd_connect_unix (nbd, argv[1]) == -1) {
101            fprintf (stderr, "%s\n", nbd_get_error ());
102            exit (EXIT_FAILURE);
103          }
104
105          /* See if the server provided extra details,
106           * using functions added in 1.4
107           */
108        #if LIBNBD_HAVE_NBD_GET_EXPORT_DESCRIPTION
109          str = nbd_get_canonical_export_name (nbd);
110          if (str)
111            printf ("canonical_name = %s\n", str);
112          free (str);
113          str = nbd_get_export_description (nbd);
114          if (str)
115            printf ("description = %s\n", str);
116          free (str);
117        #endif
118
119          /* Read and print the flags. */
120        #define PRINT_FLAG(flag_fn)                     \
121          flag = flag_fn (nbd);                         \
122          if (flag == -1) {                             \
123            fprintf (stderr, "%s\n", nbd_get_error ()); \
124            exit (EXIT_FAILURE);                        \
125          }                                             \
126          printf (#flag_fn " = %s\n",                   \
127                  flag ? "true" : "false");
128
129          PRINT_FLAG (nbd_can_cache);
130          PRINT_FLAG (nbd_can_df);
131          PRINT_FLAG (nbd_can_flush);
132          PRINT_FLAG (nbd_can_fua);
133          PRINT_FLAG (nbd_can_multi_conn);
134          PRINT_FLAG (nbd_can_trim);
135          PRINT_FLAG (nbd_can_zero);
136        #if LIBNBD_HAVE_NBD_CAN_FAST_ZERO /* Added in 1.2 */
137          PRINT_FLAG (nbd_can_fast_zero);
138        #endif
139          PRINT_FLAG (nbd_is_read_only);
140          PRINT_FLAG (nbd_is_rotational);
141
142          /* Close the libnbd handle. */
143          nbd_close (nbd);
144
145          exit (EXIT_SUCCESS);
146        }
147

SEE ALSO

149       nbd_create(3), nbd_opt_info(3), "Flag calls" in libnbd(3), "Multi-conn"
150       in libnbd(3), libnbd(3).
151

AUTHORS

153       Eric Blake
154
155       Richard W.M. Jones
156
158       Copyright Red Hat
159

LICENSE

161       This library is free software; you can redistribute it and/or modify it
162       under the terms of the GNU Lesser General Public License as published
163       by the Free Software Foundation; either version 2 of the License, or
164       (at your option) any later version.
165
166       This library is distributed in the hope that it will be useful, but
167       WITHOUT ANY WARRANTY; without even the implied warranty of
168       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
169       Lesser General Public License for more details.
170
171       You should have received a copy of the GNU Lesser General Public
172       License along with this library; if not, write to the Free Software
173       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
174       02110-1301 USA
175
176
177
178libnbd-1.16.5                     2023-09-26             nbd_can_multi_conn(3)
Impressum