]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/osdc/FakeWriteback.cc
update sources to v12.1.0
[ceph.git] / ceph / src / test / osdc / FakeWriteback.cc
CommitLineData
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 <errno.h>
5#include <time.h>
6
7#include <thread>
8#include "common/debug.h"
9#include "common/Cond.h"
10#include "common/Finisher.h"
11#include "common/Mutex.h"
12#include "include/assert.h"
13#include "common/ceph_time.h"
14
15#include "FakeWriteback.h"
16
17#define dout_subsys ceph_subsys_objectcacher
18#undef dout_prefix
19#define dout_prefix *_dout << "FakeWriteback(" << this << ") "
20
21class C_Delay : public Context {
22 CephContext *m_cct;
23 Context *m_con;
24 ceph::timespan m_delay;
25 Mutex *m_lock;
26 bufferlist *m_bl;
27 uint64_t m_off;
28
29public:
30 C_Delay(CephContext *cct, Context *c, Mutex *lock, uint64_t off,
31 bufferlist *pbl, uint64_t delay_ns=0)
32 : m_cct(cct), m_con(c), m_delay(delay_ns * std::chrono::nanoseconds(1)),
33 m_lock(lock), m_bl(pbl), m_off(off) {}
34 void finish(int r) override {
35 std::this_thread::sleep_for(m_delay);
36 if (m_bl) {
37 buffer::ptr bp(r);
38 bp.zero();
39 m_bl->append(bp);
40 ldout(m_cct, 20) << "finished read " << m_off << "~" << r << dendl;
41 }
42 m_lock->Lock();
43 m_con->complete(r);
44 m_lock->Unlock();
45 }
46};
47
48FakeWriteback::FakeWriteback(CephContext *cct, Mutex *lock, uint64_t delay_ns)
49 : m_cct(cct), m_lock(lock), m_delay_ns(delay_ns)
50{
51 m_finisher = new Finisher(cct);
52 m_finisher->start();
53}
54
55FakeWriteback::~FakeWriteback()
56{
57 m_finisher->stop();
58 delete m_finisher;
59}
60
61void FakeWriteback::read(const object_t& oid, uint64_t object_no,
62 const object_locator_t& oloc,
63 uint64_t off, uint64_t len, snapid_t snapid,
64 bufferlist *pbl, uint64_t trunc_size,
31f18b77
FG
65 __u32 trunc_seq, int op_flags,
66 const ZTracer::Trace &parent_trace,
67 Context *onfinish)
7c673cae
FG
68{
69 C_Delay *wrapper = new C_Delay(m_cct, onfinish, m_lock, off, pbl,
70 m_delay_ns);
71 m_finisher->queue(wrapper, len);
72}
73
74ceph_tid_t FakeWriteback::write(const object_t& oid,
75 const object_locator_t& oloc,
76 uint64_t off, uint64_t len,
77 const SnapContext& snapc,
78 const bufferlist &bl, ceph::real_time mtime,
79 uint64_t trunc_size, __u32 trunc_seq,
31f18b77
FG
80 ceph_tid_t journal_tid,
81 const ZTracer::Trace &parent_trace,
82 Context *oncommit)
7c673cae
FG
83{
84 C_Delay *wrapper = new C_Delay(m_cct, oncommit, m_lock, off, NULL,
85 m_delay_ns);
86 m_finisher->queue(wrapper, 0);
31f18b77 87 return ++m_tid;
7c673cae
FG
88}
89
90bool FakeWriteback::may_copy_on_write(const object_t&, uint64_t, uint64_t,
91 snapid_t)
92{
93 return false;
94}