Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / operation / SnapshotRollbackRequest.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_OPERATION_SNAPSHOT_ROLLBACK_REQUEST_H
5 #define CEPH_LIBRBD_OPERATION_SNAPSHOT_ROLLBACK_REQUEST_H
6
7 #include "librbd/operation/Request.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/internal.h"
10 #include "librbd/journal/Types.h"
11 #include <string>
12
13 class Context;
14
15 namespace librbd {
16
17 class ProgressContext;
18
19 namespace operation {
20
21 template <typename ImageCtxT = ImageCtx>
22 class SnapshotRollbackRequest : public Request<ImageCtxT> {
23 public:
24   /**
25    * Snap Rollback goes through the following state machine:
26    *
27    * @verbatim
28    *
29    * <start> ---------\
30    *                  |
31    *                  v
32    *            STATE_BLOCK_WRITES
33    *                  |
34    *                  v
35    *            STATE_RESIZE_IMAGE (skip if resize not
36    *                  |             required)
37    *                  v
38    *            STATE_ROLLBACK_OBJECT_MAP (skip if object
39    *                  |                    map disabled)
40    *                  v
41    *            STATE_ROLLBACK_OBJECTS
42    *                  |
43    *                  v
44    *            STATE_REFRESH_OBJECT_MAP  (skip if object
45    *                  |                    map disabled)
46    *                  v
47    *            STATE_INVALIDATE_CACHE (skip if cache
48    *                  |                 disabled)
49    *                  v
50    *              <finish>
51    *
52    * @endverbatim
53    *
54    * The _RESIZE_IMAGE state is skipped if the image doesn't need to be resized.
55    * The _ROLLBACK_OBJECT_MAP state is skipped if the object map isn't enabled.
56    * The _INVALIDATE_CACHE state is skipped if the cache isn't enabled.
57    */
58
59   SnapshotRollbackRequest(ImageCtxT &image_ctx, Context *on_finish,
60                           const cls::rbd::SnapshotNamespace &snap_namespace,
61                           const std::string &snap_name,
62                           uint64_t snap_id,
63                           uint64_t snap_size, ProgressContext &prog_ctx);
64   ~SnapshotRollbackRequest() override;
65
66 protected:
67   void send_op() override;
68   bool should_complete(int r) override {
69     return true;
70   }
71
72   journal::Event create_event(uint64_t op_tid) const override {
73     return journal::SnapRollbackEvent(op_tid, m_snap_namespace, m_snap_name);
74   }
75
76 private:
77   cls::rbd::SnapshotNamespace m_snap_namespace;
78   std::string m_snap_name;
79   uint64_t m_snap_id;
80   uint64_t m_snap_size;
81   ProgressContext &m_prog_ctx;
82
83   NoOpProgressContext m_no_op_prog_ctx;
84
85   bool m_blocking_writes = false;
86   decltype(ImageCtxT::object_map) m_object_map;
87
88   void send_block_writes();
89   Context *handle_block_writes(int *result);
90
91   void send_resize_image();
92   Context *handle_resize_image(int *result);
93
94   void send_rollback_object_map();
95   Context *handle_rollback_object_map(int *result);
96
97   void send_rollback_objects();
98   Context *handle_rollback_objects(int *result);
99
100   Context *send_refresh_object_map();
101   Context *handle_refresh_object_map(int *result);
102
103   Context *send_invalidate_cache();
104   Context *handle_invalidate_cache(int *result);
105
106   void apply();
107 };
108
109 } // namespace operation
110 } // namespace librbd
111
112 extern template class librbd::operation::SnapshotRollbackRequest<librbd::ImageCtx>;
113
114 #endif // CEPH_LIBRBD_OPERATION_SNAPSHOT_ROLLBACK_REQUEST_H