]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/operation/TrimRequest.h
update sources to 12.2.2
[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 TrimRequest(ImageCtxT &image_ctx, Context *on_finish,
28 uint64_t original_size, uint64_t new_size,
29 ProgressContext &prog_ctx);
30
31 void send() override;
32
33 protected:
34 /**
35 * Trim goes through the following state machine to remove whole objects,
36 * clean partially trimmed objects, and update the object map:
37 *
38 * @verbatim
39 *
40 * <start> . . . . . . . . . . . . . . . . .
41 * | .
42 * v (skip if not needed) .
43 * STATE_PRE_TRIM .
44 * | .
45 * v (skip if not needed) .
46 * STATE_COPYUP_OBJECTS .
47 * | .
48 * v (skip if not needed) .
49 * STATE_REMOVE_OBJECTS .
50 * | .
51 * v (skip if not needed) .
52 * STATE_POST_TRIM .
53 * | .
54 * v (skip if not needed) .
55 * STATE_CLEAN_BOUNDARY .
56 * | .
57 * v .
58 * STATE_FINISHED < . . . . . . . . . . . . . . .
59 * |
60 * v
61 * <finish>
62 *
63 * The _COPYUP_OBJECTS state is skipped if there is no parent overlap
64 * within the new image size and the image does not have any snapshots.
65 * The _PRE_TRIM/_POST_TRIM states are skipped if the object map
66 * isn't enabled. The _REMOVE_OBJECTS state is skipped if no whole objects
67 * are removed. The _CLEAN_BOUNDARY state is skipped if no boundary
68 * objects are cleaned. The state machine will immediately transition
69 * to _FINISHED state if there are no bytes to trim.
70 */
71
72 enum State {
73 STATE_PRE_TRIM,
74 STATE_COPYUP_OBJECTS,
75 STATE_REMOVE_OBJECTS,
76 STATE_POST_TRIM,
77 STATE_CLEAN_BOUNDARY,
78 STATE_FINISHED
79 };
80
81 bool should_complete(int r) override;
82
83 State m_state = STATE_PRE_TRIM;
84
85 private:
86 uint64_t m_delete_start;
87 uint64_t m_delete_start_min = 0;
88 uint64_t m_num_objects;
89 uint64_t m_delete_off;
90 uint64_t m_new_size;
91 ProgressContext &m_prog_ctx;
92
93 void send_pre_trim();
94 void send_copyup_objects();
95 void send_remove_objects();
96 void send_post_trim();
97
98 void send_clean_boundary();
99 void send_finish(int r);
100 };
101
102 } // namespace operation
103 } // namespace librbd
104
105 extern template class librbd::operation::TrimRequest<librbd::ImageCtx>;
106
107 #endif // CEPH_LIBRBD_OPERATION_TRIM_REQUEST_H