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