Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / cache / PassthroughImageCache.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "PassthroughImageCache.h"
5 #include "include/buffer.h"
6 #include "common/dout.h"
7 #include "librbd/ImageCtx.h"
8
9 #define dout_subsys ceph_subsys_rbd
10 #undef dout_prefix
11 #define dout_prefix *_dout << "librbd::PassthroughImageCache: " << this << " " \
12                            <<  __func__ << ": "
13
14 namespace librbd {
15 namespace cache {
16
17 template <typename I>
18 PassthroughImageCache<I>::PassthroughImageCache(ImageCtx &image_ctx)
19   : m_image_ctx(image_ctx), m_image_writeback(image_ctx) {
20 }
21
22 template <typename I>
23 void PassthroughImageCache<I>::aio_read(Extents &&image_extents, bufferlist *bl,
24                                         int fadvise_flags, Context *on_finish) {
25   CephContext *cct = m_image_ctx.cct;
26   ldout(cct, 20) << "image_extents=" << image_extents << ", "
27                  << "on_finish=" << on_finish << dendl;
28
29   m_image_writeback.aio_read(std::move(image_extents), bl, fadvise_flags,
30                              on_finish);
31 }
32
33 template <typename I>
34 void PassthroughImageCache<I>::aio_write(Extents &&image_extents,
35                                          bufferlist&& bl,
36                                          int fadvise_flags,
37                                          Context *on_finish) {
38   CephContext *cct = m_image_ctx.cct;
39   ldout(cct, 20) << "image_extents=" << image_extents << ", "
40                  << "on_finish=" << on_finish << dendl;
41
42   m_image_writeback.aio_write(std::move(image_extents), std::move(bl),
43                               fadvise_flags, on_finish);
44 }
45
46 template <typename I>
47 void PassthroughImageCache<I>::aio_discard(uint64_t offset, uint64_t length,
48                                            bool skip_partial_discard, Context *on_finish) {
49   CephContext *cct = m_image_ctx.cct;
50   ldout(cct, 20) << "offset=" << offset << ", "
51                  << "length=" << length << ", "
52                  << "on_finish=" << on_finish << dendl;
53
54   m_image_writeback.aio_discard(offset, length, skip_partial_discard, on_finish);
55 }
56
57 template <typename I>
58 void PassthroughImageCache<I>::aio_flush(Context *on_finish) {
59   CephContext *cct = m_image_ctx.cct;
60   ldout(cct, 20) << "on_finish=" << on_finish << dendl;
61
62   m_image_writeback.aio_flush(on_finish);
63 }
64
65 template <typename I>
66 void PassthroughImageCache<I>::aio_writesame(uint64_t offset, uint64_t length,
67                                              bufferlist&& bl, int fadvise_flags,
68                                              Context *on_finish) {
69   CephContext *cct = m_image_ctx.cct;
70   ldout(cct, 20) << "offset=" << offset << ", "
71                  << "length=" << length << ", "
72                  << "data_len=" << bl.length() << ", "
73                  << "on_finish=" << on_finish << dendl;
74
75   m_image_writeback.aio_writesame(offset, length, std::move(bl), fadvise_flags,
76                                   on_finish);
77 }
78
79 template <typename I>
80 void PassthroughImageCache<I>::aio_compare_and_write(Extents &&image_extents,
81                                                      bufferlist&& cmp_bl,
82                                                      bufferlist&& bl,
83                                                      uint64_t *mismatch_offset,
84                                                      int fadvise_flags,
85                                                      Context *on_finish) {
86   CephContext *cct = m_image_ctx.cct;
87   ldout(cct, 20) << "image_extents=" << image_extents << ", "
88                  << "on_finish=" << on_finish << dendl;
89
90   m_image_writeback.aio_compare_and_write(
91     std::move(image_extents), std::move(cmp_bl), std::move(bl), mismatch_offset,
92     fadvise_flags, on_finish);
93 }
94
95 template <typename I>
96 void PassthroughImageCache<I>::init(Context *on_finish) {
97   CephContext *cct = m_image_ctx.cct;
98   ldout(cct, 20) << dendl;
99
100   on_finish->complete(0);
101 }
102
103 template <typename I>
104 void PassthroughImageCache<I>::shut_down(Context *on_finish) {
105   CephContext *cct = m_image_ctx.cct;
106   ldout(cct, 20) << dendl;
107
108   on_finish->complete(0);
109 }
110
111 template <typename I>
112 void PassthroughImageCache<I>::invalidate(Context *on_finish) {
113   CephContext *cct = m_image_ctx.cct;
114   ldout(cct, 20) << dendl;
115
116   // dump cache contents (don't have anything)
117   on_finish->complete(0);
118 }
119
120 template <typename I>
121 void PassthroughImageCache<I>::flush(Context *on_finish) {
122   CephContext *cct = m_image_ctx.cct;
123   ldout(cct, 20) << dendl;
124
125   // internal flush -- nothing to writeback but make sure
126   // in-flight IO is flushed
127   aio_flush(on_finish);
128 }
129
130 } // namespace cache
131 } // namespace librbd
132
133 template class librbd::cache::PassthroughImageCache<librbd::ImageCtx>;