summaryrefslogtreecommitdiffstats
path: root/src/librbd/AsyncRequest.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/librbd/AsyncRequest.h
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librbd/AsyncRequest.h')
-rw-r--r--src/librbd/AsyncRequest.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/librbd/AsyncRequest.h b/src/librbd/AsyncRequest.h
new file mode 100644
index 000000000..f74368dc6
--- /dev/null
+++ b/src/librbd/AsyncRequest.h
@@ -0,0 +1,76 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+#ifndef CEPH_LIBRBD_ASYNC_REQUEST_H
+#define CEPH_LIBRBD_ASYNC_REQUEST_H
+
+#include "include/Context.h"
+#include "include/rados/librados.hpp"
+#include "include/xlist.h"
+#include "include/compat.h"
+
+namespace librbd {
+
+class ImageCtx;
+
+template <typename ImageCtxT = ImageCtx>
+class AsyncRequest
+{
+public:
+ AsyncRequest(ImageCtxT &image_ctx, Context *on_finish);
+ virtual ~AsyncRequest();
+
+ void complete(int r) {
+ if (should_complete(r)) {
+ r = filter_return_code(r);
+ finish_and_destroy(r);
+ }
+ }
+
+ virtual void send() = 0;
+
+ inline bool is_canceled() const {
+ return m_canceled;
+ }
+ inline void cancel() {
+ m_canceled = true;
+ }
+
+protected:
+ ImageCtxT &m_image_ctx;
+
+ librados::AioCompletion *create_callback_completion();
+ Context *create_callback_context();
+ Context *create_async_callback_context();
+
+ void async_complete(int r);
+
+ virtual bool should_complete(int r) = 0;
+ virtual int filter_return_code(int r) const {
+ return r;
+ }
+
+ // NOTE: temporary until converted to new state machine format
+ virtual void finish_and_destroy(int r) {
+ finish(r);
+ delete this;
+ }
+
+ virtual void finish(int r) {
+ finish_request();
+ m_on_finish->complete(r);
+ }
+
+private:
+ Context *m_on_finish;
+ bool m_canceled;
+ typename xlist<AsyncRequest<ImageCtxT> *>::item m_xlist_item;
+
+ void start_request();
+ void finish_request();
+};
+
+} // namespace librbd
+
+extern template class librbd::AsyncRequest<librbd::ImageCtx>;
+
+#endif //CEPH_LIBRBD_ASYNC_REQUEST_H