]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/operation/RenameRequest.h
import ceph 15.2.10
[ceph.git] / 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_DIRECTORY
31 * |
32 * v
33 * STATE_READ_SOURCE_HEADER
34 * |
35 * v
36 * STATE_WRITE_DEST_HEADER
37 * |
38 * v
39 * STATE_UPDATE_DIRECTORY
40 * |
41 * v
42 * STATE_REMOVE_SOURCE_HEADER
43 * |
44 * v
45 * <finish>
46 *
47 * @endverbatim
48 *
49 */
50 enum State {
51 STATE_READ_DIRECTORY,
52 STATE_READ_SOURCE_HEADER,
53 STATE_WRITE_DEST_HEADER,
54 STATE_UPDATE_DIRECTORY,
55 STATE_REMOVE_SOURCE_HEADER
56 };
57
58 RenameRequest(ImageCtxT &image_ctx, Context *on_finish,
59 const std::string &dest_name);
60
61 protected:
62 void send_op() override;
63 bool should_complete(int r) override;
64 int filter_return_code(int r) const override;
65
66 journal::Event create_event(uint64_t op_tid) const override {
67 return journal::RenameEvent(op_tid, m_dest_name);
68 }
69
70 private:
71 std::string m_dest_name;
72
73 std::string m_source_oid;
74 std::string m_dest_oid;
75
76 State m_state = STATE_READ_DIRECTORY;
77
78 bufferlist m_source_name_bl;
79 bufferlist m_header_bl;
80
81 void send_read_directory();
82 void send_read_source_header();
83 void send_write_destination_header();
84 void send_update_directory();
85 void send_remove_source_header();
86
87 void apply();
88 };
89
90 } // namespace operation
91 } // namespace librbd
92
93 extern template class librbd::operation::RenameRequest<librbd::ImageCtx>;
94
95 #endif // CEPH_LIBRBD_RENAME_REQUEST_H