Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / tools / rbd_mirror / image_replayer / PrepareLocalImageRequest.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 RBD_MIRROR_IMAGE_REPLAYER_PREPARE_LOCAL_IMAGE_REQUEST_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_PREPARE_LOCAL_IMAGE_REQUEST_H
6
7 #include "include/buffer.h"
8 #include <string>
9
10 namespace librados { struct IoCtx; }
11 namespace librbd { struct ImageCtx; }
12
13 struct Context;
14 struct ContextWQ;
15
16 namespace rbd {
17 namespace mirror {
18 namespace image_replayer {
19
20 template <typename ImageCtxT = librbd::ImageCtx>
21 class PrepareLocalImageRequest {
22 public:
23   static PrepareLocalImageRequest *create(librados::IoCtx &io_ctx,
24                                           const std::string &global_image_id,
25                                           std::string *local_image_id,
26                                           std::string *tag_owner,
27                                           ContextWQ *work_queue,
28                                           Context *on_finish) {
29     return new PrepareLocalImageRequest(io_ctx, global_image_id, local_image_id,
30                                         tag_owner, work_queue, on_finish);
31   }
32
33   PrepareLocalImageRequest(librados::IoCtx &io_ctx,
34                            const std::string &global_image_id,
35                            std::string *local_image_id,
36                            std::string *tag_owner,
37                            ContextWQ *work_queue,
38                            Context *on_finish)
39     : m_io_ctx(io_ctx), m_global_image_id(global_image_id),
40       m_local_image_id(local_image_id), m_tag_owner(tag_owner),
41       m_work_queue(work_queue), m_on_finish(on_finish) {
42   }
43
44   void send();
45
46 private:
47   /**
48    * @verbatim
49    *
50    * <start>
51    *    |
52    *    v
53    * GET_LOCAL_IMAGE_ID
54    *    |
55    *    v
56    * GET_MIRROR_STATE
57    *    |
58    *    v
59    * <finish>
60
61    * @endverbatim
62    */
63
64   librados::IoCtx &m_io_ctx;
65   std::string m_global_image_id;
66   std::string *m_local_image_id;
67   std::string *m_tag_owner;
68   ContextWQ *m_work_queue;
69   Context *m_on_finish;
70
71   bufferlist m_out_bl;
72
73   void get_local_image_id();
74   void handle_get_local_image_id(int r);
75
76   void get_mirror_state();
77   void handle_get_mirror_state(int r);
78
79   void get_tag_owner();
80   void handle_get_tag_owner(int r);
81
82   void finish(int r);
83
84 };
85
86 } // namespace image_replayer
87 } // namespace mirror
88 } // namespace rbd
89
90 extern template class rbd::mirror::image_replayer::PrepareLocalImageRequest<librbd::ImageCtx>;
91
92 #endif // RBD_MIRROR_IMAGE_REPLAYER_PREPARE_LOCAL_IMAGE_REQUEST_H