1nbd_can_multi_conn(3) LIBNBD nbd_can_multi_conn(3)
2
3
4
6 nbd_can_multi_conn - does the server support multi-conn?
7
9 #include <libnbd.h>
10
11 int nbd_can_multi_conn (struct nbd_handle *h);
12
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
27 This call returns a boolean value.
28
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
35 The following parameters must not be NULL: "h". For more information
36 see "Non-NULL parameters" in libnbd(3).
37
39 The handle must be negotiating, or connected with the server, or shut
40 down, otherwise this call will return an error.
41
43 This function first appeared in libnbd 1.0.
44
45 If you need to test if this function is available at compile time check
46 if the following macro is defined:
47
48 #define LIBNBD_HAVE_NBD_CAN_MULTI_CONN 1
49
51 This example is also available as examples/server-flags.c in the libnbd
52 source code.
53
54 /* This example shows how to connect to an NBD
55 * server and print the export flags.
56 *
57 * You can test it with nbdkit like this:
58 *
59 * nbdkit -U - memory 1M \
60 * --run './server-flags $unixsocket'
61 */
62
63 #include <stdio.h>
64 #include <stdlib.h>
65
66 #include <libnbd.h>
67
68 int
69 main (int argc, char *argv[])
70 {
71 struct nbd_handle *nbd;
72 char *str;
73 int flag;
74
75 if (argc != 2) {
76 fprintf (stderr, "%s socket\n", argv[0]);
77 exit (EXIT_FAILURE);
78 }
79
80 /* Create the libnbd handle. */
81 nbd = nbd_create ();
82 if (nbd == NULL) {
83 fprintf (stderr, "%s\n", nbd_get_error ());
84 exit (EXIT_FAILURE);
85 }
86
87 /* Request full information. */
88 #if LIBNBD_HAVE_NBD_SET_FULL_INFO /* Added in 1.4 */
89 if (nbd_set_full_info (nbd, true) == -1) {
90 fprintf (stderr, "%s\n", nbd_get_error ());
91 exit (EXIT_FAILURE);
92 }
93 #endif
94
95 /* Connect to the NBD server over a
96 * Unix domain socket.
97 */
98 if (nbd_connect_unix (nbd, argv[1]) == -1) {
99 fprintf (stderr, "%s\n", nbd_get_error ());
100 exit (EXIT_FAILURE);
101 }
102
103 /* See if the server provided extra details,
104 * using functions added in 1.4
105 */
106 #if LIBNBD_HAVE_NBD_GET_EXPORT_DESCRIPTION
107 str = nbd_get_canonical_export_name (nbd);
108 if (str)
109 printf ("canonical_name = %s\n", str);
110 free (str);
111 str = nbd_get_export_description (nbd);
112 if (str)
113 printf ("description = %s\n", str);
114 free (str);
115 #endif
116
117 /* Read and print the flags. */
118 #define PRINT_FLAG(flag_fn) \
119 flag = flag_fn (nbd); \
120 if (flag == -1) { \
121 fprintf (stderr, "%s\n", nbd_get_error ()); \
122 exit (EXIT_FAILURE); \
123 } \
124 printf (#flag_fn " = %s\n", \
125 flag ? "true" : "false");
126
127 PRINT_FLAG (nbd_can_cache);
128 PRINT_FLAG (nbd_can_df);
129 PRINT_FLAG (nbd_can_flush);
130 PRINT_FLAG (nbd_can_fua);
131 PRINT_FLAG (nbd_can_multi_conn);
132 PRINT_FLAG (nbd_can_trim);
133 PRINT_FLAG (nbd_can_zero);
134 #if LIBNBD_HAVE_NBD_CAN_FAST_ZERO /* Added in 1.2 */
135 PRINT_FLAG (nbd_can_fast_zero);
136 #endif
137 PRINT_FLAG (nbd_is_read_only);
138 PRINT_FLAG (nbd_is_rotational);
139
140 /* Close the libnbd handle. */
141 nbd_close (nbd);
142
143 exit (EXIT_SUCCESS);
144 }
145
147 nbd_create(3), nbd_opt_info(3), "Flag calls" in libnbd(3), "Multi-conn"
148 in libnbd(3), libnbd(3).
149
151 Eric Blake
152
153 Richard W.M. Jones
154
156 Copyright (C) 2019-2021 Red Hat Inc.
157
159 This library is free software; you can redistribute it and/or modify it
160 under the terms of the GNU Lesser General Public License as published
161 by the Free Software Foundation; either version 2 of the License, or
162 (at your option) any later version.
163
164 This library is distributed in the hope that it will be useful, but
165 WITHOUT ANY WARRANTY; without even the implied warranty of
166 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
167 Lesser General Public License for more details.
168
169 You should have received a copy of the GNU Lesser General Public
170 License along with this library; if not, write to the Free Software
171 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
172 02110-1301 USA
173
174
175
176libnbd-1.14.2 2023-01-03 nbd_can_multi_conn(3)