]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/operation/RenameRequest.h
6534d36c0986918b0ba1108c29c3efbf241ac248
[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_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 int filter_return_code(int r) const override;
61
62 journal::Event create_event(uint64_t op_tid) const override {
63 return journal::RenameEvent(op_tid, m_dest_name);
64 }
65
66 private:
67 std::string m_dest_name;
68
69 std::string m_source_oid;
70 std::string m_dest_oid;
71
72 State m_state = STATE_READ_SOURCE_HEADER;
73
74 bufferlist m_header_bl;
75
76 void send_read_source_header();
77 void send_write_destination_header();
78 void send_update_directory();
79 void send_remove_source_header();
80
81 void apply();
82 };
83
84 } // namespace operation
85 } // namespace librbd
86
87 extern template class librbd::operation::RenameRequest<librbd::ImageCtx>;
88
89 #endif // CEPH_LIBRBD_RENAME_REQUEST_H