]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/AsyncRequest.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / librbd / AsyncRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_LIBRBD_ASYNC_REQUEST_H
4 #define CEPH_LIBRBD_ASYNC_REQUEST_H
5
6 #include "include/Context.h"
7 #include "include/rados/librados.hpp"
8 #include "include/xlist.h"
9 #include "include/compat.h"
10
11 namespace librbd {
12
13 class ImageCtx;
14
15 template <typename ImageCtxT = ImageCtx>
16 class AsyncRequest
17 {
18 public:
19 AsyncRequest(ImageCtxT &image_ctx, Context *on_finish);
20 virtual ~AsyncRequest();
21
22 void complete(int r) {
23 if (should_complete(r)) {
24 r = filter_return_code(r);
25 finish_and_destroy(r);
26 }
27 }
28
29 virtual void send() = 0;
30
31 inline bool is_canceled() const {
32 return m_canceled;
33 }
34 inline void cancel() {
35 m_canceled = true;
36 }
37
38 protected:
39 ImageCtxT &m_image_ctx;
40
41 librados::AioCompletion *create_callback_completion();
42 Context *create_callback_context();
43 Context *create_async_callback_context();
44
45 void async_complete(int r);
46
47 virtual bool should_complete(int r) = 0;
48 virtual int filter_return_code(int r) const {
49 return r;
50 }
51
52 // NOTE: temporary until converted to new state machine format
53 virtual void finish_and_destroy(int r) {
54 finish(r);
55 delete this;
56 }
57
58 virtual void finish(int r) {
59 finish_request();
60 m_on_finish->complete(r);
61 }
62
63 private:
64 Context *m_on_finish;
65 bool m_canceled;
66 typename xlist<AsyncRequest<ImageCtxT> *>::item m_xlist_item;
67
68 void start_request();
69 void finish_request();
70 };
71
72 } // namespace librbd
73
74 extern template class librbd::AsyncRequest<librbd::ImageCtx>;
75
76 #endif //CEPH_LIBRBD_ASYNC_REQUEST_H