Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / image / SetSnapRequest.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_IMAGE_SNAP_SET_REQUEST_H
5 #define CEPH_LIBRBD_IMAGE_SNAP_SET_REQUEST_H
6
7 #include "cls/rbd/cls_rbd_client.h"
8 #include <string>
9
10 class Context;
11
12 namespace librbd {
13
14 template <typename> class ExclusiveLock;
15 class ImageCtx;
16 template <typename> class ObjectMap;
17
18 namespace image {
19
20 template <typename> class RefreshParentRequest;
21
22 template <typename ImageCtxT = ImageCtx>
23 class SetSnapRequest {
24 public:
25   static SetSnapRequest *create(ImageCtxT &image_ctx,
26                                 const cls::rbd::SnapshotNamespace& snap_namespace,
27                                 const std::string &snap_name,
28                                 Context *on_finish) {
29     return new SetSnapRequest(image_ctx, snap_namespace, snap_name, on_finish);
30   }
31
32   ~SetSnapRequest();
33
34   void send();
35
36 private:
37   /**
38    * @verbatim
39    *
40    * <start>
41    *    |
42    *    | (set snap)
43    *    |-----------> BLOCK_WRITES
44    *    |                 |
45    *    |                 v
46    *    |             SHUTDOWN_EXCLUSIVE_LOCK (skip if lock inactive
47    *    |                 |                    or disabled)
48    *    |                 v
49    *    |             REFRESH_PARENT (skip if no parent
50    *    |                 |           or refresh not needed)
51    *    |                 v
52    *    |             OPEN_OBJECT_MAP (skip if map disabled)
53    *    |                 |
54    *    |                 v
55    *    |              <apply>
56    *    |                 |
57    *    |                 v
58    *    |             FINALIZE_REFRESH_PARENT (skip if no parent
59    *    |                 |                    or refresh not needed)
60    *    |                 v
61    *    |             <finish>
62    *    |
63    *    \-----------> INIT_EXCLUSIVE_LOCK (skip if active or
64    *                      |                disabled)
65    *                      v
66    *                  REFRESH_PARENT (skip if no parent
67    *                      |           or refresh not needed)
68    *                      v
69    *                   <apply>
70    *                      |
71    *                      v
72    *                  FINALIZE_REFRESH_PARENT (skip if no parent
73    *                      |                    or refresh not needed)
74    *                      v
75    *                  <finish>
76    *
77    * @endverbatim
78    */
79
80   SetSnapRequest(ImageCtxT &image_ctx, const cls::rbd::SnapshotNamespace& snap_namespace,
81                  const std::string &snap_name,
82                 Context *on_finish);
83
84   ImageCtxT &m_image_ctx;
85   cls::rbd::SnapshotNamespace m_snap_namespace;
86   std::string m_snap_name;
87   Context *m_on_finish;
88
89   uint64_t m_snap_id;
90   ExclusiveLock<ImageCtxT> *m_exclusive_lock;
91   ObjectMap<ImageCtxT> *m_object_map;
92   RefreshParentRequest<ImageCtxT> *m_refresh_parent;
93
94   bool m_writes_blocked;
95
96   void send_block_writes();
97   Context *handle_block_writes(int *result);
98
99   void send_init_exclusive_lock();
100   Context *handle_init_exclusive_lock(int *result);
101
102   Context *send_shut_down_exclusive_lock(int *result);
103   Context *handle_shut_down_exclusive_lock(int *result);
104
105   Context *send_refresh_parent(int *result);
106   Context *handle_refresh_parent(int *result);
107
108   Context *send_open_object_map(int *result);
109   Context *handle_open_object_map(int *result);
110
111   Context *send_finalize_refresh_parent(int *result);
112   Context *handle_finalize_refresh_parent(int *result);
113
114   int apply();
115   void finalize();
116   void send_complete();
117 };
118
119 } // namespace image
120 } // namespace librbd
121
122 extern template class librbd::image::SetSnapRequest<librbd::ImageCtx>;
123
124 #endif // CEPH_LIBRBD_IMAGE_SNAP_SET_REQUEST_H