Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / tools / rbd_mirror / image_sync / SyncPointPruneRequest.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_SYNC_POINT_PRUNE_REQUEST_H
5 #define RBD_MIRROR_IMAGE_SYNC_SYNC_POINT_PRUNE_REQUEST_H
6
7 #include "librbd/journal/Types.h"
8 #include "librbd/journal/TypeTraits.h"
9 #include <list>
10 #include <string>
11
12 class Context;
13 namespace journal { class Journaler; }
14 namespace librbd { class ImageCtx; }
15 namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
16
17 namespace rbd {
18 namespace mirror {
19 namespace image_sync {
20
21 template <typename ImageCtxT = librbd::ImageCtx>
22 class SyncPointPruneRequest {
23 public:
24   typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
25   typedef typename TypeTraits::Journaler Journaler;
26   typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
27   typedef librbd::journal::MirrorPeerSyncPoint MirrorPeerSyncPoint;
28
29   static SyncPointPruneRequest* create(ImageCtxT *remote_image_ctx,
30                                        bool sync_complete,
31                                        Journaler *journaler,
32                                        MirrorPeerClientMeta *client_meta,
33                                        Context *on_finish) {
34     return new SyncPointPruneRequest(remote_image_ctx, sync_complete, journaler,
35                                       client_meta, on_finish);
36   }
37
38   SyncPointPruneRequest(ImageCtxT *remote_image_ctx, bool sync_complete,
39                         Journaler *journaler, MirrorPeerClientMeta *client_meta,
40                         Context *on_finish);
41
42   void send();
43
44 private:
45   /**
46    * @verbatim
47    *
48    * <start>
49    *    |
50    *    |    . . . . .
51    *    |    .       .
52    *    v    v       . (repeat if from snap
53    * REMOVE_SNAP . . .  unused by other sync)
54    *    |
55    *    v
56    * REFRESH_IMAGE
57    *    |
58    *    v
59    * UPDATE_CLIENT
60    *    |
61    *    v
62    * <finish>
63    *
64    * @endverbatim
65    */
66
67   ImageCtxT *m_remote_image_ctx;
68   bool m_sync_complete;
69   Journaler *m_journaler;
70   MirrorPeerClientMeta *m_client_meta;
71   Context *m_on_finish;
72
73   MirrorPeerClientMeta m_client_meta_copy;
74   std::list<std::string> m_snap_names;
75
76   bool m_invalid_master_sync_point = false;
77
78   void send_remove_snap();
79   void handle_remove_snap(int r);
80
81   void send_refresh_image();
82   void handle_refresh_image(int r);
83
84   void send_update_client();
85   void handle_update_client(int r);
86
87   void finish(int r);
88 };
89
90 } // namespace image_sync
91 } // namespace mirror
92 } // namespace rbd
93
94 extern template class rbd::mirror::image_sync::SyncPointPruneRequest<librbd::ImageCtx>;
95
96 #endif // RBD_MIRROR_IMAGE_SYNC_SYNC_POINT_PRUNE_REQUEST_H