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