Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / operation / SnapshotRemoveRequest.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_REMOVE_REQUEST_H
5 #define CEPH_LIBRBD_OPERATION_SNAPSHOT_REMOVE_REQUEST_H
6
7 #include "librbd/operation/Request.h"
8 #include "librbd/Types.h"
9 #include <string>
10
11 class Context;
12
13 namespace librbd {
14
15 class ImageCtx;
16
17 namespace operation {
18
19 template <typename ImageCtxT = ImageCtx>
20 class SnapshotRemoveRequest : public Request<ImageCtxT> {
21 public:
22   /**
23    * Snap Remove goes through the following state machine:
24    *
25    * @verbatim
26    *
27    * <start> ------\
28    *  .            |
29    *  .            v
30    *  .     STATE_REMOVE_OBJECT_MAP
31    *  .            |            .
32    *  .            v            .
33    *  . . > STATE_REMOVE_CHILD  .
34    *  .            |            .
35    *  .            |      . . . .
36    *  .            |      .
37    *  .            v      v
38    *  . . > STATE_REMOVE_SNAP
39    *               |
40    *               v
41    *        STATE_RELEASE_SNAP_ID
42    *               |
43    *               v
44    *           <finish>
45    *
46    * @endverbatim
47    *
48    * The _REMOVE_OBJECT_MAP state is skipped if the object map is not enabled.
49    * The _REMOVE_CHILD state is skipped if the parent is still in-use.
50    */
51   enum State {
52     STATE_REMOVE_OBJECT_MAP,
53     STATE_REMOVE_CHILD,
54     STATE_REMOVE_SNAP,
55     STATE_RELEASE_SNAP_ID,
56     STATE_ERROR
57   };
58
59   SnapshotRemoveRequest(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
64 protected:
65   void send_op() override;
66   bool should_complete(int r) override;
67
68   journal::Event create_event(uint64_t op_tid) const override {
69     return journal::SnapRemoveEvent(op_tid, m_snap_namespace, m_snap_name);
70   }
71
72 private:
73   cls::rbd::SnapshotNamespace m_snap_namespace;
74   std::string m_snap_name;
75   uint64_t m_snap_id;
76   State m_state;
77
78   int filter_state_return_code(int r) const {
79     if (m_state == STATE_REMOVE_CHILD && r == -ENOENT) {
80       return 0;
81     }
82     return r;
83   }
84
85   void send_remove_object_map();
86   void send_remove_child();
87   void send_remove_snap();
88   void send_release_snap_id();
89
90   void remove_snap_context();
91   int scan_for_parents(ParentSpec &pspec);
92
93 };
94
95 } // namespace operation
96 } // namespace librbd
97
98 extern template class librbd::operation::SnapshotRemoveRequest<librbd::ImageCtx>;
99
100 #endif // CEPH_LIBRBD_OPERATION_SNAPSHOT_REMOVE_REQUEST_H