]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_OBJECT_MAP_ITERATE_H | |
4 | #define CEPH_LIBRBD_OPERATION_OBJECT_MAP_ITERATE_H | |
5 | ||
6 | #include <iostream> | |
7 | #include <atomic> | |
8 | ||
9 | #include "include/int_types.h" | |
10 | #include "include/rbd/object_map_types.h" | |
11 | #include "librbd/AsyncRequest.h" | |
12 | ||
13 | namespace librbd { | |
14 | ||
15 | class ImageCtx; | |
16 | class ProgressContext; | |
17 | ||
18 | namespace operation { | |
19 | ||
20 | template <typename ImageCtxT = ImageCtx> | |
21 | using ObjectIterateWork = bool(*)(ImageCtxT &image_ctx, | |
22 | uint64_t object_no, | |
23 | uint8_t current_state, | |
24 | uint8_t new_state); | |
25 | ||
26 | template <typename ImageCtxT = ImageCtx> | |
27 | class ObjectMapIterateRequest : public AsyncRequest<ImageCtxT> { | |
28 | public: | |
29 | ObjectMapIterateRequest(ImageCtxT &image_ctx, Context *on_finish, | |
30 | ProgressContext &prog_ctx, | |
31 | ObjectIterateWork<ImageCtxT> handle_mismatch) | |
32 | : AsyncRequest<ImageCtxT>(image_ctx, on_finish), m_image_ctx(image_ctx), | |
33 | m_prog_ctx(prog_ctx), m_handle_mismatch(handle_mismatch) | |
34 | { | |
35 | } | |
36 | ||
37 | void send() override; | |
38 | ||
39 | protected: | |
40 | bool should_complete(int r) override; | |
41 | ||
42 | private: | |
43 | enum State { | |
44 | STATE_VERIFY_OBJECTS, | |
45 | STATE_INVALIDATE_OBJECT_MAP | |
46 | }; | |
47 | ||
48 | ImageCtxT &m_image_ctx; | |
49 | ProgressContext &m_prog_ctx; | |
50 | ObjectIterateWork<ImageCtxT> m_handle_mismatch; | |
51 | std::atomic_flag m_invalidate = ATOMIC_FLAG_INIT; | |
52 | State m_state; | |
53 | ||
54 | void send_verify_objects(); | |
55 | void send_invalidate_object_map(); | |
56 | ||
57 | uint64_t get_image_size() const; | |
58 | }; | |
59 | ||
60 | } // namespace operation | |
61 | } // namespace librbd | |
62 | ||
63 | extern template class librbd::operation::ObjectMapIterateRequest<librbd::ImageCtx>; | |
64 | ||
65 | #endif |