summaryrefslogtreecommitdiffstats
path: root/src/librbd/operation/SnapshotRollbackRequest.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/librbd/operation/SnapshotRollbackRequest.h
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librbd/operation/SnapshotRollbackRequest.h')
-rw-r--r--src/librbd/operation/SnapshotRollbackRequest.h122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/librbd/operation/SnapshotRollbackRequest.h b/src/librbd/operation/SnapshotRollbackRequest.h
new file mode 100644
index 00000000..e58a618f
--- /dev/null
+++ b/src/librbd/operation/SnapshotRollbackRequest.h
@@ -0,0 +1,122 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_LIBRBD_OPERATION_SNAPSHOT_ROLLBACK_REQUEST_H
+#define CEPH_LIBRBD_OPERATION_SNAPSHOT_ROLLBACK_REQUEST_H
+
+#include "librbd/operation/Request.h"
+#include "librbd/ImageCtx.h"
+#include "librbd/internal.h"
+#include "librbd/journal/Types.h"
+#include <string>
+
+class Context;
+
+namespace librbd {
+
+class ProgressContext;
+
+namespace operation {
+
+template <typename ImageCtxT = ImageCtx>
+class SnapshotRollbackRequest : public Request<ImageCtxT> {
+public:
+ /**
+ * Snap Rollback goes through the following state machine:
+ *
+ * @verbatim
+ *
+ * <start> ---------\
+ * |
+ * v
+ * STATE_BLOCK_WRITES
+ * |
+ * v
+ * STATE_RESIZE_IMAGE (skip if resize not
+ * | required)
+ * v
+ * STATE_GET_SNAP_OBJECT_MAP (skip if object)
+ * | map disabled)
+ * v
+ * STATE_ROLLBACK_OBJECT_MAP (skip if object
+ * | map disabled)
+ * v
+ * STATE_ROLLBACK_OBJECTS
+ * |
+ * v
+ * STATE_REFRESH_OBJECT_MAP (skip if object
+ * | map disabled)
+ * v
+ * STATE_INVALIDATE_CACHE (skip if cache
+ * | disabled)
+ * v
+ * <finish>
+ *
+ * @endverbatim
+ *
+ * The _RESIZE_IMAGE state is skipped if the image doesn't need to be resized.
+ * The _ROLLBACK_OBJECT_MAP state is skipped if the object map isn't enabled.
+ * The _INVALIDATE_CACHE state is skipped if the cache isn't enabled.
+ */
+
+ SnapshotRollbackRequest(ImageCtxT &image_ctx, Context *on_finish,
+ const cls::rbd::SnapshotNamespace &snap_namespace,
+ const std::string &snap_name,
+ uint64_t snap_id,
+ uint64_t snap_size, ProgressContext &prog_ctx);
+ ~SnapshotRollbackRequest() override;
+
+protected:
+ void send_op() override;
+ bool should_complete(int r) override {
+ return true;
+ }
+
+ journal::Event create_event(uint64_t op_tid) const override {
+ return journal::SnapRollbackEvent(op_tid, m_snap_namespace, m_snap_name);
+ }
+
+private:
+ cls::rbd::SnapshotNamespace m_snap_namespace;
+ std::string m_snap_name;
+ uint64_t m_snap_id;
+ uint64_t m_snap_size;
+ uint64_t m_head_num_objects;
+ ProgressContext &m_prog_ctx;
+
+ NoOpProgressContext m_no_op_prog_ctx;
+
+ bool m_blocking_writes = false;
+ decltype(ImageCtxT::object_map) m_object_map;
+ decltype(ImageCtxT::object_map) m_snap_object_map;
+
+ void send_block_writes();
+ Context *handle_block_writes(int *result);
+
+ void send_resize_image();
+ Context *handle_resize_image(int *result);
+
+ void send_get_snap_object_map();
+ Context *handle_get_snap_object_map(int *result);
+
+ void send_rollback_object_map();
+ Context *handle_rollback_object_map(int *result);
+
+ void send_rollback_objects();
+ Context *handle_rollback_objects(int *result);
+
+ Context *send_refresh_object_map();
+ Context *handle_refresh_object_map(int *result);
+
+ Context *send_invalidate_cache();
+ Context *handle_invalidate_cache(int *result);
+
+ void apply();
+};
+
+} // namespace operation
+} // namespace librbd
+
+extern template class librbd::operation::SnapshotRollbackRequest<librbd::ImageCtx>;
+
+#endif // CEPH_LIBRBD_OPERATION_SNAPSHOT_ROLLBACK_REQUEST_H