1nbd_can_zero(3)                     LIBNBD                     nbd_can_zero(3)
2
3
4

NAME

6       nbd_can_zero - does the server support the zero command?
7

SYNOPSIS

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

DESCRIPTION

14       Returns true if the server supports the zero command (see nbd_zero(3),
15       nbd_aio_zero(3)).  Returns false if the server does not.
16
17       This call does not block, because it returns data that is saved in the
18       handle from the NBD protocol handshake.
19

RETURN VALUE

21       This call returns a boolean value.
22

ERRORS

24       On error "-1" is returned.
25
26       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
27       of the error.
28

HANDLE STATE

30       The handle must be connected and finished handshaking with the server,
31       or shut down, otherwise this call will return an error.
32

VERSION

34       This function first appeared in libnbd 1.0.
35
36       If you need to test if this function is available at compile time check
37       if the following macro is defined:
38
39        #define LIBNBD_HAVE_NBD_CAN_ZERO 1
40

EXAMPLE

42       This example is also available as examples/server-flags.c in the libnbd
43       source code.
44
45        /* This example shows how to connect to an NBD
46         * server and print the export flags.
47         *
48         * You can test it with nbdkit like this:
49         *
50         * nbdkit -U - memory 1M \
51         *   --run './server-flags $unixsocket'
52         */
53
54        #include <stdio.h>
55        #include <stdlib.h>
56
57        #include <libnbd.h>
58
59        int
60        main (int argc, char *argv[])
61        {
62          struct nbd_handle *nbd;
63          int flag;
64
65          if (argc != 2) {
66            fprintf (stderr, "%s socket\n", argv[0]);
67            exit (EXIT_FAILURE);
68          }
69
70          /* Create the libnbd handle. */
71          nbd = nbd_create ();
72          if (nbd == NULL) {
73            fprintf (stderr, "%s\n", nbd_get_error ());
74            exit (EXIT_FAILURE);
75          }
76
77          /* Connect to the NBD server over a
78           * Unix domain socket.
79           */
80          if (nbd_connect_unix (nbd, argv[1]) == -1) {
81            fprintf (stderr, "%s\n", nbd_get_error ());
82            exit (EXIT_FAILURE);
83          }
84
85          /* Read and print the flags. */
86        #define PRINT_FLAG(flag_fn)                     \
87          flag = flag_fn (nbd);                         \
88          if (flag == -1) {                             \
89            fprintf (stderr, "%s\n", nbd_get_error ()); \
90            exit (EXIT_FAILURE);                        \
91          }                                             \
92          printf (#flag_fn " = %s\n",                   \
93                  flag ? "true" : "false");
94
95          PRINT_FLAG (nbd_can_cache);
96          PRINT_FLAG (nbd_can_df);
97          PRINT_FLAG (nbd_can_flush);
98          PRINT_FLAG (nbd_can_fua);
99          PRINT_FLAG (nbd_can_multi_conn);
100          PRINT_FLAG (nbd_can_trim);
101          PRINT_FLAG (nbd_can_zero);
102        #if LIBNBD_HAVE_NBD_CAN_FAST_ZERO /* Added in 1.2 */
103          PRINT_FLAG (nbd_can_fast_zero);
104        #endif
105          PRINT_FLAG (nbd_is_read_only);
106          PRINT_FLAG (nbd_is_rotational);
107
108          /* Close the libnbd handle. */
109          nbd_close (nbd);
110
111          exit (EXIT_SUCCESS);
112        }
113

SEE ALSO

115       "Flag calls" in libnbd(3), nbd_zero(3), nbd_aio_zero(3),
116       nbd_can_fast_zero(3), nbd_create(3), libnbd(3).
117

AUTHORS

119       Eric Blake
120
121       Richard W.M. Jones
122
124       Copyright (C) 2019 Red Hat Inc.
125

LICENSE

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