1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_LIBRBD_OPERATION_REQUEST_H
5 #define CEPH_LIBRBD_OPERATION_REQUEST_H
7 #include "librbd/AsyncRequest.h"
8 #include "include/Context.h"
9 #include "common/RWLock.h"
10 #include "librbd/Utils.h"
11 #include "librbd/Journal.h"
19 template <typename ImageCtxT = ImageCtx>
20 class Request : public AsyncRequest<ImageCtxT> {
22 Request(ImageCtxT &image_ctx, Context *on_finish,
23 uint64_t journal_op_tid = 0);
28 void finish(int r) override;
29 virtual void send_op() = 0;
31 virtual bool can_affect_io() const {
34 virtual journal::Event create_event(uint64_t op_tid) const = 0;
36 template <typename T, Context*(T::*MF)(int*)>
37 bool append_op_event(T *request) {
38 ImageCtxT &image_ctx = this->m_image_ctx;
40 assert(can_affect_io());
41 RWLock::RLocker owner_locker(image_ctx.owner_lock);
42 RWLock::RLocker snap_locker(image_ctx.snap_lock);
43 if (image_ctx.journal != nullptr) {
44 if (image_ctx.journal->is_journal_replaying()) {
45 Context *ctx = util::create_context_callback<T, MF>(request);
48 } else if (image_ctx.journal->is_journal_appending()) {
49 Context *ctx = util::create_context_callback<T, MF>(request);
57 bool append_op_event();
59 // NOTE: temporary until converted to new state machine format
60 Context *create_context_finisher(int r);
61 void finish_and_destroy(int r) override;
64 struct C_AppendOpEvent : public Context {
67 C_AppendOpEvent(Request *request, Context *on_safe)
68 : request(request), on_safe(on_safe) {
70 void finish(int r) override {
72 request->m_appended_op_event = true;
78 struct C_CommitOpEvent : public Context {
81 C_CommitOpEvent(Request *request, int ret_val)
82 : request(request), ret_val(ret_val) {
84 void finish(int r) override {
85 request->handle_commit_op_event(r, ret_val);
90 uint64_t m_op_tid = 0;
91 bool m_appended_op_event = false;
92 bool m_committed_op_event = false;
94 void replay_op_ready(Context *on_safe);
95 void append_op_event(Context *on_safe);
96 void handle_op_event_safe(int r);
98 bool commit_op_event(int r);
99 void handle_commit_op_event(int r, int original_ret_val);
103 } // namespace operation
104 } // namespace librbd
106 extern template class librbd::operation::Request<librbd::ImageCtx>;
108 #endif // CEPH_LIBRBD_OPERATION_REQUEST_H