Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / journal / Utils.h
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_JOURNAL_UTILS_H
5 #define CEPH_JOURNAL_UTILS_H
6
7 #include "include/int_types.h"
8 #include "include/Context.h"
9 #include "include/rados/librados.hpp"
10 #include <string>
11
12 namespace journal {
13 namespace utils {
14
15 namespace detail {
16
17 template <typename M>
18 struct C_AsyncCallback : public Context {
19   M journal_metadata;
20   Context *on_finish;
21
22   C_AsyncCallback(M journal_metadata, Context *on_finish)
23     : journal_metadata(journal_metadata), on_finish(on_finish) {
24   }
25   void finish(int r) override {
26     journal_metadata->queue(on_finish, r);
27   }
28 };
29
30 } // namespace detail
31
32 template <typename T, void(T::*MF)(int)>
33 void rados_state_callback(rados_completion_t c, void *arg) {
34   T *obj = reinterpret_cast<T*>(arg);
35   int r = rados_aio_get_return_value(c);
36   (obj->*MF)(r);
37 }
38
39 std::string get_object_name(const std::string &prefix, uint64_t number);
40
41 std::string unique_lock_name(const std::string &name, void *address);
42
43 void rados_ctx_callback(rados_completion_t c, void *arg);
44
45 template <typename M>
46 Context *create_async_context_callback(M journal_metadata, Context *on_finish) {
47   // use async callback to acquire a clean lock context
48   return new detail::C_AsyncCallback<M>(journal_metadata, on_finish);
49 }
50
51 } // namespace utils
52 } // namespace journal
53
54 #endif // CEPH_JOURNAL_UTILS_H