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 connected and finished handshaking with the server,
37       or shut 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          int flag;
70
71          if (argc != 2) {
72            fprintf (stderr, "%s socket\n", argv[0]);
73            exit (EXIT_FAILURE);
74          }
75
76          /* Create the libnbd handle. */
77          nbd = nbd_create ();
78          if (nbd == NULL) {
79            fprintf (stderr, "%s\n", nbd_get_error ());
80            exit (EXIT_FAILURE);
81          }
82
83          /* Connect to the NBD server over a
84           * Unix domain socket.
85           */
86          if (nbd_connect_unix (nbd, argv[1]) == -1) {
87            fprintf (stderr, "%s\n", nbd_get_error ());
88            exit (EXIT_FAILURE);
89          }
90
91          /* Read and print the flags. */
92        #define PRINT_FLAG(flag_fn)                     \
93          flag = flag_fn (nbd);                         \
94          if (flag == -1) {                             \
95            fprintf (stderr, "%s\n", nbd_get_error ()); \
96            exit (EXIT_FAILURE);                        \
97          }                                             \
98          printf (#flag_fn " = %s\n",                   \
99                  flag ? "true" : "false");
100
101          PRINT_FLAG (nbd_can_cache);
102          PRINT_FLAG (nbd_can_df);
103          PRINT_FLAG (nbd_can_flush);
104          PRINT_FLAG (nbd_can_fua);
105          PRINT_FLAG (nbd_can_multi_conn);
106          PRINT_FLAG (nbd_can_trim);
107          PRINT_FLAG (nbd_can_zero);
108        #if LIBNBD_HAVE_NBD_CAN_FAST_ZERO /* Added in 1.2 */
109          PRINT_FLAG (nbd_can_fast_zero);
110        #endif
111          PRINT_FLAG (nbd_is_read_only);
112          PRINT_FLAG (nbd_is_rotational);
113
114          /* Close the libnbd handle. */
115          nbd_close (nbd);
116
117          exit (EXIT_SUCCESS);
118        }
119

SEE ALSO

121       nbd_create(3), "Multi-conn" in libnbd(3), libnbd(3).
122

AUTHORS

124       Eric Blake
125
126       Richard W.M. Jones
127
129       Copyright (C) 2019 Red Hat Inc.
130

LICENSE

132       This library is free software; you can redistribute it and/or modify it
133       under the terms of the GNU Lesser General Public License as published
134       by the Free Software Foundation; either version 2 of the License, or
135       (at your option) any later version.
136
137       This library is distributed in the hope that it will be useful, but
138       WITHOUT ANY WARRANTY; without even the implied warranty of
139       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
140       Lesser General Public License for more details.
141
142       You should have received a copy of the GNU Lesser General Public
143       License along with this library; if not, write to the Free Software
144       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
145       02110-1301 USA
146
147
148
149libnbd-1.3.7                      2020-04-23             nbd_can_multi_conn(3)
Impressum