Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / managed_lock / BreakRequest.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_LIBRBD_MANAGED_LOCK_BREAK_REQUEST_H
5 #define CEPH_LIBRBD_MANAGED_LOCK_BREAK_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/buffer.h"
9 #include "msg/msg_types.h"
10 #include <list>
11 #include <string>
12 #include <boost/optional.hpp>
13 #include "librbd/managed_lock/Types.h"
14
15 class Context;
16 class ContextWQ;
17 class obj_watch_t;
18
19 namespace librados { class IoCtx; }
20
21 namespace librbd {
22
23 class ImageCtx;
24 template <typename> class Journal;
25
26 namespace managed_lock {
27
28 template <typename ImageCtxT = ImageCtx>
29 class BreakRequest {
30 public:
31   static BreakRequest* create(librados::IoCtx& ioctx, ContextWQ *work_queue,
32                               const std::string& oid, const Locker &locker,
33                               bool exclusive, bool blacklist_locker,
34                               uint32_t blacklist_expire_seconds,
35                               bool force_break_lock, Context *on_finish) {
36     return new BreakRequest(ioctx, work_queue, oid, locker, exclusive,
37                             blacklist_locker, blacklist_expire_seconds,
38                             force_break_lock, on_finish);
39   }
40
41   void send();
42
43 private:
44   /**
45    * @verbatim
46    *
47    * <start>
48    *    |
49    *    v
50    * GET_WATCHERS
51    *    |
52    *    v
53    * GET_LOCKER
54    *    |
55    *    v
56    * BLACKLIST (skip if disabled)
57    *    |
58    *    v
59    * BREAK_LOCK
60    *    |
61    *    v
62    * <finish>
63    *
64    * @endvertbatim
65    */
66
67   librados::IoCtx &m_ioctx;
68   CephContext *m_cct;
69   ContextWQ *m_work_queue;
70   std::string m_oid;
71   Locker m_locker;
72   bool m_exclusive;
73   bool m_blacklist_locker;
74   uint32_t m_blacklist_expire_seconds;
75   bool m_force_break_lock;
76   Context *m_on_finish;
77
78   bufferlist m_out_bl;
79
80   std::list<obj_watch_t> m_watchers;
81   int m_watchers_ret_val;
82
83   Locker m_refreshed_locker;
84
85   BreakRequest(librados::IoCtx& ioctx, ContextWQ *work_queue,
86                const std::string& oid, const Locker &locker,
87                bool exclusive, bool blacklist_locker,
88                uint32_t blacklist_expire_seconds, bool force_break_lock,
89                Context *on_finish);
90
91   void send_get_watchers();
92   void handle_get_watchers(int r);
93
94   void send_get_locker();
95   void handle_get_locker(int r);
96
97   void send_blacklist();
98   void handle_blacklist(int r);
99
100   void send_break_lock();
101   void handle_break_lock(int r);
102
103   void finish(int r);
104
105 };
106
107 } // namespace managed_lock
108 } // namespace librbd
109
110 extern template class librbd::managed_lock::BreakRequest<librbd::ImageCtx>;
111
112 #endif // CEPH_LIBRBD_MANAGED_LOCK_BREAK_REQUEST_H