Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / operation / RebuildObjectMapRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_LIBRBD_OPERATION_REBUILD_OBJECT_MAP_REQUEST_H
4 #define CEPH_LIBRBD_OPERATION_REBUILD_OBJECT_MAP_REQUEST_H
5
6 #include "include/int_types.h"
7 #include "librbd/AsyncRequest.h"
8
9 namespace librbd {
10
11 class ImageCtx;
12 class ProgressContext;
13
14 namespace operation {
15
16 template <typename ImageCtxT = ImageCtx>
17 class RebuildObjectMapRequest : public AsyncRequest<ImageCtxT> {
18 public:
19
20   RebuildObjectMapRequest(ImageCtxT &image_ctx, Context *on_finish,
21                           ProgressContext &prog_ctx)
22     : AsyncRequest<ImageCtxT>(image_ctx, on_finish), m_image_ctx(image_ctx),
23       m_prog_ctx(prog_ctx), m_attempted_trim(false)
24   {
25   }
26
27   void send() override;
28
29 protected:
30   bool should_complete(int r) override;
31
32 private:
33   /**
34    * Rebuild object map goes through the following state machine to
35    * verify per-object state:
36    *
37    * <start>
38    *  .   |               . . . . . . . . . .
39    *  .   |               .                 .
40    *  .   v               v                 .
41    *  . STATE_RESIZE_OBJECT_MAP . . . > STATE_TRIM_IMAGE
42    *  .          |
43    *  .          v
44    *  . . . > STATE_VERIFY_OBJECTS
45    *             |
46    *             v
47    *          STATE_SAVE_OBJECT_MAP
48    *             |
49    *             v
50    *          STATE_UPDATE_HEADER
51    *
52    * The _RESIZE_OBJECT_MAP state will be skipped if the object map
53    * is appropriately sized for the image. The _TRIM_IMAGE state will
54    * only be hit if the resize failed due to an in-use object.
55    */
56   enum State {
57     STATE_RESIZE_OBJECT_MAP,
58     STATE_TRIM_IMAGE,
59     STATE_VERIFY_OBJECTS,
60     STATE_SAVE_OBJECT_MAP,
61     STATE_UPDATE_HEADER
62   };
63
64   ImageCtxT &m_image_ctx;
65   ProgressContext &m_prog_ctx;
66   State m_state;
67   bool m_attempted_trim;
68
69   void send_resize_object_map();
70   void send_trim_image();
71   void send_verify_objects();
72   void send_save_object_map();
73   void send_update_header();
74
75   uint64_t get_image_size() const;
76
77 };
78
79 } // namespace operation
80 } // namespace librbd
81
82 extern template class librbd::operation::RebuildObjectMapRequest<librbd::ImageCtx>;
83
84 #endif // CEPH_LIBRBD_OPERATION_REBUILD_OBJECT_MAP_REQUEST_H