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