summaryrefslogtreecommitdiffstats
path: root/src/librbd/cache/PassthroughImageCache.h
blob: 4be69a50aed5db11886ff8f8bb87c7e8483cf4fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_LIBRBD_CACHE_PASSTHROUGH_IMAGE_CACHE
#define CEPH_LIBRBD_CACHE_PASSTHROUGH_IMAGE_CACHE

#include "ImageCache.h"
#include "ImageWriteback.h"

namespace librbd {

struct ImageCtx;

namespace cache {

/**
 * Example passthrough client-side, image extent cache
 */
template <typename ImageCtxT = librbd::ImageCtx>
class PassthroughImageCache : public ImageCache {
public:
  explicit PassthroughImageCache(ImageCtx &image_ctx);

  /// client AIO methods
  void aio_read(Extents&& image_extents, ceph::bufferlist *bl,
                int fadvise_flags, Context *on_finish) override;
  void aio_write(Extents&& image_extents, ceph::bufferlist&& bl,
                 int fadvise_flags, Context *on_finish) override;
  void aio_discard(uint64_t offset, uint64_t length,
                   uint32_t discard_granularity_bytes,
                   Context *on_finish) override;
  void aio_flush(Context *on_finish) override;
  void aio_writesame(uint64_t offset, uint64_t length,
                     ceph::bufferlist&& bl,
                     int fadvise_flags, Context *on_finish) override;
  void aio_compare_and_write(Extents&& image_extents,
                             ceph::bufferlist&& cmp_bl, ceph::bufferlist&& bl,
                             uint64_t *mismatch_offset,int fadvise_flags,
                             Context *on_finish) override;

  /// internal state methods
  void init(Context *on_finish) override;
  void shut_down(Context *on_finish) override;

  void invalidate(Context *on_finish) override;
  void flush(Context *on_finish) override;

private:
  ImageCtxT &m_image_ctx;
  ImageWriteback<ImageCtxT> m_image_writeback;

};

} // namespace cache
} // namespace librbd

extern template class librbd::cache::PassthroughImageCache<librbd::ImageCtx>;

#endif // CEPH_LIBRBD_CACHE_PASSTHROUGH_IMAGE_CACHE