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

#ifndef CEPH_LIBRBD_MIRROR_GET_INFO_REQUEST_H
#define CEPH_LIBRBD_MIRROR_GET_INFO_REQUEST_H

#include "common/snap_types.h"
#include "include/buffer.h"
#include "include/common_fwd.h"
#include "include/rados/librados.hpp"
#include "librbd/Types.h"
#include "librbd/mirror/Types.h"
#include <string>

struct Context;

namespace cls { namespace rbd { struct MirrorImage; } }

namespace librbd {

struct ImageCtx;
namespace asio { struct ContextWQ; }

namespace mirror {

template <typename ImageCtxT = librbd::ImageCtx>
class GetInfoRequest {
public:
  static GetInfoRequest *create(librados::IoCtx &io_ctx,
                                asio::ContextWQ *op_work_queue,
                                const std::string &image_id,
                                cls::rbd::MirrorImage *mirror_image,
                                PromotionState *promotion_state,
                                std::string* primary_mirror_uuid,
                                Context *on_finish) {
    return new GetInfoRequest(io_ctx, op_work_queue, image_id, mirror_image,
                              promotion_state, primary_mirror_uuid, on_finish);
  }
  static GetInfoRequest *create(ImageCtxT &image_ctx,
                                cls::rbd::MirrorImage *mirror_image,
                                PromotionState *promotion_state,
                                std::string* primary_mirror_uuid,
                                Context *on_finish) {
    return new GetInfoRequest(image_ctx, mirror_image, promotion_state,
                              primary_mirror_uuid, on_finish);
  }

  GetInfoRequest(librados::IoCtx& io_ctx, asio::ContextWQ *op_work_queue,
                 const std::string &image_id,
                 cls::rbd::MirrorImage *mirror_image,
                 PromotionState *promotion_state,
                 std::string* primary_mirror_uuid, Context *on_finish);
  GetInfoRequest(ImageCtxT &image_ctx, cls::rbd::MirrorImage *mirror_image,
                 PromotionState *promotion_state,
                 std::string* primary_mirror_uuid, Context *on_finish);

  void send();

private:
  /**
   * @verbatim
   *
   *                  <start>
   *                     |
   *                     v
   *              GET_MIRROR_IMAGE
   *                     |
   *  (journal /--------/ \--------\ (snapshot
   *   mode)   |                   |  mode)
   *           v                   v
   *  GET_JOURNAL_TAG_OWNER    GET_SNAPCONTEXT (skip if
   *           |                   |            cached)
   *           |                   v
   *           |               GET_SNAPSHOTS (skip if
   *           |                   |          cached)
   *           \--------\ /--------/
   *                     |
   *                     v
   *                  <finish>
   *
   * @endverbatim
   */

  ImageCtxT *m_image_ctx = nullptr;
  librados::IoCtx &m_io_ctx;
  asio::ContextWQ *m_op_work_queue;
  std::string m_image_id;
  cls::rbd::MirrorImage *m_mirror_image;
  PromotionState *m_promotion_state;
  std::string* m_primary_mirror_uuid;
  Context *m_on_finish;

  CephContext *m_cct;

  bufferlist m_out_bl;
  std::string m_mirror_uuid;
  ::SnapContext m_snapc;

  void get_mirror_image();
  void handle_get_mirror_image(int r);

  void get_journal_tag_owner();
  void handle_get_journal_tag_owner(int r);

  void get_snapcontext();
  void handle_get_snapcontext(int r);

  void get_snapshots();
  void handle_get_snapshots(int r);

  void finish(int r);

  void calc_promotion_state(
    const std::map<librados::snap_t, SnapInfo> &snap_info);
};

} // namespace mirror
} // namespace librbd

extern template class librbd::mirror::GetInfoRequest<librbd::ImageCtx>;

#endif // CEPH_LIBRBD_MIRROR_GET_INFO_REQUEST_H