summaryrefslogtreecommitdiffstats
path: root/src/librbd/cache/ObjectCacherWriteback.h
blob: d8c2ebbd991d007607fc7f88d471dc86e003a342 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_LIBRBD_CACHE_OBJECT_CACHER_WRITEBACK_H
#define CEPH_LIBRBD_CACHE_OBJECT_CACHER_WRITEBACK_H

#include "common/snap_types.h"
#include "osd/osd_types.h"
#include "osdc/WritebackHandler.h"
#include <queue>

class Context;

namespace librbd {

struct ImageCtx;

namespace cache {

class ObjectCacherWriteback : public WritebackHandler {
public:
  static const int READ_FLAGS_MASK  = 0xF000;
  static const int READ_FLAGS_SHIFT = 24;

  ObjectCacherWriteback(ImageCtx *ictx, ceph::mutex& lock);

  // Note that oloc, trunc_size, and trunc_seq are ignored
  void read(const object_t& oid, uint64_t object_no,
            const object_locator_t& oloc, uint64_t off, uint64_t len,
            snapid_t snapid, bufferlist *pbl, uint64_t trunc_size,
            __u32 trunc_seq, int op_flags,
            const ZTracer::Trace &parent_trace, Context *onfinish) override;

  // Determine whether a read to this extent could be affected by a
  // write-triggered copy-on-write
  bool may_copy_on_write(const object_t& oid, uint64_t read_off,
                         uint64_t read_len, snapid_t snapid) override;

  // Note that oloc, trunc_size, and trunc_seq are ignored
  ceph_tid_t write(const object_t& oid, const object_locator_t& oloc,
                   uint64_t off, uint64_t len,
                   const SnapContext& snapc, const bufferlist &bl,
                   ceph::real_time mtime, uint64_t trunc_size,
                   __u32 trunc_seq, ceph_tid_t journal_tid,
                   const ZTracer::Trace &parent_trace,
                   Context *oncommit) override;
  using WritebackHandler::write;

  void overwrite_extent(const object_t& oid, uint64_t off,
                        uint64_t len, ceph_tid_t original_journal_tid,
                        ceph_tid_t new_journal_tid) override;

  struct write_result_d {
    bool done;
    int ret;
    std::string oid;
    Context *oncommit;
    write_result_d(const std::string& oid, Context *oncommit) :
      done(false), ret(0), oid(oid), oncommit(oncommit) {}
  private:
    write_result_d(const write_result_d& rhs);
    const write_result_d& operator=(const write_result_d& rhs);
  };

private:
  void complete_writes(const std::string& oid);

  ceph_tid_t m_tid;
  ceph::mutex& m_lock;
  librbd::ImageCtx *m_ictx;
  ceph::unordered_map<std::string, std::queue<write_result_d*> > m_writes;
  friend class C_OrderedWrite;
};

} // namespace cache
} // namespace librbd

#endif // CEPH_LIBRBD_CACHE_OBJECT_CACHER_WRITEBACK_H