]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/pwl/rwl/Builder.h
c13c7b5ae9310a90b26376ca9b0aa67d643c3d6b
[ceph.git] / ceph / src / librbd / cache / pwl / rwl / Builder.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_LIBRBD_CACHE_PWL_RWL_BUILDER_H
5 #define CEPH_LIBRBD_CACHE_PWL_RWL_BUILDER_H
6
7 #include <iostream>
8 #include "LogEntry.h"
9 #include "ReadRequest.h"
10 #include "Request.h"
11 #include "LogOperation.h"
12
13 #include "librbd/cache/ImageWriteback.h"
14 #include "librbd/cache/pwl/Builder.h"
15
16 namespace librbd {
17 namespace cache {
18 namespace pwl {
19 namespace rwl {
20
21 template <typename T>
22 class Builder : public pwl::Builder<T> {
23 public:
24 std::shared_ptr<pwl::WriteLogEntry> create_write_log_entry(
25 uint64_t image_offset_bytes, uint64_t write_bytes) override {
26 return std::make_shared<WriteLogEntry>(image_offset_bytes, write_bytes);
27 }
28 std::shared_ptr<pwl::WriteLogEntry> create_write_log_entry(
29 std::shared_ptr<SyncPointLogEntry> sync_point_entry,
30 uint64_t image_offset_bytes, uint64_t write_bytes) override {
31 return std::make_shared<WriteLogEntry>(
32 sync_point_entry, image_offset_bytes, write_bytes);
33 }
34 std::shared_ptr<pwl::WriteLogEntry> create_writesame_log_entry(
35 uint64_t image_offset_bytes, uint64_t write_bytes,
36 uint32_t data_length) override {
37 return std::make_shared<WriteSameLogEntry>(
38 image_offset_bytes, write_bytes, data_length);
39 }
40 std::shared_ptr<pwl::WriteLogEntry> create_writesame_log_entry(
41 std::shared_ptr<SyncPointLogEntry> sync_point_entry,
42 uint64_t image_offset_bytes, uint64_t write_bytes,
43 uint32_t data_length) override {
44 return std::make_shared<WriteSameLogEntry>(
45 sync_point_entry, image_offset_bytes, write_bytes, data_length);
46 }
47 pwl::C_WriteRequest<T> *create_write_request(
48 T &pwl, utime_t arrived, io::Extents &&image_extents,
49 bufferlist&& bl, const int fadvise_flags, ceph::mutex &lock,
50 PerfCounters *perfcounter, Context *user_req) override {
51 return new C_WriteRequest<T>(
52 pwl, arrived, std::move(image_extents), std::move(bl),
53 fadvise_flags, lock, perfcounter, user_req);
54 }
55 pwl::C_WriteSameRequest<T> *create_writesame_request(
56 T &pwl, utime_t arrived, io::Extents &&image_extents,
57 bufferlist&& bl, const int fadvise_flags, ceph::mutex &lock,
58 PerfCounters *perfcounter, Context *user_req) override {
59 return new C_WriteSameRequest<T>(
60 pwl, arrived, std::move(image_extents), std::move(bl),
61 fadvise_flags, lock, perfcounter, user_req);
62 }
63 pwl::C_WriteRequest<T> *create_comp_and_write_request(
64 T &pwl, utime_t arrived, io::Extents &&image_extents,
65 bufferlist&& cmp_bl, bufferlist&& bl, uint64_t *mismatch_offset,
66 const int fadvise_flags, ceph::mutex &lock,
67 PerfCounters *perfcounter, Context *user_req) override {
68 return new rwl::C_CompAndWriteRequest<T>(
69 pwl, arrived, std::move(image_extents), std::move(cmp_bl),
70 std::move(bl), mismatch_offset, fadvise_flags,
71 lock, perfcounter, user_req);
72 }
73 std::shared_ptr<pwl::WriteLogOperation> create_write_log_operation(
74 WriteLogOperationSet &set, uint64_t image_offset_bytes,
75 uint64_t write_bytes, CephContext *cct,
76 std::shared_ptr<pwl::WriteLogEntry> write_log_entry) {
77 return std::make_shared<WriteLogOperation>(
78 set, image_offset_bytes, write_bytes, cct, write_log_entry);
79 }
80 std::shared_ptr<pwl::WriteLogOperation> create_write_log_operation(
81 WriteLogOperationSet &set, uint64_t image_offset_bytes,
82 uint64_t write_bytes, uint32_t data_len, CephContext *cct,
83 std::shared_ptr<pwl::WriteLogEntry> writesame_log_entry) {
84 return std::make_shared<WriteLogOperation>(
85 set, image_offset_bytes, write_bytes, data_len, cct,
86 writesame_log_entry);
87 }
88 std::shared_ptr<pwl::DiscardLogOperation> create_discard_log_operation(
89 std::shared_ptr<SyncPoint> sync_point, uint64_t image_offset_bytes,
90 uint64_t write_bytes, uint32_t discard_granularity_bytes,
91 utime_t dispatch_time, PerfCounters *perfcounter, CephContext *cct) {
92 return std::make_shared<DiscardLogOperation>(
93 sync_point, image_offset_bytes, write_bytes, discard_granularity_bytes,
94 dispatch_time, perfcounter, cct);
95 }
96 C_ReadRequest *create_read_request(CephContext *cct, utime_t arrived,
97 PerfCounters *perfcounter, ceph::bufferlist *bl, Context *on_finish) {
98 return new C_ReadRequest(cct, arrived, perfcounter, bl, on_finish);
99 }
100 };
101
102 } // namespace rwl
103 } // namespace pwl
104 } // namespace cache
105 } // namespace librbd
106
107 #endif // CEPH_LIBRBD_CACHE_PWL_RWL_BUILDER_H