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