Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / object_map / RefreshRequest.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_OBJECT_MAP_REFRESH_REQUEST_H
5 #define CEPH_LIBRBD_OBJECT_MAP_REFRESH_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/buffer.h"
9 #include "common/bit_vector.hpp"
10
11 class Context;
12
13 namespace librbd {
14
15 class ImageCtx;
16
17 namespace object_map {
18
19 template <typename ImageCtxT = ImageCtx>
20 class RefreshRequest {
21 public:
22   static RefreshRequest *create(ImageCtxT &image_ctx,
23                                 ceph::BitVector<2> *object_map,
24                                 uint64_t snap_id, Context *on_finish) {
25     return new RefreshRequest(image_ctx, object_map, snap_id, on_finish);
26   }
27
28   RefreshRequest(ImageCtxT &image_ctx, ceph::BitVector<2> *object_map,
29                  uint64_t snap_id, Context *on_finish);
30
31   void send();
32
33 private:
34   /**
35    * @verbatim
36    *
37    * <start> -----> LOCK (skip if snapshot)
38    *    *             |
39    *    *             v  (other errors)
40    *    *           LOAD * * * * * * * > INVALIDATE ------------\
41    *    *             |    *                                    |
42    *    *             |    * (-EINVAL or too small)             |
43    *    *             |    * * * * * * > INVALIDATE_AND_RESIZE  |
44    *    *             |                      |              *   |
45    *    *             |                      |              *   |
46    *    *             |                      v              *   |
47    *    *             |                    RESIZE           *   |
48    *    *             |                      |              *   |
49    *    *             |                      |  * * * * * * *   |
50    *    *             |                      |  *               |
51    *    *             |                      v  v               |
52    *    *             \--------------------> LOCK <-------------/
53    *    *                                     |
54    *    v                                     v
55    * INVALIDATE_AND_CLOSE ---------------> <finish>
56    *
57    * @endverbatim
58    */
59
60   ImageCtxT &m_image_ctx;
61   ceph::BitVector<2> *m_object_map;
62   uint64_t m_snap_id;
63   Context *m_on_finish;
64
65   uint64_t m_object_count;
66   ceph::BitVector<2> m_on_disk_object_map;
67   bool m_truncate_on_disk_object_map;
68   bufferlist m_out_bl;
69
70   void send_lock();
71   Context *handle_lock(int *ret_val);
72
73   void send_load();
74   Context *handle_load(int *ret_val);
75
76   void send_invalidate();
77   Context *handle_invalidate(int *ret_val);
78
79   void send_resize_invalidate();
80   Context *handle_resize_invalidate(int *ret_val);
81
82   void send_resize();
83   Context *handle_resize(int *ret_val);
84
85   void send_invalidate_and_close();
86   Context *handle_invalidate_and_close(int *ret_val);
87
88   void apply();
89 };
90
91 } // namespace object_map
92 } // namespace librbd
93
94 extern template class librbd::object_map::RefreshRequest<librbd::ImageCtx>;
95
96 #endif // CEPH_LIBRBD_OBJECT_MAP_REFRESH_REQUEST_H