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