]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/object_map/SnapshotRemoveRequest.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / librbd / object_map / SnapshotRemoveRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_REMOVE_REQUEST_H
5 #define CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_REMOVE_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/buffer.h"
9 #include "common/bit_vector.hpp"
10 #include "librbd/AsyncRequest.h"
11
12 namespace librbd {
13 namespace object_map {
14
15 class SnapshotRemoveRequest : public AsyncRequest<> {
16 public:
17 /**
18 * Snapshot rollback goes through the following state machine:
19 *
20 * @verbatim
21 *
22 * <start> -----------> STATE_LOAD_MAP ----\
23 * . * |
24 * . * (error) |
25 * . (invalid object map) v |
26 * . . . > STATE_INVALIDATE_NEXT_MAP |
27 * . | |
28 * . | |
29 * . (fast diff disabled) v v
30 * . . . . . . . . . . > STATE_REMOVE_MAP
31 * |
32 * v
33 * <finish>
34 *
35 * @endverbatim
36 *
37 * The _LOAD_MAP state is skipped if the fast diff feature is disabled.
38 * If the fast diff feature is enabled and the snapshot is flagged as
39 * invalid, the next snapshot / HEAD object mapis flagged as invalid;
40 * otherwise, the state machine proceeds to remove the object map.
41 */
42 enum State {
43 STATE_LOAD_MAP,
44 STATE_REMOVE_SNAPSHOT,
45 STATE_INVALIDATE_NEXT_MAP,
46 STATE_REMOVE_MAP
47 };
48
49 SnapshotRemoveRequest(ImageCtx &image_ctx, ceph::BitVector<2> *object_map,
50 uint64_t snap_id, Context *on_finish)
51 : AsyncRequest(image_ctx, on_finish), m_object_map(*object_map),
52 m_snap_id(snap_id), m_next_snap_id(CEPH_NOSNAP) {
53 }
54
55 void send() override;
56
57 protected:
58 bool should_complete(int r) override;
59
60 int filter_return_code(int r) const override {
61 if ((m_state == STATE_LOAD_MAP || m_state == STATE_REMOVE_MAP) &&
62 r == -ENOENT) {
63 return 0;
64 }
65 return r;
66 }
67
68 private:
69 State m_state;
70 ceph::BitVector<2> &m_object_map;
71 uint64_t m_snap_id;
72 uint64_t m_next_snap_id;
73
74 ceph::BitVector<2> m_snap_object_map;
75 bufferlist m_out_bl;
76
77 void send_load_map();
78 void send_remove_snapshot();
79 void send_invalidate_next_map();
80 void send_remove_map();
81
82 void compute_next_snap_id();
83 void update_object_map();
84 };
85
86 } // namespace object_map
87 } // namespace librbd
88
89 #endif // CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_REMOVE_REQUEST_H