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