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