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       The "flags" parameter may be 0 for no flags, or may contain
79       "LIBNBD_CMD_FLAG_DF" meaning that the server should not reply with more
80       than one fragment (if that is supported - some servers cannot do this,
81       see nbd_can_df(3)). Libnbd does not validate that the server actually
82       obeys the flag.
83

RETURN VALUE

85       If the call is successful the function returns 0.
86

ERRORS

88       On error "-1" is returned.
89
90       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
91       of the error.
92

HANDLE STATE

94       The handle must be connected and finished handshaking with the server,
95       otherwise this call will return an error.
96

VERSION

98       This function first appeared in libnbd 1.0.
99
100       If you need to test if this function is available at compile time check
101       if the following macro is defined:
102
103        #define LIBNBD_HAVE_NBD_PREAD_STRUCTURED 1
104

SEE ALSO

106       nbd_aio_pread_structured(3), nbd_can_df(3), nbd_create(3),
107       nbd_pread(3), libnbd(3).
108

AUTHORS

110       Eric Blake
111
112       Richard W.M. Jones
113
115       Copyright (C) 2019 Red Hat Inc.
116

LICENSE

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