Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / object_map / UpdateRequest.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_UPDATE_REQUEST_H
5 #define CEPH_LIBRBD_OBJECT_MAP_UPDATE_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "librbd/object_map/Request.h"
9 #include "common/bit_vector.hpp"
10 #include "common/zipkin_trace.h"
11 #include "librbd/Utils.h"
12 #include <boost/optional.hpp>
13
14 class Context;
15
16 namespace librbd {
17
18 class ImageCtx;
19
20 namespace object_map {
21
22 template <typename ImageCtxT = librbd::ImageCtx>
23 class UpdateRequest : public Request {
24 public:
25   static UpdateRequest *create(ImageCtx &image_ctx,
26                                ceph::BitVector<2> *object_map,
27                                uint64_t snap_id, uint64_t start_object_no,
28                                uint64_t end_object_no, uint8_t new_state,
29                                const boost::optional<uint8_t> &current_state,
30                                const ZTracer::Trace &parent_trace,
31                                Context *on_finish) {
32     return new UpdateRequest(image_ctx, object_map, snap_id, start_object_no,
33                              end_object_no, new_state, current_state,
34                              parent_trace, on_finish);
35   }
36
37   UpdateRequest(ImageCtx &image_ctx, ceph::BitVector<2> *object_map,
38                 uint64_t snap_id, uint64_t start_object_no,
39                 uint64_t end_object_no, uint8_t new_state,
40                 const boost::optional<uint8_t> &current_state,
41                 const ZTracer::Trace &parent_trace, Context *on_finish)
42     : Request(image_ctx, snap_id, on_finish), m_object_map(*object_map),
43       m_start_object_no(start_object_no), m_end_object_no(end_object_no),
44       m_update_start_object_no(start_object_no), m_new_state(new_state),
45       m_current_state(current_state),
46       m_trace(util::create_trace(image_ctx, "update object map", parent_trace))
47   {
48     m_trace.event("start");
49   }
50   virtual ~UpdateRequest() {
51     m_trace.event("finish");
52   }
53
54   void send() override;
55
56 protected:
57   void finish_request() override;
58
59 private:
60   /**
61    * @verbatim
62    *
63    * <start>
64    *    |
65    *    |/------------------\
66    *    v                   | (repeat in batches)
67    * UPDATE_OBJECT_MAP -----/
68    *    |
69    *    v
70    * <finish>
71    *
72    * @endverbatim
73    */
74
75   ceph::BitVector<2> &m_object_map;
76   uint64_t m_start_object_no;
77   uint64_t m_end_object_no;
78   uint64_t m_update_start_object_no;
79   uint64_t m_update_end_object_no = 0;
80   uint8_t m_new_state;
81   boost::optional<uint8_t> m_current_state;
82   ZTracer::Trace m_trace;
83
84   void update_object_map();
85   void handle_update_object_map(int r);
86
87   void update_in_memory_object_map();
88
89 };
90
91 } // namespace object_map
92 } // namespace librbd
93
94 extern template class librbd::object_map::UpdateRequest<librbd::ImageCtx>;
95
96 #endif // CEPH_LIBRBD_OBJECT_MAP_UPDATE_REQUEST_H