summaryrefslogtreecommitdiffstats
path: root/src/librbd/operation/SnapshotRollbackRequest.h
blob: e58a618f2ecf47c6da19d48df7c6bf9f24663f6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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