Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / exclusive_lock / PreAcquireRequest.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_EXCLUSIVE_LOCK_PRE_ACQUIRE_REQUEST_H
5 #define CEPH_LIBRBD_EXCLUSIVE_LOCK_PRE_ACQUIRE_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/buffer.h"
9 #include "librbd/ImageCtx.h"
10 #include "msg/msg_types.h"
11 #include <string>
12
13 class Context;
14
15 namespace librbd {
16
17 namespace exclusive_lock {
18
19 template <typename ImageCtxT = ImageCtx>
20 class PreAcquireRequest {
21 public:
22   static PreAcquireRequest* create(ImageCtxT &image_ctx, Context *on_finish);
23
24   ~PreAcquireRequest();
25   void send();
26
27 private:
28
29   /**
30    * @verbatim
31    *
32    * <start>
33    *    |
34    *    v
35    * PREPARE_LOCK
36    *    |
37    *    v
38    * FLUSH_NOTIFIES
39    *    |
40    *    |
41    *    |
42         v
43    * <finish>
44    *
45    * @endverbatim
46    */
47
48   PreAcquireRequest(ImageCtxT &image_ctx, Context *on_finish);
49
50   ImageCtxT &m_image_ctx;
51   Context *m_on_finish;
52
53   int m_error_result;
54
55   void send_prepare_lock();
56   void handle_prepare_lock(int r);
57
58   void send_flush_notifies();
59   void handle_flush_notifies(int r);
60
61   void finish();
62
63   void save_result(int result) {
64     if (m_error_result == 0 && result < 0) {
65       m_error_result = result;
66     }
67   }
68 };
69
70 } // namespace exclusive_lock
71 } // namespace librbd
72
73 extern template class librbd::exclusive_lock::PreAcquireRequest<librbd::ImageCtx>;
74
75 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_ACQUIRE_REQUEST_H