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_RESIZE_REQUEST_H
4 #define CEPH_LIBRBD_OPERATION_RESIZE_REQUEST_H
6 #include "librbd/operation/Request.h"
7 #include "include/xlist.h"
13 class ProgressContext;
17 template <typename ImageCtxT = ImageCtx>
18 class ResizeRequest : public Request<ImageCtxT> {
20 static ResizeRequest *create(ImageCtxT &image_ctx, Context *on_finish,
21 uint64_t new_size, bool allow_shrink,
22 ProgressContext &prog_ctx, uint64_t journal_op_tid,
23 bool disable_journal) {
24 return new ResizeRequest(image_ctx, on_finish, new_size, allow_shrink, prog_ctx,
25 journal_op_tid, disable_journal);
28 ResizeRequest(ImageCtxT &image_ctx, Context *on_finish, uint64_t new_size,
29 bool allow_shrink, ProgressContext &prog_ctx, uint64_t journal_op_tid,
30 bool disable_journal);
31 ~ResizeRequest() override;
33 inline bool shrinking() const {
34 return (m_shrink_size_visible && m_new_size < m_original_size);
37 inline uint64_t get_image_size() const {
44 void send_op() override;
45 bool should_complete(int r) override {
48 bool can_affect_io() const override {
51 journal::Event create_event(uint64_t op_tid) const override {
52 return journal::ResizeEvent(op_tid, m_new_size);
57 * Resize goes through the following state machine to resize the image
58 * and update the object map:
65 * STATE_PRE_BLOCK_WRITES
68 * STATE_APPEND_OP_EVENT (skip if journaling
74 * |\--------> STATE_GROW_OBJECT_MAP (skip if object map
77 * | STATE_POST_BLOCK_WRITES
80 * | STATE_UPDATE_HEADER ----------------------------\
83 * |\--------> STATE_FLUSH_CACHE |
86 * | STATE_INVALIDATE_CACHE |
89 * | STATE_TRIM_IMAGE |
92 * | STATE_POST_BLOCK_WRITES |
95 * | STATE_UPDATE_HEADER |
98 * | STATE_SHRINK_OBJECT_MAP (skip if object map |
100 * | | (unblock writes) |
102 * \------------> <finish> <-----------------------------------/
106 * The _OBJECT_MAP states are skipped if the object map isn't enabled.
107 * The state machine will immediately transition to _FINISHED if there
108 * are no objects to trim.
111 uint64_t m_original_size;
113 bool m_allow_shrink = true;
114 ProgressContext &m_prog_ctx;
115 uint64_t m_new_parent_overlap;
116 bool m_shrink_size_visible = false;
117 bool m_disable_journal = false;
119 typename xlist<ResizeRequest<ImageCtxT>*>::item m_xlist_item;
121 void send_pre_block_writes();
122 Context *handle_pre_block_writes(int *result);
124 Context *send_append_op_event();
125 Context *handle_append_op_event(int *result);
127 void send_flush_cache();
128 Context *handle_flush_cache(int *result);
130 void send_invalidate_cache();
131 Context *handle_invalidate_cache(int *result);
133 void send_trim_image();
134 Context *handle_trim_image(int *result);
136 Context *send_grow_object_map();
137 Context *handle_grow_object_map(int *result);
139 Context *send_shrink_object_map();
140 Context *handle_shrink_object_map(int *result);
142 void send_post_block_writes();
143 Context *handle_post_block_writes(int *result);
145 void send_update_header();
146 Context *handle_update_header(int *result);
148 void compute_parent_overlap();
149 void update_size_and_overlap();
153 } // namespace operation
154 } // namespace librbd
156 extern template class librbd::operation::ResizeRequest<librbd::ImageCtx>;
158 #endif // CEPH_LIBRBD_OPERATION_RESIZE_REQUEST_H