X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Flibrbd%2FAsyncRequest.h;fp=src%2Fceph%2Fsrc%2Flibrbd%2FAsyncRequest.h;h=f74368dc644f68325a78aab8eafb3a9eed7c9069;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/librbd/AsyncRequest.h b/src/ceph/src/librbd/AsyncRequest.h new file mode 100644 index 0000000..f74368d --- /dev/null +++ b/src/ceph/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 +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 *>::item m_xlist_item; + + void start_request(); + void finish_request(); +}; + +} // namespace librbd + +extern template class librbd::AsyncRequest; + +#endif //CEPH_LIBRBD_ASYNC_REQUEST_H