1nbd_pread_structured(3)             LIBNBD             nbd_pread_structured(3)
2
3
4

NAME

6       nbd_pread_structured - read from the NBD server
7

SYNOPSIS

9        #include <libnbd.h>
10
11        typedef struct {
12          int (*callback) (void *user_data, const void *subbuf,
13                           size_t count, uint64_t offset,
14                           unsigned status, int *error);
15          void *user_data;
16          void (*free) (void *user_data);
17        } nbd_chunk_callback;
18
19        int nbd_pread_structured (
20              struct nbd_handle *h, void *buf, size_t count,
21              uint64_t offset, nbd_chunk_callback chunk_callback,
22              uint32_t flags
23            );
24

DESCRIPTION

26       Issue a read command to the NBD server for the range starting at
27       "offset" and ending at "offset" + "count" - 1.  The server's response
28       may be subdivided into chunks which may arrive out of order before
29       reassembly into the original buffer; the "chunk" callback is used for
30       notification after each chunk arrives, and may perform additional
31       sanity checking on the server's reply. The callback cannot call "nbd_*"
32       APIs on the same handle since it holds the handle lock and will cause a
33       deadlock.  If the callback returns -1, and no earlier error has been
34       detected, then the overall read command will fail with any non-zero
35       value stored into the callback's "error" parameter (with a default of
36       "EPROTO"); but any further chunks will still invoke the callback.
37
38       The "chunk" function is called once per chunk of data received, with
39       the "user_data" passed to this function.  The "subbuf" and "count"
40       parameters represent the subset of the original buffer which has just
41       been populated by results from the server (in C, "subbuf" always points
42       within the original "buf"; but this guarantee may not extend to other
43       language bindings). The "offset" parameter represents the absolute
44       offset at which "subbuf" begins within the image (note that this is not
45       the relative offset of "subbuf" within the original buffer "buf").
46       Changes to "error" on output are ignored unless the callback fails. The
47       input meaning of the "error" parameter is controlled by the "status"
48       parameter, which is one of
49
50       "LIBNBD_READ_DATA" = 1
51           "subbuf" was populated with "count" bytes of data. On input,
52           "error" contains the errno value of any earlier detected error, or
53           zero.
54
55       "LIBNBD_READ_HOLE" = 2
56           "subbuf" represents a hole, and contains "count" NUL bytes. On
57           input, "error" contains the errno value of any earlier detected
58           error, or zero.
59
60       "LIBNBD_READ_ERROR" = 3
61           "count" is 0, so "subbuf" is unusable. On input, "error" contains
62           the errno value reported by the server as occurring while reading
63           that "offset", regardless if any earlier error has been detected.
64
65       Future NBD extensions may permit other values for "status", but those
66       will not be returned to a client that has not opted in to requesting
67       such extensions. If the server is non-compliant, it is possible for the
68       "chunk" function to be called more times than you expect or with
69       "count" 0 for "LIBNBD_READ_DATA" or "LIBNBD_READ_HOLE". It is also
70       possible that the "chunk" function is not called at all (in particular,
71       "LIBNBD_READ_ERROR" is used only when an error is associated with a
72       particular offset, and not when the server reports a generic error),
73       but you are guaranteed that the callback was called at least once if
74       the overall read succeeds. Libnbd does not validate that the server
75       obeyed the requirement that a read call must not have overlapping
76       chunks and must not succeed without enough chunks to cover the entire
77       request.
78
79       Note that libnbd currently enforces a maximum read buffer of 64MiB,
80       even if the server would permit a larger buffer in a single
81       transaction; attempts to exceed this will result in an "ERANGE" error.
82       The server may enforce a smaller limit, which can be learned with
83       nbd_get_block_size(3).
84
85       The "flags" parameter may be 0 for no flags, or may contain
86       "LIBNBD_CMD_FLAG_DF" meaning that the server should not reply with more
87       than one fragment (if that is supported - some servers cannot do this,
88       see nbd_can_df(3)). Libnbd does not validate that the server actually
89       obeys the flag.
90
91       Note that if this command fails, and nbd_get_pread_initialize(3)
92       returns true, then libnbd sanitized "buf", but it is unspecified
93       whether the contents of "buf" will read as zero or as partial results
94       from the server.  If nbd_get_pread_initialize(3) returns false, then
95       libnbd did not sanitize "buf", and the contents are undefined on
96       failure.
97
98       By default, libnbd will reject attempts to use this function with
99       parameters that are likely to result in server failure, such as
100       requesting an unknown command flag.  The nbd_set_strict_mode(3)
101       function can be used to alter which scenarios should await a server
102       reply rather than failing fast.
103

RETURN VALUE

105       If the call is successful the function returns 0.
106

ERRORS

108       On error -1 is returned.
109
110       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
111       of the error.
112
113       The following parameters must not be NULL: "h", "buf".  For more
114       information see "Non-NULL parameters" in libnbd(3).
115

HANDLE STATE

117       The handle must be connected with the server, otherwise this call will
118       return an error.
119

VERSION

121       This function first appeared in libnbd 1.0.
122
123       If you need to test if this function is available at compile time check
124       if the following macro is defined:
125
126        #define LIBNBD_HAVE_NBD_PREAD_STRUCTURED 1
127

SEE ALSO

129       nbd_aio_pread_structured(3), nbd_can_df(3), nbd_create(3),
130       nbd_get_block_size(3), nbd_get_pread_initialize(3), nbd_pread(3),
131       nbd_set_pread_initialize(3), nbd_set_request_block_size(3),
132       nbd_set_strict_mode(3), libnbd(3).
133

AUTHORS

135       Eric Blake
136
137       Richard W.M. Jones
138
140       Copyright Red Hat
141

LICENSE

143       This library is free software; you can redistribute it and/or modify it
144       under the terms of the GNU Lesser General Public License as published
145       by the Free Software Foundation; either version 2 of the License, or
146       (at your option) any later version.
147
148       This library is distributed in the hope that it will be useful, but
149       WITHOUT ANY WARRANTY; without even the implied warranty of
150       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
151       Lesser General Public License for more details.
152
153       You should have received a copy of the GNU Lesser General Public
154       License along with this library; if not, write to the Free Software
155       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
156       02110-1301 USA
157
158
159
160libnbd-1.16.5                     2023-09-26           nbd_pread_structured(3)
Impressum