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