]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_deleter/TrashWatcher.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / tools / rbd_mirror / image_deleter / TrashWatcher.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_RBD_MIRROR_IMAGE_DELETE_TRASH_WATCHER_H
5 #define CEPH_RBD_MIRROR_IMAGE_DELETE_TRASH_WATCHER_H
6
7 #include "include/rados/librados.hpp"
8 #include "common/AsyncOpTracker.h"
9 #include "common/ceph_mutex.h"
10 #include "librbd/TrashWatcher.h"
11 #include <set>
12 #include <string>
13
14 struct Context;
15 namespace librbd { struct ImageCtx; }
16
17 namespace rbd {
18 namespace mirror {
19
20 template <typename> struct Threads;
21
22 namespace image_deleter {
23
24 struct TrashListener;
25
26 template <typename ImageCtxT = librbd::ImageCtx>
27 class TrashWatcher : public librbd::TrashWatcher<ImageCtxT> {
28 public:
29 static TrashWatcher* create(librados::IoCtx &io_ctx,
30 Threads<ImageCtxT> *threads,
31 TrashListener& trash_listener) {
32 return new TrashWatcher(io_ctx, threads, trash_listener);
33 }
34
35 TrashWatcher(librados::IoCtx &io_ctx, Threads<ImageCtxT> *threads,
36 TrashListener& trash_listener);
37 TrashWatcher(const TrashWatcher&) = delete;
38 TrashWatcher& operator=(const TrashWatcher&) = delete;
39
40 void init(Context *on_finish);
41 void shut_down(Context *on_finish);
42
43 protected:
44 void handle_image_added(const std::string &image_id,
45 const cls::rbd::TrashImageSpec& spec) override;
46
47 void handle_image_removed(const std::string &image_id) override;
48
49 void handle_rewatch_complete(int r) override;
50
51 private:
52 /**
53 * @verbatim
54 *
55 * <start>
56 * |
57 * v
58 * INIT
59 * |
60 * v
61 * CREATE_TRASH
62 * |
63 * v
64 * REGISTER_WATCHER
65 * |
66 * |/--------------------------------\
67 * | |
68 * |/---------\ |
69 * | | |
70 * v | (more images) |
71 * TRASH_LIST ---/ |
72 * | |
73 * |/----------------------------\ |
74 * | | |
75 * v | |
76 * <idle> --\ | |
77 * | | | |
78 * | |\---> IMAGE_ADDED -----/ |
79 * | | |
80 * | \----> WATCH_ERROR ---------/
81 * v
82 * SHUT_DOWN
83 * |
84 * v
85 * UNREGISTER_WATCHER
86 * |
87 * v
88 * <finish>
89 *
90 * @endverbatim
91 */
92
93 librados::IoCtx m_io_ctx;
94 Threads<ImageCtxT> *m_threads;
95 TrashListener& m_trash_listener;
96
97 std::string m_last_image_id;
98 bufferlist m_out_bl;
99
100 mutable ceph::mutex m_lock;
101
102 Context *m_on_init_finish = nullptr;
103 Context *m_timer_ctx = nullptr;
104
105 AsyncOpTracker m_async_op_tracker;
106 bool m_trash_list_in_progress = false;
107 bool m_deferred_trash_list = false;
108 bool m_shutting_down = false;
109
110 void register_watcher();
111 void handle_register_watcher(int r);
112
113 void create_trash();
114 void handle_create_trash(int r);
115
116 void unregister_watcher(Context* on_finish);
117 void handle_unregister_watcher(int r, Context* on_finish);
118
119 void trash_list(bool initial_request);
120 void handle_trash_list(int r);
121
122 void schedule_trash_list(double interval);
123 void process_trash_list();
124
125 void get_mirror_uuid();
126 void handle_get_mirror_uuid(int r);
127
128 void add_image(const std::string& image_id,
129 const cls::rbd::TrashImageSpec& spec);
130
131 };
132
133 } // namespace image_deleter
134 } // namespace mirror
135 } // namespace rbd
136
137 extern template class rbd::mirror::image_deleter::TrashWatcher<librbd::ImageCtx>;
138
139 #endif // CEPH_RBD_MIRROR_IMAGE_DELETE_TRASH_WATCHER_H