1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_LIBRBD_OPERATIONS_H
5 #define CEPH_LIBRBD_OPERATIONS_H
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"
16 #include <boost/function.hpp>
23 class ProgressContext
;
26 OPERATION_CHECK_OBJECT_MAP
,
28 OPERATION_METADATA_UPDATE
,
30 OPERATION_REBUILD_OBJECT_MAP
,
33 OPERATION_SNAP_CREATE
,
34 OPERATION_SNAP_PROTECT
,
35 OPERATION_SNAP_REMOVE
,
36 OPERATION_SNAP_RENAME
,
37 OPERATION_SNAP_ROLLBACK
,
38 OPERATION_SNAP_UNPROTECT
,
40 OPERATION_UPDATE_FEATURES
,
43 template <typename ImageCtxT
= ImageCtx
>
46 Operations(ImageCtxT
&image_ctx
);
48 void start_op(enum Operation op
, Context
*ctx
);
49 void finish_op(enum Operation op
, int r
);
51 int flatten(ProgressContext
&prog_ctx
);
52 void execute_flatten(ProgressContext
&prog_ctx
, Context
*on_finish
);
54 int rebuild_object_map(ProgressContext
&prog_ctx
);
55 void execute_rebuild_object_map(ProgressContext
&prog_ctx
,
58 int check_object_map(ProgressContext
&prog_ctx
);
59 void check_object_map(ProgressContext
&prog_ctx
, Context
*on_finish
);
61 void object_map_iterate(ProgressContext
&prog_ctx
,
62 operation::ObjectIterateWork
<ImageCtxT
> handle_mismatch
,
65 int rename(const char *dstname
);
66 void execute_rename(const std::string
&dest_name
, Context
*on_finish
);
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
);
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
);
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
);
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
,
95 void execute_snap_remove(const cls::rbd::SnapshotNamespace
& snap_namespace
,
96 const std::string
&snap_name
,
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
,
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
,
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
,
116 int snap_set_limit(uint64_t limit
);
117 void execute_snap_set_limit(uint64_t limit
, Context
*on_finish
);
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
);
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
,
127 int metadata_remove(const std::string
&key
);
128 void execute_metadata_remove(const std::string
&key
, Context
*on_finish
);
130 int migrate(ProgressContext
&prog_ctx
);
131 void execute_migrate(ProgressContext
&prog_ctx
, Context
*on_finish
);
133 int sparsify(size_t sparse_size
, ProgressContext
&prog_ctx
);
134 void execute_sparsify(size_t sparse_size
, ProgressContext
&prog_ctx
,
137 int prepare_image_update(exclusive_lock::OperationRequestType request_type
,
141 ImageCtxT
&m_image_ctx
;
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
;
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
);
154 } // namespace librbd
156 extern template class librbd::Operations
<librbd::ImageCtx
>;
158 #endif // CEPH_LIBRBD_OPERATIONS_H