Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / tools / rbd_mirror / image_sync / ImageCopyRequest.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_SYNC_IMAGE_COPY_REQUEST_H
5 #define RBD_MIRROR_IMAGE_SYNC_IMAGE_COPY_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/rados/librados.hpp"
9 #include "common/Mutex.h"
10 #include "librbd/journal/Types.h"
11 #include "librbd/journal/TypeTraits.h"
12 #include "tools/rbd_mirror/BaseRequest.h"
13 #include <map>
14 #include <vector>
15
16 class Context;
17 class SafeTimer;
18 namespace journal { class Journaler; }
19 namespace librbd { struct ImageCtx; }
20
21 namespace rbd {
22 namespace mirror {
23
24 class ProgressContext;
25
26 namespace image_sync {
27
28 template <typename ImageCtxT = librbd::ImageCtx>
29 class ImageCopyRequest : public BaseRequest {
30 public:
31   typedef std::vector<librados::snap_t> SnapIds;
32   typedef std::map<librados::snap_t, SnapIds> SnapMap;
33   typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
34   typedef typename TypeTraits::Journaler Journaler;
35   typedef librbd::journal::MirrorPeerSyncPoint MirrorPeerSyncPoint;
36   typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
37   typedef rbd::mirror::ProgressContext ProgressContext;
38
39   static ImageCopyRequest* create(ImageCtxT *local_image_ctx,
40                                   ImageCtxT *remote_image_ctx,
41                                   SafeTimer *timer, Mutex *timer_lock,
42                                   Journaler *journaler,
43                                   MirrorPeerClientMeta *client_meta,
44                                   MirrorPeerSyncPoint *sync_point,
45                                   Context *on_finish,
46                                   ProgressContext *progress_ctx = nullptr) {
47     return new ImageCopyRequest(local_image_ctx, remote_image_ctx, timer,
48                                 timer_lock, journaler, client_meta, sync_point,
49                                 on_finish, progress_ctx);
50   }
51
52   ImageCopyRequest(ImageCtxT *local_image_ctx, ImageCtxT *remote_image_ctx,
53                    SafeTimer *timer, Mutex *timer_lock, Journaler *journaler,
54                    MirrorPeerClientMeta *client_meta,
55                    MirrorPeerSyncPoint *sync_point, Context *on_finish,
56                    ProgressContext *progress_ctx = nullptr);
57
58   void send() override;
59   void cancel() override;
60
61 private:
62   /**
63    * @verbatim
64    *
65    * <start>
66    *    |
67    *    v
68    * UPDATE_MAX_OBJECT_COUNT
69    *    |
70    *    |   . . . . .
71    *    |   .       .  (parallel execution of
72    *    v   v       .   multiple objects at once)
73    * COPY_OBJECT  . .
74    *    |
75    *    v
76    * FLUSH_SYNC_POINT
77    *    |
78    *    v
79    * <finish>
80    *
81    * @endverbatim
82    */
83
84   ImageCtxT *m_local_image_ctx;
85   ImageCtxT *m_remote_image_ctx;
86   SafeTimer *m_timer;
87   Mutex *m_timer_lock;
88   Journaler *m_journaler;
89   MirrorPeerClientMeta *m_client_meta;
90   MirrorPeerSyncPoint *m_sync_point;
91   ProgressContext *m_progress_ctx;
92
93   SnapMap m_snap_map;
94
95   Mutex m_lock;
96   bool m_canceled = false;
97
98   uint64_t m_object_no = 0;
99   uint64_t m_end_object_no;
100   uint64_t m_current_ops = 0;
101   int m_ret_val = 0;
102
103   bool m_updating_sync_point;
104   Context *m_update_sync_ctx;
105   double m_update_sync_point_interval;
106
107   MirrorPeerClientMeta m_client_meta_copy;
108
109   void send_update_max_object_count();
110   void handle_update_max_object_count(int r);
111
112   void send_object_copies();
113   void send_next_object_copy();
114   void handle_object_copy(int r);
115
116   void send_update_sync_point();
117   void handle_update_sync_point(int r);
118
119   void send_flush_sync_point();
120   void handle_flush_sync_point(int r);
121
122   int compute_snap_map();
123
124   void update_progress(const std::string &description, bool flush = true);
125 };
126
127 } // namespace image_sync
128 } // namespace mirror
129 } // namespace rbd
130
131 extern template class rbd::mirror::image_sync::ImageCopyRequest<librbd::ImageCtx>;
132
133 #endif // RBD_MIRROR_IMAGE_SYNC_IMAGE_COPY_REQUEST_H