]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "ImageWriteback.h" | |
5 | #include "include/buffer.h" | |
6 | #include "common/dout.h" | |
7 | #include "librbd/ImageCtx.h" | |
9f95a23c | 8 | #include "librbd/Utils.h" |
7c673cae FG |
9 | #include "librbd/io/AioCompletion.h" |
10 | #include "librbd/io/ImageRequest.h" | |
11 | #include "librbd/io/ReadResult.h" | |
12 | ||
13 | #define dout_subsys ceph_subsys_rbd | |
14 | #undef dout_prefix | |
15 | #define dout_prefix *_dout << "librbd::ImageWriteback: " << __func__ << ": " | |
16 | ||
17 | namespace librbd { | |
18 | namespace cache { | |
19 | ||
20 | template <typename I> | |
21 | ImageWriteback<I>::ImageWriteback(I &image_ctx) : m_image_ctx(image_ctx) { | |
22 | } | |
23 | ||
24 | template <typename I> | |
25 | void ImageWriteback<I>::aio_read(Extents &&image_extents, bufferlist *bl, | |
26 | int fadvise_flags, Context *on_finish) { | |
27 | CephContext *cct = m_image_ctx.cct; | |
28 | ldout(cct, 20) << "image_extents=" << image_extents << ", " | |
29 | << "on_finish=" << on_finish << dendl; | |
30 | ||
9f95a23c TL |
31 | ImageCtx *image_ctx = util::get_image_ctx(&m_image_ctx); |
32 | auto aio_comp = io::AioCompletion::create_and_start( | |
33 | on_finish, image_ctx, io::AIO_TYPE_READ); | |
34 | io::ImageReadRequest<> req(*image_ctx, aio_comp, std::move(image_extents), | |
31f18b77 | 35 | io::ReadResult{bl}, fadvise_flags, {}); |
7c673cae FG |
36 | req.set_bypass_image_cache(); |
37 | req.send(); | |
38 | } | |
39 | ||
40 | template <typename I> | |
41 | void ImageWriteback<I>::aio_write(Extents &&image_extents, | |
42 | ceph::bufferlist&& bl, | |
43 | int fadvise_flags, Context *on_finish) { | |
44 | CephContext *cct = m_image_ctx.cct; | |
45 | ldout(cct, 20) << "image_extents=" << image_extents << ", " | |
46 | << "on_finish=" << on_finish << dendl; | |
47 | ||
9f95a23c TL |
48 | ImageCtx *image_ctx = util::get_image_ctx(&m_image_ctx); |
49 | auto aio_comp = io::AioCompletion::create_and_start( | |
50 | on_finish, image_ctx, io::AIO_TYPE_WRITE); | |
51 | io::ImageWriteRequest<> req(*image_ctx, aio_comp, std::move(image_extents), | |
31f18b77 | 52 | std::move(bl), fadvise_flags, {}); |
7c673cae FG |
53 | req.set_bypass_image_cache(); |
54 | req.send(); | |
55 | } | |
56 | ||
57 | template <typename I> | |
58 | void ImageWriteback<I>::aio_discard(uint64_t offset, uint64_t length, | |
11fdf7f2 TL |
59 | uint32_t discard_granularity_bytes, |
60 | Context *on_finish) { | |
7c673cae FG |
61 | CephContext *cct = m_image_ctx.cct; |
62 | ldout(cct, 20) << "offset=" << offset << ", " | |
63 | << "length=" << length << ", " | |
64 | << "on_finish=" << on_finish << dendl; | |
65 | ||
9f95a23c TL |
66 | ImageCtx *image_ctx = util::get_image_ctx(&m_image_ctx); |
67 | auto aio_comp = io::AioCompletion::create_and_start( | |
68 | on_finish, image_ctx, io::AIO_TYPE_DISCARD); | |
69 | io::ImageDiscardRequest<> req(*image_ctx, aio_comp, {{offset, length}}, | |
11fdf7f2 | 70 | discard_granularity_bytes, {}); |
7c673cae FG |
71 | req.set_bypass_image_cache(); |
72 | req.send(); | |
73 | } | |
74 | ||
75 | template <typename I> | |
76 | void ImageWriteback<I>::aio_flush(Context *on_finish) { | |
77 | CephContext *cct = m_image_ctx.cct; | |
78 | ldout(cct, 20) << "on_finish=" << on_finish << dendl; | |
79 | ||
9f95a23c TL |
80 | ImageCtx *image_ctx = util::get_image_ctx(&m_image_ctx); |
81 | auto aio_comp = io::AioCompletion::create_and_start( | |
82 | on_finish, image_ctx, io::AIO_TYPE_FLUSH); | |
83 | io::ImageFlushRequest<> req(*image_ctx, aio_comp, io::FLUSH_SOURCE_INTERNAL, {}); | |
7c673cae FG |
84 | req.set_bypass_image_cache(); |
85 | req.send(); | |
86 | } | |
87 | ||
88 | template <typename I> | |
89 | void ImageWriteback<I>::aio_writesame(uint64_t offset, uint64_t length, | |
90 | ceph::bufferlist&& bl, | |
91 | int fadvise_flags, Context *on_finish) { | |
92 | CephContext *cct = m_image_ctx.cct; | |
93 | ldout(cct, 20) << "offset=" << offset << ", " | |
94 | << "length=" << length << ", " | |
95 | << "data_len=" << bl.length() << ", " | |
96 | << "on_finish=" << on_finish << dendl; | |
97 | ||
9f95a23c TL |
98 | ImageCtx *image_ctx = util::get_image_ctx(&m_image_ctx); |
99 | auto aio_comp = io::AioCompletion::create_and_start( | |
100 | on_finish, image_ctx, io::AIO_TYPE_WRITESAME); | |
101 | io::ImageWriteSameRequest<> req(*image_ctx, aio_comp, {{offset, length}}, | |
31f18b77 | 102 | std::move(bl), fadvise_flags, {}); |
7c673cae FG |
103 | req.set_bypass_image_cache(); |
104 | req.send(); | |
105 | } | |
106 | ||
c07f9fc5 FG |
107 | template <typename I> |
108 | void ImageWriteback<I>::aio_compare_and_write(Extents &&image_extents, | |
109 | ceph::bufferlist&& cmp_bl, | |
110 | ceph::bufferlist&& bl, | |
111 | uint64_t *mismatch_offset, | |
112 | int fadvise_flags, | |
113 | Context *on_finish) { | |
114 | CephContext *cct = m_image_ctx.cct; | |
115 | ldout(cct, 20) << "image_extents=" << image_extents << ", " | |
116 | << "on_finish=" << on_finish << dendl; | |
117 | ||
9f95a23c TL |
118 | ImageCtx *image_ctx = util::get_image_ctx(&m_image_ctx); |
119 | auto aio_comp = io::AioCompletion::create_and_start( | |
120 | on_finish, image_ctx, io::AIO_TYPE_COMPARE_AND_WRITE); | |
121 | io::ImageCompareAndWriteRequest<> req(*image_ctx, aio_comp, | |
c07f9fc5 FG |
122 | std::move(image_extents), |
123 | std::move(cmp_bl), std::move(bl), | |
124 | mismatch_offset, fadvise_flags, {}); | |
125 | req.set_bypass_image_cache(); | |
126 | req.send(); | |
127 | } | |
128 | ||
7c673cae FG |
129 | } // namespace cache |
130 | } // namespace librbd | |
131 | ||
132 | template class librbd::cache::ImageWriteback<librbd::ImageCtx>; | |
133 |