]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/cache/pwl/ssd/WriteLog.h
import ceph 16.2.7
[ceph.git] / ceph / src / librbd / cache / pwl / ssd / WriteLog.h
CommitLineData
f67539c2
TL
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_SSD_WRITE_LOG
5#define CEPH_LIBRBD_CACHE_PWL_SSD_WRITE_LOG
6
7#include "blk/BlockDevice.h"
8#include "common/AsyncOpTracker.h"
9#include "common/Checksummer.h"
10#include "common/environment.h"
11#include "common/RWLock.h"
12#include "common/WorkQueue.h"
13#include "librbd/BlockGuard.h"
14#include "librbd/Utils.h"
15#include "librbd/cache/ImageWriteback.h"
16#include "librbd/cache/Types.h"
17#include "librbd/cache/pwl/AbstractWriteLog.h"
18#include "librbd/cache/pwl/LogMap.h"
19#include "librbd/cache/pwl/LogOperation.h"
20#include "librbd/cache/pwl/Request.h"
21#include "librbd/cache/pwl/ssd/Builder.h"
22#include "librbd/cache/pwl/ssd/Types.h"
23#include <functional>
24#include <list>
25
26namespace librbd {
27
28struct ImageCtx;
29
30namespace cache {
31namespace pwl {
32namespace ssd {
33
34template <typename ImageCtxT>
35class WriteLog : public AbstractWriteLog<ImageCtxT> {
36public:
37 WriteLog(ImageCtxT &image_ctx,
38 librbd::cache::pwl::ImageCacheState<ImageCtxT>* cache_state,
39 cache::ImageWritebackInterface& image_writeback,
40 plugin::Api<ImageCtxT>& plugin_api);
41 ~WriteLog();
42 WriteLog(const WriteLog&) = delete;
43 WriteLog &operator=(const WriteLog&) = delete;
44
45 typedef io::Extent Extent;
46 using This = AbstractWriteLog<ImageCtxT>;
47 using C_BlockIORequestT = pwl::C_BlockIORequest<This>;
48 using C_WriteRequestT = pwl::C_WriteRequest<This>;
49 using C_WriteSameRequestT = pwl::C_WriteSameRequest<This>;
50
51 bool alloc_resources(C_BlockIORequestT *req) override;
52 void setup_schedule_append(
53 pwl::GenericLogOperationsVector &ops, bool do_early_flush,
54 C_BlockIORequestT *req) override;
55 void complete_user_request(Context *&user_req, int r) override;
56
57protected:
58 using AbstractWriteLog<ImageCtxT>::m_lock;
59 using AbstractWriteLog<ImageCtxT>::m_log_entries;
60 using AbstractWriteLog<ImageCtxT>::m_image_ctx;
61 using AbstractWriteLog<ImageCtxT>::m_cache_state;
62 using AbstractWriteLog<ImageCtxT>::m_first_free_entry;
63 using AbstractWriteLog<ImageCtxT>::m_first_valid_entry;
64 using AbstractWriteLog<ImageCtxT>::m_bytes_allocated;
65
a4b75251 66 bool initialize_pool(Context *on_finish,
f67539c2
TL
67 pwl::DeferredContexts &later) override;
68 void process_work() override;
69 void append_scheduled_ops(void) override;
a4b75251 70 void schedule_append_ops(pwl::GenericLogOperations &ops, C_BlockIORequestT *req) override;
f67539c2
TL
71 void remove_pool_file() override;
72 void release_ram(std::shared_ptr<GenericLogEntry> log_entry) override;
73
74private:
75 class AioTransContext {
76 public:
77 Context *on_finish;
78 ::IOContext ioc;
79 explicit AioTransContext(CephContext* cct, Context *cb)
80 : on_finish(cb), ioc(cct, this) {}
81
82 ~AioTransContext(){}
83
84 void aio_finish() {
85 on_finish->complete(ioc.get_return_value());
86 delete this;
87 }
88 }; //class AioTransContext
89
90 struct WriteLogPoolRootUpdate {
91 std::shared_ptr<pwl::WriteLogPoolRoot> root;
92 Context *ctx;
93 WriteLogPoolRootUpdate(std::shared_ptr<pwl::WriteLogPoolRoot> r,
94 Context* c)
95 : root(r), ctx(c) {}
96 };
97
98 using WriteLogPoolRootUpdateList = std::list<std::shared_ptr<WriteLogPoolRootUpdate>>;
99 WriteLogPoolRootUpdateList m_poolroot_to_update; /* pool root list to update to SSD */
100 bool m_updating_pool_root = false;
101
f67539c2
TL
102 std::atomic<int> m_async_update_superblock = {0};
103 BlockDevice *bdev = nullptr;
f67539c2
TL
104 pwl::WriteLogPoolRoot pool_root;
105 Builder<This> *m_builderobj;
106
107 Builder<This>* create_builder();
a4b75251 108 int create_and_open_bdev();
f67539c2 109 void load_existing_entries(pwl::DeferredContexts &later);
a4b75251
TL
110 void inc_allocated_cached_bytes(
111 std::shared_ptr<pwl::GenericLogEntry> log_entry) override;
f67539c2
TL
112 void collect_read_extents(
113 uint64_t read_buffer_offset, LogMapEntry<GenericWriteLogEntry> map_entry,
a4b75251 114 std::vector<std::shared_ptr<GenericWriteLogEntry>> &log_entries_to_read,
f67539c2
TL
115 std::vector<bufferlist*> &bls_to_read, uint64_t entry_hit_length,
116 Extent hit_extent, pwl::C_ReadRequest *read_ctx) override;
117 void complete_read(
a4b75251 118 std::vector<std::shared_ptr<GenericWriteLogEntry>> &log_entries_to_read,
f67539c2
TL
119 std::vector<bufferlist*> &bls_to_read, Context *ctx) override;
120 void enlist_op_appender();
121 bool retire_entries(const unsigned long int frees_per_tx);
122 bool has_sync_point_logs(GenericLogOperations &ops);
123 void append_op_log_entries(GenericLogOperations &ops);
124 void alloc_op_log_entries(GenericLogOperations &ops);
a4b75251
TL
125 void construct_flush_entries(pwl::GenericLogEntries entires_to_flush,
126 DeferredContexts &post_unlock,
127 bool has_write_entry) override;
f67539c2 128 void append_ops(GenericLogOperations &ops, Context *ctx,
a4b75251 129 uint64_t* new_first_free_entry);
f67539c2 130 void write_log_entries(GenericLogEntriesVector log_entries,
a4b75251 131 AioTransContext *aio, uint64_t *pos);
f67539c2
TL
132 void schedule_update_root(std::shared_ptr<WriteLogPoolRoot> root,
133 Context *ctx);
134 void enlist_op_update_root();
135 void update_root_scheduled_ops();
136 int update_pool_root_sync(std::shared_ptr<pwl::WriteLogPoolRoot> root);
137 void update_pool_root(std::shared_ptr<WriteLogPoolRoot> root,
138 AioTransContext *aio);
a4b75251
TL
139 void aio_read_data_block(std::shared_ptr<GenericWriteLogEntry> log_entry,
140 bufferlist *bl, Context *ctx);
141 void aio_read_data_blocks(std::vector<std::shared_ptr<GenericWriteLogEntry>> &log_entries,
142 std::vector<bufferlist *> &bls, Context *ctx);
f67539c2
TL
143 static void aio_cache_cb(void *priv, void *priv2) {
144 AioTransContext *c = static_cast<AioTransContext*>(priv2);
145 c->aio_finish();
146 }
147};//class WriteLog
148
149} // namespace ssd
150} // namespace pwl
151} // namespace cache
152} // namespace librbd
153
154extern template class librbd::cache::pwl::ssd::WriteLog<librbd::ImageCtx>;
155
156#endif // CEPH_LIBRBD_CACHE_PWL_SSD_WRITE_LOG