Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / operation / FlattenRequest.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_FLATTEN_REQUEST_H
4 #define CEPH_LIBRBD_OPERATION_FLATTEN_REQUEST_H
5
6 #include "librbd/operation/Request.h"
7 #include "common/snap_types.h"
8 #include "librbd/Types.h"
9
10 namespace librbd {
11
12 class ImageCtx;
13 class ProgressContext;
14
15 namespace operation {
16
17 template <typename ImageCtxT = ImageCtx>
18 class FlattenRequest : public Request<ImageCtxT>
19 {
20 public:
21   FlattenRequest(ImageCtxT &image_ctx, Context *on_finish,
22                  uint64_t object_size, uint64_t overlap_objects,
23                  const ::SnapContext &snapc, ProgressContext &prog_ctx)
24     : Request<ImageCtxT>(image_ctx, on_finish), m_object_size(object_size),
25       m_overlap_objects(overlap_objects), m_snapc(snapc), m_prog_ctx(prog_ctx),
26       m_ignore_enoent(false)
27   {
28   }
29
30 protected:
31   void send_op() override;
32   bool should_complete(int r) override;
33
34   journal::Event create_event(uint64_t op_tid) const override {
35     return journal::FlattenEvent(op_tid);
36   }
37
38 private:
39   /**
40    * Flatten goes through the following state machine to copyup objects
41    * from the parent image:
42    *
43    * @verbatim
44    *
45    * <start>
46    *    |
47    *    v
48    * STATE_FLATTEN_OBJECTS ---> STATE_UPDATE_HEADER . . . . .
49    *           .                         |                  .
50    *           .                         |                  .
51    *           .                         v                  .
52    *           .               STATE_UPDATE_CHILDREN        .
53    *           .                         |                  .
54    *           .                         |                  .
55    *           .                         \---> <finish> < . .
56    *           .                                   ^
57    *           .                                   .
58    *           . . . . . . . . . . . . . . . . . . .
59    *
60    * @endverbatim
61    *
62    * The _UPDATE_CHILDREN state will be skipped if the image has one or
63    * more snapshots. The _UPDATE_HEADER state will be skipped if the
64    * image was concurrently flattened by another client.
65    */
66   enum State {
67     STATE_FLATTEN_OBJECTS,
68     STATE_UPDATE_HEADER,
69     STATE_UPDATE_CHILDREN
70   };
71
72   uint64_t m_object_size;
73   uint64_t m_overlap_objects;
74   ::SnapContext m_snapc;
75   ProgressContext &m_prog_ctx;
76   State m_state;
77
78   ParentSpec m_parent_spec;
79   bool m_ignore_enoent;
80
81   bool send_update_header();
82   bool send_update_children();
83 };
84
85 } // namespace operation
86 } // namespace librbd
87
88 extern template class librbd::operation::FlattenRequest<librbd::ImageCtx>;
89
90 #endif // CEPH_LIBRBD_OPERATION_FLATTEN_REQUEST_H