]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_LIBRBD_IO_READ_RESULT_H | |
5 | #define CEPH_LIBRBD_IO_READ_RESULT_H | |
6 | ||
7 | #include "include/int_types.h" | |
8 | #include "include/buffer_fwd.h" | |
9 | #include "include/Context.h" | |
10 | #include "librbd/io/Types.h" | |
11 | #include "osdc/Striper.h" | |
12 | #include <sys/uio.h> | |
13 | #include <boost/variant/variant.hpp> | |
14 | ||
15 | struct CephContext; | |
16 | ||
17 | namespace librbd { | |
18 | ||
19 | struct ImageCtx; | |
20 | ||
21 | namespace io { | |
22 | ||
23 | struct AioCompletion; | |
24 | template <typename> struct ObjectReadRequest; | |
25 | ||
26 | class ReadResult { | |
27 | private: | |
28 | struct C_ReadRequest : public Context { | |
29 | AioCompletion *aio_completion; | |
30 | bufferlist bl; | |
31 | ||
32 | C_ReadRequest(AioCompletion *aio_completion); | |
33 | ||
34 | void finish(int r) override; | |
35 | }; | |
36 | ||
37 | public: | |
38 | ||
39 | struct C_ImageReadRequest : public C_ReadRequest { | |
40 | Extents image_extents; | |
41 | ||
42 | C_ImageReadRequest(AioCompletion *aio_completion, | |
43 | const Extents image_extents) | |
44 | : C_ReadRequest(aio_completion), image_extents(image_extents) { | |
45 | } | |
46 | ||
47 | void finish(int r) override; | |
48 | }; | |
49 | ||
50 | struct C_SparseReadRequestBase : public C_ReadRequest { | |
51 | bool ignore_enoent; | |
52 | ||
53 | C_SparseReadRequestBase(AioCompletion *aio_completion, bool ignore_enoent) | |
54 | : C_ReadRequest(aio_completion), ignore_enoent(ignore_enoent) { | |
55 | } | |
56 | ||
57 | using C_ReadRequest::finish; | |
58 | void finish(ExtentMap &extent_map, const Extents &buffer_extents, | |
59 | uint64_t offset, size_t length, bufferlist &bl, int r); | |
60 | }; | |
61 | ||
62 | template <typename ImageCtxT = ImageCtx> | |
63 | struct C_SparseReadRequest : public C_SparseReadRequestBase { | |
64 | ObjectReadRequest<ImageCtxT> *request; | |
65 | Extents buffer_extents; | |
66 | ||
67 | C_SparseReadRequest(AioCompletion *aio_completion, Extents&& buffer_extents, | |
68 | bool ignore_enoent) | |
69 | : C_SparseReadRequestBase(aio_completion, ignore_enoent), | |
70 | buffer_extents(std::move(buffer_extents)) { | |
71 | } | |
72 | ||
73 | void finish(int r) override { | |
74 | C_SparseReadRequestBase::finish(request->get_extent_map(), buffer_extents, | |
75 | request->get_offset(), | |
76 | request->get_length(), request->data(), | |
77 | r); | |
78 | } | |
79 | }; | |
80 | ||
81 | ReadResult(); | |
82 | ReadResult(char *buf, size_t buf_len); | |
83 | ReadResult(const struct iovec *iov, int iov_count); | |
84 | ReadResult(ceph::bufferlist *bl); | |
85 | ||
86 | void set_clip_length(size_t length); | |
87 | void assemble_result(CephContext *cct); | |
88 | ||
89 | private: | |
90 | struct Empty { | |
91 | }; | |
92 | ||
93 | struct Linear { | |
94 | char *buf; | |
95 | size_t buf_len; | |
96 | ||
97 | Linear(char *buf, size_t buf_len) : buf(buf), buf_len(buf_len) { | |
98 | } | |
99 | }; | |
100 | ||
101 | struct Vector { | |
102 | const struct iovec *iov; | |
103 | int iov_count; | |
104 | ||
105 | Vector(const struct iovec *iov, int iov_count) | |
106 | : iov(iov), iov_count(iov_count) { | |
107 | } | |
108 | }; | |
109 | ||
110 | struct Bufferlist { | |
111 | ceph::bufferlist *bl; | |
112 | ||
113 | Bufferlist(ceph::bufferlist *bl) : bl(bl) { | |
114 | } | |
115 | }; | |
116 | ||
117 | typedef boost::variant<Empty, | |
118 | Linear, | |
119 | Vector, | |
120 | Bufferlist> Buffer; | |
121 | struct SetClipLengthVisitor; | |
122 | struct AssembleResultVisitor; | |
123 | ||
124 | Buffer m_buffer; | |
125 | Striper::StripedReadResult m_destriper; | |
126 | ||
127 | }; | |
128 | ||
129 | } // namespace io | |
130 | } // namespace librbd | |
131 | ||
132 | #endif // CEPH_LIBRBD_IO_READ_RESULT_H | |
133 |