summaryrefslogtreecommitdiffstats
path: root/src/librbd/image/SetSnapRequest.h
blob: c12ea9f27fceb09ae173ca080f284bc21b06db11 (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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_LIBRBD_IMAGE_SNAP_SET_REQUEST_H
#define CEPH_LIBRBD_IMAGE_SNAP_SET_REQUEST_H

#include "cls/rbd/cls_rbd_client.h"
#include <string>

class Context;

namespace librbd {

template <typename> class ExclusiveLock;
class ImageCtx;
template <typename> class ObjectMap;

namespace image {

template <typename> class RefreshParentRequest;

template <typename ImageCtxT = ImageCtx>
class SetSnapRequest {
public:
  static SetSnapRequest *create(ImageCtxT &image_ctx, uint64_t snap_id,
                                Context *on_finish) {
    return new SetSnapRequest(image_ctx, snap_id, on_finish);
  }

  ~SetSnapRequest();

  void send();

private:
  /**
   * @verbatim
   *
   * <start>
   *    |
   *    | (set snap)
   *    |-----------> BLOCK_WRITES
   *    |                 |
   *    |                 v
   *    |             SHUTDOWN_EXCLUSIVE_LOCK (skip if lock inactive
   *    |                 |                    or disabled)
   *    |                 v
   *    |             REFRESH_PARENT (skip if no parent
   *    |                 |           or refresh not needed)
   *    |                 v
   *    |             OPEN_OBJECT_MAP (skip if map disabled)
   *    |                 |
   *    |                 v
   *    |              <apply>
   *    |                 |
   *    |                 v
   *    |             FINALIZE_REFRESH_PARENT (skip if no parent
   *    |                 |                    or refresh not needed)
   *    |                 v
   *    |             <finish>
   *    |
   *    \-----------> INIT_EXCLUSIVE_LOCK (skip if active or
   *                      |                disabled)
   *                      v
   *                  REFRESH_PARENT (skip if no parent
   *                      |           or refresh not needed)
   *                      v
   *                   <apply>
   *                      |
   *                      v
   *                  FINALIZE_REFRESH_PARENT (skip if no parent
   *                      |                    or refresh not needed)
   *                      v
   *                  <finish>
   *
   * @endverbatim
   */

  SetSnapRequest(ImageCtxT &image_ctx, uint64_t snap_id, Context *on_finish);

  ImageCtxT &m_image_ctx;
  uint64_t m_snap_id;
  Context *m_on_finish;

  ExclusiveLock<ImageCtxT> *m_exclusive_lock;
  ObjectMap<ImageCtxT> *m_object_map;
  RefreshParentRequest<ImageCtxT> *m_refresh_parent;

  bool m_writes_blocked;

  void send_block_writes();
  Context *handle_block_writes(int *result);

  void send_init_exclusive_lock();
  Context *handle_init_exclusive_lock(int *result);

  Context *send_shut_down_exclusive_lock(int *result);
  Context *handle_shut_down_exclusive_lock(int *result);

  Context *send_refresh_parent(int *result);
  Context *handle_refresh_parent(int *result);

  Context *send_open_object_map(int *result);
  Context *handle_open_object_map(int *result);

  Context *send_finalize_refresh_parent(int *result);
  Context *handle_finalize_refresh_parent(int *result);

  int apply();
  void finalize();
  void send_complete();
};

} // namespace image
} // namespace librbd

extern template class librbd::image::SetSnapRequest<librbd::ImageCtx>;

#endif // CEPH_LIBRBD_IMAGE_SNAP_SET_REQUEST_H