1nbd_block_status(3) LIBNBD nbd_block_status(3)
2
3
4
6 nbd_block_status - send block status command to the NBD server
7
9 #include <libnbd.h>
10
11 typedef struct {
12 int (*callback) (void *user_data,
13 const char *metacontext,
14 uint64_t offset, uint32_t *entries,
15 size_t nr_entries, int *error);
16 void *user_data;
17 void (*free) (void *user_data);
18 } nbd_extent_callback;
19
20 int nbd_block_status (
21 struct nbd_handle *h, uint64_t count,
22 uint64_t offset, nbd_extent_callback extent_callback,
23 uint32_t flags
24 );
25
27 Issue the block status command to the NBD server. If supported by the
28 server, this causes metadata context information about blocks beginning
29 from the specified offset to be returned. The "count" parameter is a
30 hint: the server may choose to return less status, or the final block
31 may extend beyond the requested range. If multiple contexts are
32 supported, the number of blocks and cumulative length of those blocks
33 need not be identical between contexts.
34
35 Note that not all servers can support a "count" of 4GiB or larger. The
36 NBD protocol does not yet have a way for a client to learn if the
37 server will enforce an even smaller maximum block status size, although
38 a future extension may add a constraint visible in
39 nbd_get_block_size(3).
40
41 Depending on which metadata contexts were enabled before connecting
42 (see nbd_add_meta_context(3)) and which are supported by the server
43 (see nbd_can_meta_context(3)) this call returns information about
44 extents by calling back to the "extent" function. The callback cannot
45 call "nbd_*" APIs on the same handle since it holds the handle lock and
46 will cause a deadlock. If the callback returns -1, and no earlier
47 error has been detected, then the overall block status command will
48 fail with any non-zero value stored into the callback's "error"
49 parameter (with a default of "EPROTO"); but any further contexts will
50 still invoke the callback.
51
52 The "extent" function is called once per type of metadata available,
53 with the "user_data" passed to this function. The "metacontext"
54 parameter is a string such as "base:allocation". The "entries" array
55 is an array of pairs of integers with the first entry in each pair
56 being the length (in bytes) of the block and the second entry being a
57 status/flags field which is specific to the metadata context. (The
58 number of pairs passed to the function is "nr_entries/2".) The NBD
59 protocol document in the section about "NBD_REPLY_TYPE_BLOCK_STATUS"
60 describes the meaning of this array; for contexts known to libnbd,
61 <libnbd.h> contains constants beginning with "LIBNBD_STATE_" that may
62 help decipher the values. On entry to the callback, the "error"
63 parameter contains the errno value of any previously detected error,
64 but even if an earlier error was detected, the current "metacontext"
65 and "entries" are valid.
66
67 It is possible for the extent function to be called more times than you
68 expect (if the server is buggy), so always check the "metacontext"
69 field to ensure you are receiving the data you expect. It is also
70 possible that the extent function is not called at all, even for
71 metadata contexts that you requested. This indicates either that the
72 server doesn't support the context or for some other reason cannot
73 return the data.
74
75 The "flags" parameter may be 0 for no flags, or may contain
76 "LIBNBD_CMD_FLAG_REQ_ONE" meaning that the server should return only
77 one extent per metadata context where that extent does not exceed
78 "count" bytes; however, libnbd does not validate that the server obeyed
79 the flag.
80
81 By default, libnbd will reject attempts to use this function with
82 parameters that are likely to result in server failure, such as
83 requesting an unknown command flag. The nbd_set_strict_mode(3)
84 function can be used to alter which scenarios should await a server
85 reply rather than failing fast.
86
88 If the call is successful the function returns 0.
89
91 On error -1 is returned.
92
93 Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
94 of the error.
95
96 The following parameters must not be NULL: "h". For more information
97 see "Non-NULL parameters" in libnbd(3).
98
100 The handle must be connected with the server, otherwise this call will
101 return an error.
102
104 This function first appeared in libnbd 1.0.
105
106 If you need to test if this function is available at compile time check
107 if the following macro is defined:
108
109 #define LIBNBD_HAVE_NBD_BLOCK_STATUS 1
110
112 nbd_add_meta_context(3), nbd_aio_block_status(3),
113 nbd_can_meta_context(3), nbd_create(3), nbd_get_block_size(3),
114 nbd_set_strict_mode(3), libnbd(3).
115
117 Eric Blake
118
119 Richard W.M. Jones
120
122 Copyright Red Hat
123
125 This library is free software; you can redistribute it and/or modify it
126 under the terms of the GNU Lesser General Public License as published
127 by the Free Software Foundation; either version 2 of the License, or
128 (at your option) any later version.
129
130 This library is distributed in the hope that it will be useful, but
131 WITHOUT ANY WARRANTY; without even the implied warranty of
132 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
133 Lesser General Public License for more details.
134
135 You should have received a copy of the GNU Lesser General Public
136 License along with this library; if not, write to the Free Software
137 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
138 02110-1301 USA
139
140
141
142libnbd-1.16.5 2023-09-26 nbd_block_status(3)