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