1nbd_is_read_only(3)                 LIBNBD                 nbd_is_read_only(3)
2
3
4

NAME

6       nbd_is_read_only - is the NBD export read-only?
7

SYNOPSIS

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

DESCRIPTION

16       Returns true if the NBD export is read-only; writes and write-like
17       operations will fail.
18
19       This call does not block, because it returns data that is saved in the
20       handle from the NBD protocol handshake.
21

RETURN VALUE

23       This call returns a boolean value.
24

ERRORS

26       On error -1 is returned.
27
28       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
29       of the error.
30
31       The following parameters must not be NULL: "h".  For more information
32       see "Non-NULL parameters" in libnbd(3).
33

HANDLE STATE

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

VERSION

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

EXAMPLE

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

SEE ALSO

143       nbd_create(3), nbd_opt_info(3), "Flag calls" in libnbd(3), libnbd(3).
144

AUTHORS

146       Eric Blake
147
148       Richard W.M. Jones
149
151       Copyright Red Hat
152

LICENSE

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