1nbd_block_status(3)                 LIBNBD                 nbd_block_status(3)
2
3
4

NAME

6       nbd_block_status - send block status command to the NBD server
7

SYNOPSIS

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

DESCRIPTION

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       Depending on which metadata contexts were enabled before connecting
35       (see nbd_add_meta_context(3)) and which are supported by the server
36       (see nbd_can_meta_context(3)) this call returns information about
37       extents by calling back to the "extent" function.  The callback cannot
38       call "nbd_*" APIs on the same handle since it holds the handle lock and
39       will cause a deadlock.  If the callback returns "-1", and no earlier
40       error has been detected, then the overall block status command will
41       fail with any non-zero value stored into the callback's "error"
42       parameter (with a default of "EPROTO"); but any further contexts will
43       still invoke the callback.
44
45       The "extent" function is called once per type of metadata available,
46       with the "user_data" passed to this function.  The "metacontext"
47       parameter is a string such as "base:allocation".  The "entries" array
48       is an array of pairs of integers with the first entry in each pair
49       being the length (in bytes) of the block and the second entry being a
50       status/flags field which is specific to the metadata context.  (The
51       number of pairs passed to the function is "nr_entries/2".)  The NBD
52       protocol document in the section about "NBD_REPLY_TYPE_BLOCK_STATUS"
53       describes the meaning of this array; for contexts known to libnbd,
54       <libnbd.h> contains constants beginning with "LIBNBD_STATE_" that may
55       help decipher the values.  On entry to the callback, the "error"
56       parameter contains the errno value of any previously detected error.
57
58       It is possible for the extent function to be called more times than you
59       expect (if the server is buggy), so always check the "metacontext"
60       field to ensure you are receiving the data you expect.  It is also
61       possible that the extent function is not called at all, even for
62       metadata contexts that you requested.  This indicates either that the
63       server doesn't support the context or for some other reason cannot
64       return the data.
65
66       The "flags" parameter may be 0 for no flags, or may contain
67       "LIBNBD_CMD_FLAG_REQ_ONE" meaning that the server should return only
68       one extent per metadata context where that extent does not exceed
69       "count" bytes; however, libnbd does not validate that the server obeyed
70       the flag.
71
72       By default, libnbd will reject attempts to use this function with
73       parameters that are likely to result in server failure, such as
74       requesting an unknown command flag.  The nbd_set_strict_mode(3)
75       function can be used to alter which scenarios should await a server
76       reply rather than failing fast.
77

RETURN VALUE

79       If the call is successful the function returns 0.
80

ERRORS

82       On error "-1" is returned.
83
84       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
85       of the error.
86

HANDLE STATE

88       The handle must be connected with the server, otherwise this call will
89       return an error.
90

VERSION

92       This function first appeared in libnbd 1.0.
93
94       If you need to test if this function is available at compile time check
95       if the following macro is defined:
96
97        #define LIBNBD_HAVE_NBD_BLOCK_STATUS 1
98

SEE ALSO

100       nbd_add_meta_context(3), nbd_aio_block_status(3),
101       nbd_can_meta_context(3), nbd_create(3), nbd_set_strict_mode(3),
102       libnbd(3).
103

AUTHORS

105       Eric Blake
106
107       Richard W.M. Jones
108
110       Copyright (C) 2019-2020 Red Hat Inc.
111

LICENSE

113       This library is free software; you can redistribute it and/or modify it
114       under the terms of the GNU Lesser General Public License as published
115       by the Free Software Foundation; either version 2 of the License, or
116       (at your option) any later version.
117
118       This library is distributed in the hope that it will be useful, but
119       WITHOUT ANY WARRANTY; without even the implied warranty of
120       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
121       Lesser General Public License for more details.
122
123       You should have received a copy of the GNU Lesser General Public
124       License along with this library; if not, write to the Free Software
125       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
126       02110-1301 USA
127
128
129
130libnbd-1.6.2                      2021-03-02               nbd_block_status(3)
Impressum