1nbd_can_zero(3) LIBNBD nbd_can_zero(3)
2
3
4
6 nbd_can_zero - does the server support the zero command?
7
9 #include <libnbd.h>
10
11 int nbd_can_zero (
12 struct nbd_handle *h
13 );
14
16 Returns true if the server supports the zero command (see nbd_zero(3),
17 nbd_aio_zero(3)). Returns false if the server does not.
18
19 This call does not block, because it returns data that is saved in the
20 handle from the NBD protocol handshake.
21
23 This call returns a boolean value.
24
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
35 The handle must be negotiating, or connected with the server, or shut
36 down, otherwise this call will return an error.
37
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_CAN_ZERO 1
45
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
131 /* Added in 1.2 */
132 PRINT_FLAG (nbd_can_fast_zero);
133 #endif
134 #if LIBNBD_HAVE_NBD_CAN_BLOCK_STATUS_PAYLOAD
135 /* Added in 1.18 */
136 PRINT_FLAG (nbd_can_block_status_payload);
137 #endif
138 PRINT_FLAG (nbd_is_read_only);
139 PRINT_FLAG (nbd_is_rotational);
140
141 /* Close the libnbd handle. */
142 nbd_close (nbd);
143
144 exit (EXIT_SUCCESS);
145 }
146
148 nbd_aio_zero(3), nbd_can_fast_zero(3), nbd_create(3), nbd_opt_info(3),
149 nbd_zero(3), "Flag calls" in libnbd(3), libnbd(3).
150
152 Eric Blake
153
154 Richard W.M. Jones
155
157 Copyright Red Hat
158
160 This library is free software; you can redistribute it and/or modify it
161 under the terms of the GNU Lesser General Public License as published
162 by the Free Software Foundation; either version 2 of the License, or
163 (at your option) any later version.
164
165 This library is distributed in the hope that it will be useful, but
166 WITHOUT ANY WARRANTY; without even the implied warranty of
167 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
168 Lesser General Public License for more details.
169
170 You should have received a copy of the GNU Lesser General Public
171 License along with this library; if not, write to the Free Software
172 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
173 02110-1301 USA
174
175
176
177libnbd-1.18.1 2023-10-31 nbd_can_zero(3)