]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/io/ReadResult.h
import 15.2.0 Octopus source
[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/common_fwd.h"
8 #include "include/int_types.h"
9 #include "include/buffer_fwd.h"
10 #include "include/Context.h"
11 #include "librbd/io/Types.h"
12 #include "osdc/Striper.h"
13 #include <sys/uio.h>
14 #include <boost/variant/variant.hpp>
15
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 public:
28 struct C_ImageReadRequest : public Context {
29 AioCompletion *aio_completion;
30 Extents image_extents;
31 bufferlist bl;
32
33 C_ImageReadRequest(AioCompletion *aio_completion,
34 const Extents image_extents);
35
36 void finish(int r) override;
37 };
38
39 struct C_ObjectReadRequest : public Context {
40 AioCompletion *aio_completion;
41 uint64_t object_off;
42 uint64_t object_len;
43 LightweightBufferExtents buffer_extents;
44
45 bufferlist bl;
46 ExtentMap extent_map;
47
48 C_ObjectReadRequest(AioCompletion *aio_completion, uint64_t object_off,
49 uint64_t object_len,
50 LightweightBufferExtents&& buffer_extents);
51
52 void finish(int r) override;
53 };
54
55 ReadResult();
56 ReadResult(char *buf, size_t buf_len);
57 ReadResult(const struct iovec *iov, int iov_count);
58 ReadResult(ceph::bufferlist *bl);
59 ReadResult(std::map<uint64_t, uint64_t> *extent_map, ceph::bufferlist *bl);
60
61 void set_clip_length(size_t length);
62 void assemble_result(CephContext *cct);
63
64 private:
65 struct Empty {
66 };
67
68 struct Linear {
69 char *buf;
70 size_t buf_len;
71
72 Linear(char *buf, size_t buf_len) : buf(buf), buf_len(buf_len) {
73 }
74 };
75
76 struct Vector {
77 const struct iovec *iov;
78 int iov_count;
79
80 Vector(const struct iovec *iov, int iov_count)
81 : iov(iov), iov_count(iov_count) {
82 }
83 };
84
85 struct Bufferlist {
86 ceph::bufferlist *bl;
87
88 Bufferlist(ceph::bufferlist *bl) : bl(bl) {
89 }
90 };
91
92 struct SparseBufferlist {
93 std::map<uint64_t, uint64_t> *extent_map;
94 ceph::bufferlist *bl;
95
96 SparseBufferlist(std::map<uint64_t, uint64_t> *extent_map,
97 ceph::bufferlist *bl)
98 : extent_map(extent_map), bl(bl) {
99 }
100 };
101
102 typedef boost::variant<Empty,
103 Linear,
104 Vector,
105 Bufferlist,
106 SparseBufferlist> Buffer;
107 struct SetClipLengthVisitor;
108 struct AssembleResultVisitor;
109
110 Buffer m_buffer;
111 Striper::StripedReadResult m_destriper;
112
113 };
114
115 } // namespace io
116 } // namespace librbd
117
118 #endif // CEPH_LIBRBD_IO_READ_RESULT_H
119