Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / image / RefreshParentRequest.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 CEPH_LIBRBD_IMAGE_REFRESH_PARENT_REQUEST_H
5 #define CEPH_LIBRBD_IMAGE_REFRESH_PARENT_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "librbd/Types.h"
9
10 class Context;
11
12 namespace librbd {
13
14 class ImageCtx;
15
16 namespace image {
17
18 template <typename ImageCtxT = ImageCtx>
19 class RefreshParentRequest {
20 public:
21   static RefreshParentRequest *create(ImageCtxT &child_image_ctx,
22                                       const ParentInfo &parent_md,
23                                       Context *on_finish) {
24     return new RefreshParentRequest(child_image_ctx, parent_md, on_finish);
25   }
26
27   static bool is_refresh_required(ImageCtxT &child_image_ctx,
28                                   const ParentInfo &parent_md);
29
30   void send();
31   void apply();
32   void finalize(Context *on_finish);
33
34 private:
35   /**
36    * @verbatim
37    *
38    * <start>
39    *    |
40    *    | (open required)
41    *    |----------------> OPEN_PARENT * * * * * * * * * * * * * * *
42    *    |                     |                                    *
43    *    |                     v                                    *
44    *    |                  SET_PARENT_SNAP * * * * * *             *
45    *    |                     |                      *             *
46    *    |                     v                      * (on error)  *
47    *    \----------------> <apply>                   *             *
48    *                          |                      *             *
49    *                          | (close required)     v             *
50    *                          |-----------------> CLOSE_PARENT     *
51    *                          |                      |             *
52    *                          |                      v             *
53    *                          \-----------------> <finish> < * * * *
54    *
55    * @endverbatim
56    */
57
58   RefreshParentRequest(ImageCtxT &child_image_ctx, const ParentInfo &parent_md,
59                        Context *on_finish);
60
61   ImageCtxT &m_child_image_ctx;
62   ParentInfo m_parent_md;
63   Context *m_on_finish;
64
65   ImageCtxT *m_parent_image_ctx;
66   uint64_t m_parent_snap_id;
67
68   int m_error_result;
69
70   static bool is_close_required(ImageCtxT &child_image_ctx,
71                                 const ParentInfo &parent_md);
72   static bool is_open_required(ImageCtxT &child_image_ctx,
73                                const ParentInfo &parent_md);
74
75   void send_open_parent();
76   Context *handle_open_parent(int *result);
77
78   void send_set_parent_snap();
79   Context *handle_set_parent_snap(int *result);
80
81   void send_close_parent();
82   Context *handle_close_parent(int *result);
83
84   void send_complete(int r);
85
86   void save_result(int *result) {
87     if (m_error_result == 0 && *result < 0) {
88       m_error_result = *result;
89     }
90   }
91
92 };
93
94 } // namespace image
95 } // namespace librbd
96
97 extern template class librbd::image::RefreshParentRequest<librbd::ImageCtx>;
98
99 #endif // CEPH_LIBRBD_IMAGE_REFRESH_PARENT_REQUEST_H