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

RETURN VALUE

73       If the call is successful the function returns 0.
74

ERRORS

76       On error "-1" is returned.
77
78       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
79       of the error.
80

HANDLE STATE

82       The handle must be connected and finished handshaking with the server,
83       otherwise this call will return an error.
84

VERSION

86       This function first appeared in libnbd 1.0.
87
88       If you need to test if this function is available at compile time check
89       if the following macro is defined:
90
91        #define LIBNBD_HAVE_NBD_BLOCK_STATUS 1
92

SEE ALSO

94       nbd_add_meta_context(3), nbd_aio_block_status(3),
95       nbd_can_meta_context(3), nbd_create(3), libnbd(3).
96

AUTHORS

98       Eric Blake
99
100       Richard W.M. Jones
101
103       Copyright (C) 2019 Red Hat Inc.
104

LICENSE

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