1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_LIBRBD_OPERATION_SNAPSHOT_CREATE_REQUEST_H
5 #define CEPH_LIBRBD_OPERATION_SNAPSHOT_CREATE_REQUEST_H
7 #include "cls/rbd/cls_rbd_types.h"
8 #include "librbd/Types.h"
9 #include "librbd/operation/Request.h"
20 template <typename ImageCtxT = ImageCtx>
21 class SnapshotCreateRequest : public Request<ImageCtxT> {
24 * Snap Create goes through the following state machine:
31 * STATE_SUSPEND_REQUESTS
34 * STATE_SUSPEND_AIO * * * * * * * * * * * * *
37 * STATE_APPEND_OP_EVENT (skip if journal *
40 * . . . > STATE_ALLOCATE_SNAP_ID *
43 * . . . . STATE_CREATE_SNAP * * * * * * * * * * *
46 * STATE_CREATE_OBJECT_MAP (skip if * *
50 * | STATE_RELEASE_SNAP_ID *
53 * \----------------> <finish> < * * * * *
57 * The _CREATE_STATE state may repeat back to the _ALLOCATE_SNAP_ID state
58 * if a stale snapshot context is allocated. If the create operation needs
59 * to abort, the error path is followed to record the result in the journal
60 * (if enabled) and bubble the originating error code back to the client.
62 SnapshotCreateRequest(ImageCtxT &image_ctx, Context *on_finish,
63 const cls::rbd::SnapshotNamespace &snap_namespace,
64 const std::string &snap_name,
65 uint64_t journal_op_tid,
66 bool skip_object_map);
69 void send_op() override;
70 bool should_complete(int r) override {
73 bool can_affect_io() const override {
76 journal::Event create_event(uint64_t op_tid) const override {
77 return journal::SnapCreateEvent(op_tid, m_snap_namespace, m_snap_name);
81 cls::rbd::SnapshotNamespace m_snap_namespace;
82 std::string m_snap_name;
83 bool m_skip_object_map;
89 ParentInfo m_parent_info;
91 void send_suspend_requests();
92 Context *handle_suspend_requests(int *result);
94 void send_suspend_aio();
95 Context *handle_suspend_aio(int *result);
97 void send_append_op_event();
98 Context *handle_append_op_event(int *result);
100 void send_allocate_snap_id();
101 Context *handle_allocate_snap_id(int *result);
103 void send_create_snap();
104 Context *handle_create_snap(int *result);
106 Context *send_create_object_map();
107 Context *handle_create_object_map(int *result);
109 void send_release_snap_id();
110 Context *handle_release_snap_id(int *result);
112 void update_snap_context();
114 void save_result(int *result) {
115 if (m_ret_val == 0 && *result < 0) {
121 } // namespace operation
122 } // namespace librbd
124 extern template class librbd::operation::SnapshotCreateRequest<librbd::ImageCtx>;
126 #endif // CEPH_LIBRBD_OPERATION_SNAPSHOT_CREATE_REQUEST_H