1nbd_can_flush(3)                    LIBNBD                    nbd_can_flush(3)
2
3
4

NAME

6       nbd_can_flush - does the server support the flush command?
7

SYNOPSIS

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

DESCRIPTION

14       Returns true if the server supports the flush command (see
15       nbd_flush(3), nbd_aio_flush(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 negotiating, or connected with the server, or shut
31       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_FLUSH 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          char *str;
64          int flag;
65
66          if (argc != 2) {
67            fprintf (stderr, "%s socket\n", argv[0]);
68            exit (EXIT_FAILURE);
69          }
70
71          /* Create the libnbd handle. */
72          nbd = nbd_create ();
73          if (nbd == NULL) {
74            fprintf (stderr, "%s\n", nbd_get_error ());
75            exit (EXIT_FAILURE);
76          }
77
78          /* Request full information. */
79        #if LIBNBD_HAVE_NBD_SET_FULL_INFO /* Added in 1.4 */
80          if (nbd_set_full_info (nbd, true) == -1) {
81            fprintf (stderr, "%s\n", nbd_get_error ());
82            exit (EXIT_FAILURE);
83          }
84        #endif
85
86          /* Connect to the NBD server over a
87           * Unix domain socket.
88           */
89          if (nbd_connect_unix (nbd, argv[1]) == -1) {
90            fprintf (stderr, "%s\n", nbd_get_error ());
91            exit (EXIT_FAILURE);
92          }
93
94          /* See if the server provided extra details,
95           * using functions added in 1.4
96           */
97        #if LIBNBD_HAVE_NBD_GET_EXPORT_DESCRIPTION
98          str = nbd_get_canonical_export_name (nbd);
99          if (str)
100            printf ("canonical_name = %s\n", str);
101          free (str);
102          str = nbd_get_export_description (nbd);
103          if (str)
104            printf ("description = %s\n", str);
105          free (str);
106        #endif
107
108          /* Read and print the flags. */
109        #define PRINT_FLAG(flag_fn)                     \
110          flag = flag_fn (nbd);                         \
111          if (flag == -1) {                             \
112            fprintf (stderr, "%s\n", nbd_get_error ()); \
113            exit (EXIT_FAILURE);                        \
114          }                                             \
115          printf (#flag_fn " = %s\n",                   \
116                  flag ? "true" : "false");
117
118          PRINT_FLAG (nbd_can_cache);
119          PRINT_FLAG (nbd_can_df);
120          PRINT_FLAG (nbd_can_flush);
121          PRINT_FLAG (nbd_can_fua);
122          PRINT_FLAG (nbd_can_multi_conn);
123          PRINT_FLAG (nbd_can_trim);
124          PRINT_FLAG (nbd_can_zero);
125        #if LIBNBD_HAVE_NBD_CAN_FAST_ZERO /* Added in 1.2 */
126          PRINT_FLAG (nbd_can_fast_zero);
127        #endif
128          PRINT_FLAG (nbd_is_read_only);
129          PRINT_FLAG (nbd_is_rotational);
130
131          /* Close the libnbd handle. */
132          nbd_close (nbd);
133
134          exit (EXIT_SUCCESS);
135        }
136

SEE ALSO

138       nbd_aio_flush(3), nbd_create(3), nbd_flush(3), nbd_opt_info(3), "Flag
139       calls" in libnbd(3), libnbd(3).
140

AUTHORS

142       Eric Blake
143
144       Richard W.M. Jones
145
147       Copyright (C) 2019-2021 Red Hat Inc.
148

LICENSE

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