Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / operation / SnapshotUnprotectRequest.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_UNPROTECT_REQUEST_H
5 #define CEPH_LIBRBD_OPERATION_SNAPSHOT_UNPROTECT_REQUEST_H
6
7 #include "librbd/operation/Request.h"
8 #include <string>
9
10 class Context;
11
12 namespace librbd {
13
14 class ImageCtx;
15
16 namespace operation {
17
18 template <typename ImageCtxT = ImageCtx>
19 class SnapshotUnprotectRequest : public Request<ImageCtxT> {
20 public:
21   /**
22    * Snap Unprotect goes through the following state machine:
23    *
24    * @verbatim
25    *
26    * <start>
27    *    |
28    *    v
29    * STATE_UNPROTECT_SNAP_START
30    *    |
31    *    v
32    * STATE_SCAN_POOL_CHILDREN * * * * > STATE_UNPROTECT_SNAP_ROLLBACK
33    *    |                                  |
34    *    v                                  |
35    * STATE_UNPROTECT_SNAP_FINISH           |
36    *    |                                  |
37    *    v                                  |
38    * <finish> <----------------------------/
39    *
40    * @endverbatim
41    *
42    * If the unprotect operation needs to abort, the error path is followed
43    * to rollback the unprotect in-progress status on the image.
44    */
45   enum State {
46     STATE_UNPROTECT_SNAP_START,
47     STATE_SCAN_POOL_CHILDREN,
48     STATE_UNPROTECT_SNAP_FINISH,
49     STATE_UNPROTECT_SNAP_ROLLBACK
50   };
51
52   SnapshotUnprotectRequest(ImageCtxT &image_ctx, Context *on_finish,
53                            const cls::rbd::SnapshotNamespace &snap_namespace,
54                            const std::string &snap_name);
55
56 protected:
57   void send_op() override;
58   bool should_complete(int r) override;
59
60   int filter_return_code(int r) const override {
61     if (m_ret_val < 0) {
62       return m_ret_val;
63     }
64     return 0;
65   }
66
67   journal::Event create_event(uint64_t op_tid) const override {
68     return journal::SnapUnprotectEvent(op_tid, m_snap_namespace, m_snap_name);
69   }
70
71 private:
72   cls::rbd::SnapshotNamespace m_snap_namespace;
73   std::string m_snap_name;
74   State m_state;
75
76   int m_ret_val;
77   uint64_t m_snap_id;
78
79   bool should_complete_error();
80
81   void send_unprotect_snap_start();
82   void send_scan_pool_children();
83   void send_unprotect_snap_finish();
84   void send_unprotect_snap_rollback();
85
86   int verify_and_send_unprotect_snap_start();
87 };
88
89 } // namespace operation
90 } // namespace librbd
91
92 extern template class librbd::operation::SnapshotUnprotectRequest<librbd::ImageCtx>;
93
94 #endif // CEPH_LIBRBD_OPERATION_SNAPSHOT_UNPROTECT_REQUEST_H