]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/Operations.h
import ceph quincy 17.2.1
[ceph.git] / ceph / src / librbd / Operations.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_OPERATIONS_H
5 #define CEPH_LIBRBD_OPERATIONS_H
6
7 #include "cls/rbd/cls_rbd_types.h"
8 #include "include/int_types.h"
9 #include "librbd/exclusive_lock/Policy.h"
10 #include "librbd/operation/ObjectMapIterate.h"
11 #include <atomic>
12 #include <string>
13 #include <list>
14 #include <map>
15 #include <set>
16 #include <boost/function.hpp>
17
18 class Context;
19
20 namespace librbd {
21
22 class ImageCtx;
23 class ProgressContext;
24
25 enum Operation {
26 OPERATION_CHECK_OBJECT_MAP,
27 OPERATION_FLATTEN,
28 OPERATION_METADATA_UPDATE,
29 OPERATION_MIGRATE,
30 OPERATION_REBUILD_OBJECT_MAP,
31 OPERATION_RENAME,
32 OPERATION_RESIZE,
33 OPERATION_SNAP_CREATE,
34 OPERATION_SNAP_PROTECT,
35 OPERATION_SNAP_REMOVE,
36 OPERATION_SNAP_RENAME,
37 OPERATION_SNAP_ROLLBACK,
38 OPERATION_SNAP_UNPROTECT,
39 OPERATION_SPARSIFY,
40 OPERATION_UPDATE_FEATURES,
41 };
42
43 template <typename ImageCtxT = ImageCtx>
44 class Operations {
45 public:
46 Operations(ImageCtxT &image_ctx);
47
48 void start_op(enum Operation op, Context *ctx);
49 void finish_op(enum Operation op, int r);
50
51 int flatten(ProgressContext &prog_ctx);
52 void execute_flatten(ProgressContext &prog_ctx, Context *on_finish);
53
54 int rebuild_object_map(ProgressContext &prog_ctx);
55 void execute_rebuild_object_map(ProgressContext &prog_ctx,
56 Context *on_finish);
57
58 int check_object_map(ProgressContext &prog_ctx);
59 void check_object_map(ProgressContext &prog_ctx, Context *on_finish);
60
61 void object_map_iterate(ProgressContext &prog_ctx,
62 operation::ObjectIterateWork<ImageCtxT> handle_mismatch,
63 Context* on_finish);
64
65 int rename(const char *dstname);
66 void execute_rename(const std::string &dest_name, Context *on_finish);
67
68 int resize(uint64_t size, bool allow_shrink, ProgressContext& prog_ctx);
69 void execute_resize(uint64_t size, bool allow_shrink, ProgressContext &prog_ctx,
70 Context *on_finish, uint64_t journal_op_tid);
71
72 int snap_create(const cls::rbd::SnapshotNamespace &snap_namespace,
73 const std::string& snap_name, uint64_t flags,
74 ProgressContext& prog_ctx);
75 void snap_create(const cls::rbd::SnapshotNamespace &snap_namespace,
76 const std::string& snap_name, uint64_t flags,
77 ProgressContext& prog_ctx, Context *on_finish);
78 void execute_snap_create(const cls::rbd::SnapshotNamespace &snap_namespace,
79 const std::string &snap_name, Context *on_finish,
80 uint64_t journal_op_tid, uint64_t flags,
81 ProgressContext &prog_ctx);
82
83 int snap_rollback(const cls::rbd::SnapshotNamespace& snap_namespace,
84 const std::string& snap_name,
85 ProgressContext& prog_ctx);
86 void execute_snap_rollback(const cls::rbd::SnapshotNamespace& snap_namespace,
87 const std::string &snap_name,
88 ProgressContext& prog_ctx, Context *on_finish);
89
90 int snap_remove(const cls::rbd::SnapshotNamespace& snap_namespace,
91 const std::string& snap_name);
92 void snap_remove(const cls::rbd::SnapshotNamespace& snap_namespace,
93 const std::string& snap_name,
94 Context *on_finish);
95 void execute_snap_remove(const cls::rbd::SnapshotNamespace& snap_namespace,
96 const std::string &snap_name,
97 Context *on_finish);
98
99 int snap_rename(const char *srcname, const char *dstname);
100 void execute_snap_rename(const uint64_t src_snap_id,
101 const std::string &dest_snap_name,
102 Context *on_finish);
103
104 int snap_protect(const cls::rbd::SnapshotNamespace& snap_namespace,
105 const std::string& snap_name);
106 void execute_snap_protect(const cls::rbd::SnapshotNamespace& snap_namespace,
107 const std::string &snap_name,
108 Context *on_finish);
109
110 int snap_unprotect(const cls::rbd::SnapshotNamespace& snap_namespace,
111 const std::string& snap_name);
112 void execute_snap_unprotect(const cls::rbd::SnapshotNamespace& snap_namespace,
113 const std::string &snap_name,
114 Context *on_finish);
115
116 int snap_set_limit(uint64_t limit);
117 void execute_snap_set_limit(uint64_t limit, Context *on_finish);
118
119 int update_features(uint64_t features, bool enabled);
120 void execute_update_features(uint64_t features, bool enabled,
121 Context *on_finish, uint64_t journal_op_tid);
122
123 int metadata_set(const std::string &key, const std::string &value);
124 void execute_metadata_set(const std::string &key, const std::string &value,
125 Context *on_finish);
126
127 int metadata_remove(const std::string &key);
128 void execute_metadata_remove(const std::string &key, Context *on_finish);
129
130 int migrate(ProgressContext &prog_ctx);
131 void execute_migrate(ProgressContext &prog_ctx, Context *on_finish);
132
133 int sparsify(size_t sparse_size, ProgressContext &prog_ctx);
134 void execute_sparsify(size_t sparse_size, ProgressContext &prog_ctx,
135 Context *on_finish);
136
137 int prepare_image_update(exclusive_lock::OperationRequestType request_type,
138 bool request_lock);
139
140 private:
141 ImageCtxT &m_image_ctx;
142
143 mutable ceph::mutex m_queue_lock;
144 std::set<Operation> m_in_flight_ops;
145 std::map<Operation, std::list<Context *>> m_queued_ops;
146
147 int invoke_async_request(Operation op,
148 exclusive_lock::OperationRequestType request_type,
149 bool permit_snapshot,
150 const boost::function<void(Context*)>& local,
151 const boost::function<void(Context*)>& remote);
152 };
153
154 } // namespace librbd
155
156 extern template class librbd::Operations<librbd::ImageCtx>;
157
158 #endif // CEPH_LIBRBD_OPERATIONS_H