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 (struct nbd_handle *h);
12

DESCRIPTION

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

RETURN VALUE

27       This call returns a boolean value.
28

ERRORS

30       On error "-1" is returned.
31
32       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
33       of the error.
34

HANDLE STATE

36       The handle must be negotiating, or connected with the server, or shut
37       down, otherwise this call will return an error.
38

VERSION

40       This function first appeared in libnbd 1.0.
41
42       If you need to test if this function is available at compile time check
43       if the following macro is defined:
44
45        #define LIBNBD_HAVE_NBD_CAN_MULTI_CONN 1
46

EXAMPLE

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

SEE ALSO

144       nbd_create(3), nbd_opt_info(3), "Flag calls" in libnbd(3), "Multi-conn"
145       in libnbd(3), libnbd(3).
146

AUTHORS

148       Eric Blake
149
150       Richard W.M. Jones
151
153       Copyright (C) 2019-2020 Red Hat Inc.
154

LICENSE

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