1nbd_get_canonical_export_name(3)    LIBNBD    nbd_get_canonical_export_name(3)
2
3
4

NAME

6       nbd_get_canonical_export_name - return the canonical export name, if
7       the server has one
8

SYNOPSIS

10        #include <libnbd.h>
11
12        char * nbd_get_canonical_export_name (struct nbd_handle *h);
13

DESCRIPTION

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

RETURN VALUE

26       This call returns a string.  The caller must free the returned string
27       to avoid a memory leak.
28

ERRORS

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

HANDLE STATE

39       The handle must be negotiating, or connected with the server, or shut
40       down, otherwise this call will return an error.
41

VERSION

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_CANONICAL_EXPORT_NAME 1
49

EXAMPLE

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

SEE ALSO

147       nbd_connect_uri(3), nbd_create(3), nbd_get_export_name(3),
148       nbd_opt_info(3), nbd_set_export_name(3), nbd_set_full_info(3),
149       libnbd(3).
150

AUTHORS

152       Eric Blake
153
154       Richard W.M. Jones
155
157       Copyright (C) 2019-2021 Red Hat Inc.
158

LICENSE

160       This library is free software; you can redistribute it and/or modify it
161       under the terms of the GNU Lesser General Public License as published
162       by the Free Software Foundation; either version 2 of the License, or
163       (at your option) any later version.
164
165       This library is distributed in the hope that it will be useful, but
166       WITHOUT ANY WARRANTY; without even the implied warranty of
167       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
168       Lesser General Public License for more details.
169
170       You should have received a copy of the GNU Lesser General Public
171       License along with this library; if not, write to the Free Software
172       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
173       02110-1301 USA
174
175
176
177libnbd-1.14.2                     2023-01-03  nbd_get_canonical_export_name(3)
Impressum