Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / tools / rbd_mirror / image_replayer / OpenLocalImageRequest.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_OPEN_LOCAL_IMAGE_REQUEST_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_OPEN_LOCAL_IMAGE_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "librbd/ImageCtx.h"
9 #include <string>
10
11 class Context;
12 class ContextWQ;
13 namespace librbd { class ImageCtx; }
14
15 namespace rbd {
16 namespace mirror {
17 namespace image_replayer {
18
19 template <typename ImageCtxT = librbd::ImageCtx>
20 class OpenLocalImageRequest {
21 public:
22   static OpenLocalImageRequest* create(librados::IoCtx &local_io_ctx,
23                                        ImageCtxT **local_image_ctx,
24                                        const std::string &local_image_id,
25                                        ContextWQ *work_queue,
26                                        Context *on_finish) {
27     return new OpenLocalImageRequest(local_io_ctx, local_image_ctx,
28                                      local_image_id, work_queue, on_finish);
29   }
30
31   OpenLocalImageRequest(librados::IoCtx &local_io_ctx,
32                         ImageCtxT **local_image_ctx,
33                         const std::string &local_image_id,
34                         ContextWQ *m_work_queue,
35                         Context *on_finish);
36
37   void send();
38
39 private:
40   /**
41    * @verbatim
42    *
43    * <start>
44    *    |
45    *    v
46    * OPEN_IMAGE * * * * * * * *
47    *    |                     *
48    *    v                     *
49    * IS_PRIMARY * * * * * * * *
50    *    |                     *
51    *    v (skip if primary)   v
52    * LOCK_IMAGE * * * > CLOSE_IMAGE
53    *    |                     |
54    *    v                     |
55    * <finish> <---------------/
56    *
57    * @endverbatim
58    */
59   librados::IoCtx &m_local_io_ctx;
60   ImageCtxT **m_local_image_ctx;
61   std::string m_local_image_id;
62   ContextWQ *m_work_queue;
63   Context *m_on_finish;
64
65   bool m_primary = false;
66   int m_ret_val = 0;
67
68   void send_open_image();
69   void handle_open_image(int r);
70
71   void send_is_primary();
72   void handle_is_primary(int r);
73
74   void send_lock_image();
75   void handle_lock_image(int r);
76
77   void send_close_image(int r);
78   void handle_close_image(int r);
79
80   void finish(int r);
81
82 };
83
84 } // namespace image_replayer
85 } // namespace mirror
86 } // namespace rbd
87
88 extern template class rbd::mirror::image_replayer::OpenLocalImageRequest<librbd::ImageCtx>;
89
90 #endif // RBD_MIRROR_IMAGE_REPLAYER_OPEN_LOCAL_IMAGE_REQUEST_H