1nbd_can_fast_zero(3)                LIBNBD                nbd_can_fast_zero(3)
2
3
4

NAME

6       nbd_can_fast_zero - does the server support the fast zero flag?
7

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

22       This call returns a boolean value.
23

ERRORS

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
30       The following parameters must not be NULL: "h".  For more information
31       see "Non-NULL parameters" in libnbd(3).
32

HANDLE STATE

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

VERSION

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

EXAMPLE

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

SEE ALSO

142       nbd_aio_zero(3), nbd_can_zero(3), nbd_create(3), nbd_opt_info(3),
143       nbd_zero(3), "Flag calls" in libnbd(3), libnbd(3).
144

AUTHORS

146       Eric Blake
147
148       Richard W.M. Jones
149
151       Copyright (C) 2019-2021 Red Hat Inc.
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.14.2                     2023-01-03              nbd_can_fast_zero(3)
Impressum