1nbd_can_df(3) LIBNBD nbd_can_df(3)
2
3
4
6 nbd_can_df - does the server support the don't fragment flag to pread?
7
9 #include <libnbd.h>
10
11 int nbd_can_df (struct nbd_handle *h);
12
14 Returns true if the server supports structured reads with an ability to
15 request a non-fragmented read (see nbd_pread_structured(3),
16 nbd_aio_pread_structured(3)). Returns false if the server either lacks
17 structured reads or if it does not support a non-fragmented read
18 request.
19
20 This call does not block, because it returns data that is saved in the
21 handle from the NBD protocol handshake.
22
24 This call returns a boolean value.
25
27 On error "-1" is returned.
28
29 Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
30 of the error.
31
33 This function first appeared in libnbd 1.0.
34
35 If you need to test if this function is available at compile time check
36 if the following macro is defined:
37
38 #define LIBNBD_HAVE_NBD_CAN_DF 1
39
41 This example is also available as examples/server-flags.c in the libnbd
42 source code.
43
44 /* This example shows how to connect to an NBD
45 * server and print the export flags.
46 *
47 * You can test it with nbdkit like this:
48 *
49 * nbdkit -U - memory 1M \
50 * --run './server-flags $unixsocket'
51 */
52
53 #include <stdio.h>
54 #include <stdlib.h>
55
56 #include <libnbd.h>
57
58 int
59 main (int argc, char *argv[])
60 {
61 struct nbd_handle *nbd;
62 int flag;
63
64 if (argc != 2) {
65 fprintf (stderr, "%s socket\n", argv[0]);
66 exit (EXIT_FAILURE);
67 }
68
69 /* Create the libnbd handle. */
70 nbd = nbd_create ();
71 if (nbd == NULL) {
72 fprintf (stderr, "%s\n", nbd_get_error ());
73 exit (EXIT_FAILURE);
74 }
75
76 /* Connect to the NBD server over a
77 * Unix domain socket.
78 */
79 if (nbd_connect_unix (nbd, argv[1]) == -1) {
80 fprintf (stderr, "%s\n", nbd_get_error ());
81 exit (EXIT_FAILURE);
82 }
83
84 /* Read and print the flags. */
85 #define PRINT_FLAG(flag_fn) \
86 flag = flag_fn (nbd); \
87 if (flag == -1) { \
88 fprintf (stderr, "%s\n", nbd_get_error ()); \
89 exit (EXIT_FAILURE); \
90 } \
91 printf (#flag_fn " = %s\n", \
92 flag ? "true" : "false");
93
94 PRINT_FLAG (nbd_can_cache);
95 PRINT_FLAG (nbd_can_df);
96 PRINT_FLAG (nbd_can_flush);
97 PRINT_FLAG (nbd_can_fua);
98 PRINT_FLAG (nbd_can_multi_conn);
99 PRINT_FLAG (nbd_can_trim);
100 PRINT_FLAG (nbd_can_zero);
101 #if LIBNBD_HAVE_NBD_CAN_FAST_ZERO /* Added in 1.2 */
102 PRINT_FLAG (nbd_can_fast_zero);
103 #endif
104 PRINT_FLAG (nbd_is_read_only);
105 PRINT_FLAG (nbd_is_rotational);
106
107 /* Close the libnbd handle. */
108 nbd_close (nbd);
109
110 exit (EXIT_SUCCESS);
111 }
112
114 "Flag calls" in libnbd(3), nbd_pread_structured(3),
115 nbd_aio_pread_structured(3), nbd_create(3), libnbd(3).
116
118 Eric Blake
119
120 Richard W.M. Jones
121
123 Copyright (C) 2019 Red Hat Inc.
124
126 This library is free software; you can redistribute it and/or modify it
127 under the terms of the GNU Lesser General Public License as published
128 by the Free Software Foundation; either version 2 of the License, or
129 (at your option) any later version.
130
131 This library is distributed in the hope that it will be useful, but
132 WITHOUT ANY WARRANTY; without even the implied warranty of
133 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
134 Lesser General Public License for more details.
135
136 You should have received a copy of the GNU Lesser General Public
137 License along with this library; if not, write to the Free Software
138 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
139 02110-1301 USA
140
141
142
143libnbd-1.2.1 2019-11-14 nbd_can_df(3)