]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/io/ReadResult.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / librbd / io / ReadResult.h
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 namespace io {
19
20 struct AioCompletion;
21 template <typename> struct ObjectReadRequest;
22
23 class ReadResult {
24 private:
25 struct C_ReadRequest : public Context {
26 AioCompletion *aio_completion;
27 bufferlist bl;
28
29 C_ReadRequest(AioCompletion *aio_completion);
30
31 void finish(int r) override;
32 };
33
34 public:
35
36 struct C_ImageReadRequest : public C_ReadRequest {
37 Extents image_extents;
38
39 C_ImageReadRequest(AioCompletion *aio_completion,
40 const Extents image_extents)
41 : C_ReadRequest(aio_completion), image_extents(image_extents) {
42 }
43
44 void finish(int r) override;
45 };
46
47 struct C_SparseReadRequestBase : public C_ReadRequest {
48 C_SparseReadRequestBase(AioCompletion *aio_completion)
49 : C_ReadRequest(aio_completion) {
50 }
51
52 using C_ReadRequest::finish;
53 void finish(ExtentMap &extent_map, const Extents &buffer_extents,
54 uint64_t offset, size_t length, bufferlist &bl, int r);
55 };
56
57 template <typename ImageCtxT>
58 struct C_SparseReadRequest : public C_SparseReadRequestBase {
59 ObjectReadRequest<ImageCtxT> *request;
60
61 C_SparseReadRequest(AioCompletion *aio_completion)
62 : C_SparseReadRequestBase(aio_completion) {
63 }
64
65 void finish(int r) override {
66 C_SparseReadRequestBase::finish(request->get_extent_map(),
67 request->get_buffer_extents(),
68 request->get_offset(),
69 request->get_length(), request->data(),
70 r);
71 }
72 };
73
74 ReadResult();
75 ReadResult(char *buf, size_t buf_len);
76 ReadResult(const struct iovec *iov, int iov_count);
77 ReadResult(ceph::bufferlist *bl);
78
79 void set_clip_length(size_t length);
80 void assemble_result(CephContext *cct);
81
82 private:
83 struct Empty {
84 };
85
86 struct Linear {
87 char *buf;
88 size_t buf_len;
89
90 Linear(char *buf, size_t buf_len) : buf(buf), buf_len(buf_len) {
91 }
92 };
93
94 struct Vector {
95 const struct iovec *iov;
96 int iov_count;
97
98 Vector(const struct iovec *iov, int iov_count)
99 : iov(iov), iov_count(iov_count) {
100 }
101 };
102
103 struct Bufferlist {
104 ceph::bufferlist *bl;
105
106 Bufferlist(ceph::bufferlist *bl) : bl(bl) {
107 }
108 };
109
110 typedef boost::variant<Empty,
111 Linear,
112 Vector,
113 Bufferlist> Buffer;
114 struct SetClipLengthVisitor;
115 struct AssembleResultVisitor;
116
117 Buffer m_buffer;
118 Striper::StripedReadResult m_destriper;
119
120 };
121
122 } // namespace io
123 } // namespace librbd
124
125 #endif // CEPH_LIBRBD_IO_READ_RESULT_H
126