Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / io / CopyupRequest.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_IO_COPYUP_REQUEST_H
5 #define CEPH_LIBRBD_IO_COPYUP_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/rados/librados.hpp"
9 #include "include/buffer.h"
10 #include "common/zipkin_trace.h"
11 #include "librbd/io/AsyncOperation.h"
12 #include "librbd/io/Types.h"
13
14 #include <string>
15 #include <vector>
16 #include <atomic>
17
18 namespace ZTracer { struct Trace; }
19
20 namespace librbd {
21
22 struct ImageCtx;
23
24 namespace io {
25
26 struct AioCompletion;
27 template <typename I> class ObjectRequest;
28
29 class CopyupRequest {
30 public:
31   CopyupRequest(ImageCtx *ictx, const std::string &oid, uint64_t objectno,
32                 Extents &&image_extents, const ZTracer::Trace &parent_trace);
33   ~CopyupRequest();
34
35   void append_request(ObjectRequest<ImageCtx> *req);
36
37   void send();
38
39   void complete(int r);
40
41 private:
42   /**
43    * Copyup requests go through the following state machine to read from the
44    * parent image, update the object map, and copyup the object:
45    *
46    *
47    * @verbatim
48    *
49    *              <start>
50    *                 |
51    *                 v
52    *    . . .STATE_READ_FROM_PARENT. . .
53    *    . .          |                 .
54    *    . .          v                 .
55    *    . .  STATE_OBJECT_MAP_HEAD     v (copy on read /
56    *    . .          |                 .  no HEAD rev. update)
57    *    v v          v                 .
58    *    . .    STATE_OBJECT_MAP. . . . .
59    *    . .          |
60    *    . .          v
61    *    . . . . > STATE_COPYUP
62    *    .            |
63    *    .            v
64    *    . . . . > <finish>
65    *
66    * @endverbatim
67    *
68    * The _OBJECT_MAP state is skipped if the object map isn't enabled or if
69    * an object map update isn't required. The _COPYUP state is skipped if
70    * no data was read from the parent *and* there are no additional ops.
71    */
72   enum State {
73     STATE_READ_FROM_PARENT,
74     STATE_OBJECT_MAP_HEAD, // only update the HEAD revision
75     STATE_OBJECT_MAP,      // update HEAD+snaps (if any)
76     STATE_COPYUP
77   };
78
79   ImageCtx *m_ictx;
80   std::string m_oid;
81   uint64_t m_object_no;
82   Extents m_image_extents;
83   ZTracer::Trace m_trace;
84
85   State m_state;
86   ceph::bufferlist m_copyup_data;
87   std::vector<ObjectRequest<ImageCtx> *> m_pending_requests;
88   std::atomic<unsigned> m_pending_copyups { 0 };
89
90   AsyncOperation m_async_op;
91
92   std::vector<uint64_t> m_snap_ids;
93   librados::IoCtx m_data_ctx; // for empty SnapContext
94
95   void complete_requests(int r);
96
97   bool should_complete(int r);
98
99   void remove_from_list();
100
101   bool send_object_map_head();
102   bool send_object_map();
103   bool send_copyup();
104   bool is_copyup_required();
105 };
106
107 } // namespace io
108 } // namespace librbd
109
110 #endif // CEPH_LIBRBD_IO_COPYUP_REQUEST_H