Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / exclusive_lock / PostAcquireRequest.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_POST_ACQUIRE_REQUEST_H
5 #define CEPH_LIBRBD_EXCLUSIVE_LOCK_POST_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 PostAcquireRequest {
21 public:
22   static PostAcquireRequest* create(ImageCtxT &image_ctx, Context *on_acquire,
23                                     Context *on_finish);
24
25   ~PostAcquireRequest();
26   void send();
27
28 private:
29
30   /**
31    * @verbatim
32    *
33    *    <start>
34    *      |
35    *      |
36    *      v
37    * REFRESH (skip if not
38    *      |   needed)
39    *      v
40    * OPEN_OBJECT_MAP (skip if
41    *      |           disabled)
42    *      v
43    * OPEN_JOURNAL (skip if
44    *      |   *     disabled)
45    *      |   *
46    *      |   * * * * * * * *
47    *      v                 *
48    *  ALLOCATE_JOURNAL_TAG  *
49    *      |            *    *
50    *      |            *    *
51    *      |            v    v
52    *      |         CLOSE_JOURNAL
53    *      |               |
54    *      |               v
55    *      |         CLOSE_OBJECT_MAP
56    *      |               |
57    *      v               |
58    *  <finish> <----------/
59    *
60    * @endverbatim
61    */
62
63   PostAcquireRequest(ImageCtxT &image_ctx, Context *on_acquire,
64                      Context *on_finish);
65
66   ImageCtxT &m_image_ctx;
67   Context *m_on_acquire;
68   Context *m_on_finish;
69
70   decltype(m_image_ctx.object_map) m_object_map;
71   decltype(m_image_ctx.journal) m_journal;
72
73   bool m_prepare_lock_completed = false;
74   int m_error_result;
75
76   void send_refresh();
77   void handle_refresh(int r);
78
79   void send_open_journal();
80   void handle_open_journal(int r);
81
82   void send_allocate_journal_tag();
83   void handle_allocate_journal_tag(int r);
84
85   void send_open_object_map();
86   void handle_open_object_map(int r);
87
88   void send_close_journal();
89   void handle_close_journal(int r);
90
91   void send_close_object_map();
92   void handle_close_object_map(int r);
93
94   void apply();
95   void revert();
96
97   void finish();
98
99   void save_result(int result) {
100     if (m_error_result == 0 && result < 0) {
101       m_error_result = result;
102     }
103   }
104 };
105
106 } // namespace exclusive_lock
107 } // namespace librbd
108
109 extern template class librbd::exclusive_lock::PostAcquireRequest<librbd::ImageCtx>;
110
111 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_POST_ACQUIRE_REQUEST_H