]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/operation/TrimRequest.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / librbd / operation / TrimRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_LIBRBD_OPERATION_TRIM_REQUEST_H
4 #define CEPH_LIBRBD_OPERATION_TRIM_REQUEST_H
5
6 #include "librbd/AsyncRequest.h"
7
8 namespace librbd
9 {
10
11 class ImageCtx;
12 class ProgressContext;
13
14 namespace operation {
15
16 template <typename ImageCtxT = ImageCtx>
17 class TrimRequest : public AsyncRequest<ImageCtxT>
18 {
19 public:
20 static TrimRequest *create(ImageCtxT &image_ctx, Context *on_finish,
21 uint64_t original_size, uint64_t new_size,
22 ProgressContext &prog_ctx) {
23 return new TrimRequest(image_ctx, on_finish, original_size, new_size,
24 prog_ctx);
25 }
26
27 void send() override;
28
29 protected:
30 /**
31 * Trim goes through the following state machine to remove whole objects,
32 * clean partially trimmed objects, and update the object map:
33 *
34 * @verbatim
35 *
36 * <start> . . . . > STATE_FINISHED . . . . . . . . .
37 * | . . . . . . . . . . > . . . . . . . . . .
38 * | / . .
39 * STATE_PRE_COPYUP ---> STATE_COPYUP_OBJECTS . .
40 * | . .
41 * /-----------------------/ v .
42 * | . .
43 * v . .
44 * STATE_POST_COPYUP. . . > . . .
45 * | . . . . . . . . . . < . . . . . . . . . .
46 * | | . .
47 * v v v .
48 * STATE_PRE_REMOVE ---> STATE_REMOVE_OBJECTS .
49 * | . . .
50 * /-----------------------/ . . . . . . . .
51 * | . . .
52 * v v v v
53 * STATE_POST_REMOVE --> STATE_CLEAN_BOUNDARY ---> <finish>
54 * . ^
55 * . .
56 * . . . . . . . . . . . . . . . . . . . . . . .
57 *
58 * @endverbatim
59 *
60 * The _COPYUP_OBJECTS state is skipped if there is no parent overlap
61 * within the new image size and the image does not have any snapshots.
62 * The _PRE_REMOVE/_POST_REMOVE states are skipped if the object map
63 * isn't enabled. The _REMOVE_OBJECTS state is skipped if no whole objects
64 * are removed. The _CLEAN_BOUNDARY state is skipped if no boundary
65 * objects are cleaned. The state machine will immediately transition
66 * to _FINISHED state if there are no bytes to trim.
67 */
68
69 enum State {
70 STATE_PRE_COPYUP,
71 STATE_COPYUP_OBJECTS,
72 STATE_POST_COPYUP,
73 STATE_PRE_REMOVE,
74 STATE_REMOVE_OBJECTS,
75 STATE_POST_REMOVE,
76 STATE_CLEAN_BOUNDARY,
77 STATE_FINISHED
78 };
79
80 bool should_complete(int r) override;
81
82 State m_state;
83
84 private:
85 uint64_t m_delete_start;
86 uint64_t m_num_objects;
87 uint64_t m_delete_off;
88 uint64_t m_new_size;
89 ProgressContext &m_prog_ctx;
90
91 uint64_t m_copyup_start;
92 uint64_t m_copyup_end;
93
94 TrimRequest(ImageCtxT &image_ctx, Context *on_finish,
95 uint64_t original_size, uint64_t new_size,
96 ProgressContext &prog_ctx);
97
98 void send_pre_copyup();
99 void send_copyup_objects();
100 void send_post_copyup();
101
102 void send_pre_remove();
103 void send_remove_objects();
104 void send_post_remove();
105
106 void send_clean_boundary();
107 void send_finish(int r);
108 };
109
110 } // namespace operation
111 } // namespace librbd
112
113 extern template class librbd::operation::TrimRequest<librbd::ImageCtx>;
114
115 #endif // CEPH_LIBRBD_OPERATION_TRIM_REQUEST_H