Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / object_map / LockRequest.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_OBJECT_MAP_LOCK_REQUEST_H
5 #define CEPH_LIBRBD_OBJECT_MAP_LOCK_REQUEST_H
6
7 #include "include/buffer.h"
8 #include "cls/lock/cls_lock_types.h"
9 #include <map>
10
11 class Context;
12
13 namespace librbd {
14
15 class ImageCtx;
16
17 namespace object_map {
18
19 template <typename ImageCtxT = ImageCtx>
20 class LockRequest {
21 public:
22   static LockRequest* create(ImageCtxT &image_ctx, Context *on_finish) {
23     return new LockRequest(image_ctx, on_finish);
24   }
25   LockRequest(ImageCtxT &image_ctx, Context *on_finish);
26
27   void send();
28
29 private:
30   /**
31    * @verbatim
32    *
33    * <start>         /------------------------------------- BREAK_LOCKS * * *
34    *    |            |                                        ^             *
35    *    |            |                                        |             *
36    *    |            |                                        |             *
37    *    |            v   (EBUSY && !broke_lock)               |             *
38    *    \---------> LOCK_OBJECT_MAP * * * * * * * * * * * > GET_LOCK_INFO * *
39    *                 |  *       ^                             *             *
40    *                 |  *       *                             *             *
41    *                 |  *       *  (ENOENT)                   *             *
42    *                 |  *       * * * * * * * * * * * * * * * *             *
43    *                 |  *                                                   *
44    *                 |  * (other errors)                                    *
45    *                 |  *                                                   *
46    *                 v  v                         (other errors)            *
47    *               <finish> < * * * * * * * * * * * * * * * * * * * * * * * *
48    *
49    * @endverbatim
50    */
51
52   ImageCtxT &m_image_ctx;
53   Context *m_on_finish;
54
55   bool m_broke_lock;
56   std::map<rados::cls::lock::locker_id_t,
57            rados::cls::lock::locker_info_t> m_lockers;
58   bufferlist m_out_bl;
59
60   void send_lock();
61   Context *handle_lock(int *ret_val);
62
63   void send_get_lock_info();
64   Context *handle_get_lock_info(int *ret_val);
65
66   void send_break_locks();
67   Context *handle_break_locks(int *ret_val);
68 };
69
70 } // namespace object_map
71 } // namespace librbd
72
73 extern template class librbd::object_map::LockRequest<librbd::ImageCtx>;
74
75 #endif // CEPH_LIBRBD_OBJECT_MAP_LOCK_REQUEST_H