Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / managed_lock / AcquireRequest.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_ACQUIRE_REQUEST_H
5 #define CEPH_LIBRBD_MANAGED_LOCK_ACQUIRE_REQUEST_H
6
7 #include "include/rados/librados.hpp"
8 #include "include/int_types.h"
9 #include "include/buffer.h"
10 #include "msg/msg_types.h"
11 #include "librbd/managed_lock/Types.h"
12 #include "librbd/watcher/Types.h"
13 #include <string>
14
15 class Context;
16 class ContextWQ;
17
18 namespace librbd {
19
20 class Watcher;
21
22 namespace managed_lock {
23
24 template <typename ImageCtxT>
25 class AcquireRequest {
26 private:
27   typedef watcher::Traits<ImageCtxT> TypeTraits;
28   typedef typename TypeTraits::Watcher Watcher;
29
30 public:
31   static AcquireRequest* create(librados::IoCtx& ioctx, Watcher *watcher,
32                                 ContextWQ *work_queue, const std::string& oid,
33                                 const std::string& cookie,
34                                 bool exclusive,
35                                 bool blacklist_on_break_lock,
36                                 uint32_t blacklist_expire_seconds,
37                                 Context *on_finish);
38
39   ~AcquireRequest();
40   void send();
41
42 private:
43
44   /**
45    * @verbatim
46    *
47    * <start>
48    *    |
49    *    v
50    * GET_LOCKER
51    *    |     ^
52    *    |     . (EBUSY && no cached locker)
53    *    |     .
54    *    |     .          (EBUSY && cached locker)
55    *    \--> LOCK_IMAGE * * * * * * * * > BREAK_LOCK . . . . .
56    *            |   ^                         |              .
57    *            |   |                         | (success)    .
58    *            |   \-------------------------/              .
59    *            v                                            .
60    *         <finish>  < . . . . . . . . . . . . . . . . . . .
61    *
62    * @endverbatim
63    */
64
65   AcquireRequest(librados::IoCtx& ioctx, Watcher *watcher,
66                  ContextWQ *work_queue, const std::string& oid,
67                  const std::string& cookie, bool exclusive,
68                  bool blacklist_on_break_lock,
69                  uint32_t blacklist_expire_seconds, Context *on_finish);
70
71   librados::IoCtx& m_ioctx;
72   Watcher *m_watcher;
73   CephContext *m_cct;
74   ContextWQ *m_work_queue;
75   std::string m_oid;
76   std::string m_cookie;
77   bool m_exclusive;
78   bool m_blacklist_on_break_lock;
79   uint32_t m_blacklist_expire_seconds;
80   Context *m_on_finish;
81
82   bufferlist m_out_bl;
83
84   Locker m_locker;
85
86   void send_get_locker();
87   void handle_get_locker(int r);
88
89   void send_lock();
90   void handle_lock(int r);
91
92   void send_break_lock();
93   void handle_break_lock(int r);
94
95   void finish(int r);
96 };
97
98 } // namespace managed_lock
99 } // namespace librbd
100
101 #endif // CEPH_LIBRBD_MANAGED_LOCK_ACQUIRE_REQUEST_H