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 (struct nbd_handle *h, void *buf,
20                                  size_t count, uint64_t offset,
21                                  nbd_chunk_callback chunk_callback,
22                                  uint32_t flags);
23

DESCRIPTION

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

RETURN VALUE

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

ERRORS

107       On error "-1" is returned.
108
109       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
110       of the error.
111

HANDLE STATE

113       The handle must be connected with the server, otherwise this call will
114       return an error.
115

VERSION

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

SEE ALSO

125       nbd_aio_pread_structured(3), nbd_can_df(3), nbd_create(3),
126       nbd_get_block_size(3), nbd_get_pread_initialize(3), nbd_pread(3),
127       nbd_set_pread_initialize(3), nbd_set_request_block_size(3),
128       nbd_set_strict_mode(3), libnbd(3).
129

AUTHORS

131       Eric Blake
132
133       Richard W.M. Jones
134
136       Copyright (C) 2019-2021 Red Hat Inc.
137

LICENSE

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