]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/migration/OpenSourceImageRequest.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / migration / OpenSourceImageRequest.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_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H
5 #define CEPH_LIBRBD_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H
6
7 #include "include/rados/librados_fwd.hpp"
8 #include "librbd/Types.h"
9 #include <map>
10 #include <memory>
11
12 struct Context;
13
14 namespace librbd {
15
16 struct ImageCtx;
17
18 namespace migration {
19
20 struct FormatInterface;
21
22 template <typename ImageCtxT>
23 class OpenSourceImageRequest {
24 public:
25 static OpenSourceImageRequest* create(librados::IoCtx& io_ctx,
26 ImageCtxT* destination_image_ctx,
27 uint64_t src_snap_id,
28 const MigrationInfo &migration_info,
29 ImageCtxT** source_image_ctx,
30 Context* on_finish) {
31 return new OpenSourceImageRequest(io_ctx, destination_image_ctx,
32 src_snap_id, migration_info,
33 source_image_ctx, on_finish);
34 }
35
36 OpenSourceImageRequest(librados::IoCtx& io_ctx,
37 ImageCtxT* destination_image_ctx,
38 uint64_t src_snap_id,
39 const MigrationInfo &migration_info,
40 ImageCtxT** source_image_ctx,
41 Context* on_finish);
42
43 void send();
44
45 private:
46 /**
47 * @verbatim
48 *
49 * <start>
50 * |
51 * v
52 * OPEN_SOURCE
53 * |
54 * v
55 * GET_IMAGE_SIZE * * * * * * *
56 * | *
57 * v v
58 * GET_SNAPSHOTS * * * * > CLOSE_IMAGE
59 * | |
60 * v |
61 * <finish> <------------------/
62 *
63 * @endverbatim
64 */
65
66 typedef std::map<uint64_t, SnapInfo> SnapInfos;
67
68 CephContext* m_cct;
69 librados::IoCtx& m_io_ctx;
70 ImageCtxT* m_dst_image_ctx;
71 uint64_t m_src_snap_id;
72 MigrationInfo m_migration_info;
73 ImageCtxT** m_src_image_ctx;
74 Context* m_on_finish;
75
76 std::unique_ptr<FormatInterface> m_format;
77
78 uint64_t m_image_size = 0;
79 SnapInfos m_snap_infos;
80
81 void open_source();
82 void handle_open_source(int r);
83
84 void get_image_size();
85 void handle_get_image_size(int r);
86
87 void get_snapshots();
88 void handle_get_snapshots(int r);
89
90 void close_image(int r);
91
92 void register_image_dispatch();
93
94 void finish(int r);
95
96 };
97
98 } // namespace migration
99 } // namespace librbd
100
101 extern template class librbd::migration::OpenSourceImageRequest<librbd::ImageCtx>;
102
103 #endif // CEPH_LIBRBD_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H