Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / operation / RenameRequest.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_RENAME_REQUEST_H
5 #define CEPH_LIBRBD_RENAME_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 RenameRequest : public Request<ImageCtxT>
20 {
21 public:
22   /**
23    * Rename goes through the following state machine:
24    *
25    * @verbatim
26    *
27    * <start>
28    *    |
29    *    v
30    * STATE_READ_SOURCE_HEADER
31    *    |
32    *    v
33    * STATE_WRITE_DEST_HEADER
34    *    |
35    *    v
36    * STATE_UPDATE_DIRECTORY
37    *    |
38    *    v
39    * STATE_REMOVE_SOURCE_HEADER
40    *    |
41    *    v
42    * <finish>
43    *
44    * @endverbatim
45    *
46    */
47   enum State {
48     STATE_READ_SOURCE_HEADER,
49     STATE_WRITE_DEST_HEADER,
50     STATE_UPDATE_DIRECTORY,
51     STATE_REMOVE_SOURCE_HEADER
52   };
53
54   RenameRequest(ImageCtxT &image_ctx, Context *on_finish,
55                 const std::string &dest_name);
56
57 protected:
58   void send_op() override;
59   bool should_complete(int r) override;
60
61   journal::Event create_event(uint64_t op_tid) const override {
62     return journal::RenameEvent(op_tid, m_dest_name);
63   }
64
65 private:
66   std::string m_dest_name;
67
68   std::string m_source_oid;
69   std::string m_dest_oid;
70
71   State m_state;
72
73   bufferlist m_header_bl;
74
75   int filter_state_return_code(int r);
76
77   void send_read_source_header();
78   void send_write_destination_header();
79   void send_update_directory();
80   void send_remove_source_header();
81
82   void apply();
83 };
84
85 } // namespace operation
86 } // namespace librbd
87
88 extern template class librbd::operation::RenameRequest<librbd::ImageCtx>;
89
90 #endif // CEPH_LIBRBD_RENAME_REQUEST_H