summaryrefslogtreecommitdiffstats
path: root/src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.h
blob: fc776ecc30117ac1268f6b7688ad270dd7356199 (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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef RBD_MIRROR_IMAGE_REPLAYER_JOURNAL_CREATE_LOCAL_IMAGE_REQUEST_H
#define RBD_MIRROR_IMAGE_REPLAYER_JOURNAL_CREATE_LOCAL_IMAGE_REQUEST_H

#include "include/rados/librados_fwd.hpp"
#include "tools/rbd_mirror/BaseRequest.h"
#include <string>

struct Context;
namespace journal { class Journaler; }
namespace librbd { class ImageCtx; }

namespace rbd {
namespace mirror {

class PoolMetaCache;
class ProgressContext;
template <typename> struct Threads;

namespace image_replayer {
namespace journal {

template <typename> class StateBuilder;

template <typename ImageCtxT>
class CreateLocalImageRequest : public BaseRequest {
public:
  typedef rbd::mirror::ProgressContext ProgressContext;

  static CreateLocalImageRequest* create(
      Threads<ImageCtxT>* threads,
      librados::IoCtx& local_io_ctx,
      ImageCtxT* remote_image_ctx,
      const std::string& global_image_id,
      PoolMetaCache* pool_meta_cache,
      ProgressContext* progress_ctx,
      StateBuilder<ImageCtxT>* state_builder,
      Context* on_finish) {
    return new CreateLocalImageRequest(threads, local_io_ctx, remote_image_ctx,
                                       global_image_id, pool_meta_cache,
                                       progress_ctx, state_builder, on_finish);
  }

  CreateLocalImageRequest(
      Threads<ImageCtxT>* threads,
      librados::IoCtx& local_io_ctx,
      ImageCtxT* remote_image_ctx,
      const std::string& global_image_id,
      PoolMetaCache* pool_meta_cache,
      ProgressContext* progress_ctx,
      StateBuilder<ImageCtxT>* state_builder,
      Context* on_finish)
    : BaseRequest(on_finish),
      m_threads(threads),
      m_local_io_ctx(local_io_ctx),
      m_remote_image_ctx(remote_image_ctx),
      m_global_image_id(global_image_id),
      m_pool_meta_cache(pool_meta_cache),
      m_progress_ctx(progress_ctx),
      m_state_builder(state_builder) {
  }

  void send();

private:
  /**
   * @verbatim
   *
   * <start>
   *    |
   *    v
   * UNREGISTER_CLIENT  < * * * * * * * *
   *    |                               *
   *    v                               *
   * REGISTER_CLIENT                    *
   *    |                               *
   *    v               (id exists)     *
   * CREATE_LOCAL_IMAGE * * * * * * * * *
   *    |
   *    v
   * <finish>
   *
   * @endverbatim
   */

  Threads<ImageCtxT>* m_threads;
  librados::IoCtx& m_local_io_ctx;
  ImageCtxT* m_remote_image_ctx;
  std::string m_global_image_id;
  PoolMetaCache* m_pool_meta_cache;
  ProgressContext* m_progress_ctx;
  StateBuilder<ImageCtxT>* m_state_builder;

  void unregister_client();
  void handle_unregister_client(int r);

  void register_client();
  void handle_register_client(int r);

  void create_local_image();
  void handle_create_local_image(int r);

  void update_progress(const std::string& description);

};

} // namespace journal
} // namespace image_replayer
} // namespace mirror
} // namespace rbd

extern template class rbd::mirror::image_replayer::journal::CreateLocalImageRequest<librbd::ImageCtx>;

#endif // RBD_MIRROR_IMAGE_REPLAYER_JOURNAL_CREATE_LOCAL_IMAGE_REQUEST_H