]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/mirror/snapshot/PromoteRequest.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librbd / mirror / snapshot / PromoteRequest.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_MIRROR_SNAPSHOT_PROMOTE_REQUEST_H
5 #define CEPH_LIBRBD_MIRROR_SNAPSHOT_PROMOTE_REQUEST_H
6
7 #include "include/buffer.h"
8 #include "include/rbd/librbd.hpp"
9 #include "librbd/internal.h"
10
11 #include <string>
12 #include <set>
13
14 class SafeTimer;
15 struct Context;
16
17 namespace librbd {
18
19 struct ImageCtx;
20
21 namespace mirror {
22 namespace snapshot {
23
24 template <typename ImageCtxT = librbd::ImageCtx>
25 class PromoteRequest {
26 public:
27 static PromoteRequest *create(ImageCtxT *image_ctx,
28 const std::string& global_image_id,
29 Context *on_finish) {
30 return new PromoteRequest(image_ctx, global_image_id, on_finish);
31 }
32
33 PromoteRequest(ImageCtxT *image_ctx, const std::string& global_image_id,
34 Context *on_finish)
35 : m_image_ctx(image_ctx), m_global_image_id(global_image_id),
36 m_on_finish(on_finish) {
37 }
38
39 void send();
40
41 private:
42 /**
43 * @verbatim
44 *
45 * <start>
46 * |
47 * | (can promote)
48 * |\----------------------------------------\
49 * | |
50 * | |
51 * v (skip if not needed) |
52 * CREATE_ORPHAN_SNAPSHOT |
53 * | |
54 * | /-- UNREGISTER_UPDATE_WATCHER <-\ |
55 * v v | |
56 * LIST_WATCHERS ----> WAIT_UPDATE_NOTIFY --/ |
57 * | |
58 * | (no watchers) |
59 * v |
60 * ACQUIRE_EXCLUSIVE_LOCK |
61 * | (skip if not needed) |
62 * v |
63 * ROLLBACK |
64 * | |
65 * v |
66 * CREATE_PROMOTE_SNAPSHOT <--------------------/
67 * |
68 * v
69 * DISABLE_NON_PRIMARY_FEATURE
70 * |
71 * v
72 * RELEASE_EXCLUSIVE_LOCK (skip if not needed)
73 * |
74 * v
75 * <finish>
76 *
77 * @endverbatim
78 */
79
80 ImageCtxT *m_image_ctx;
81 std::string m_global_image_id;
82 Context *m_on_finish;
83
84 uint64_t m_rollback_snap_id = CEPH_NOSNAP;
85 bool m_lock_acquired = false;
86 NoOpProgressContext m_progress_ctx;
87
88 class UpdateWatchCtx : public librbd::UpdateWatchCtx {
89 public:
90 UpdateWatchCtx(PromoteRequest *promote_request)
91 : promote_request(promote_request) {
92 }
93
94 void handle_notify() {
95 promote_request->handle_update_notify();
96 }
97
98 private:
99 PromoteRequest *promote_request;
100
101 } m_update_watch_ctx = {this};
102
103 std::list<obj_watch_t> m_watchers;
104 uint64_t m_update_watcher_handle = 0;
105 uint64_t m_scheduler_ticks = 0;
106 SafeTimer *m_timer = nullptr;
107 ceph::mutex *m_timer_lock = nullptr;
108
109 void refresh_image();
110 void handle_refresh_image(int r);
111
112 void create_orphan_snapshot();
113 void handle_create_orphan_snapshot(int r);
114
115 void list_watchers();
116 void handle_list_watchers(int r);
117
118 void wait_update_notify();
119 void handle_update_notify();
120 void scheduler_unregister_update_watcher();
121
122 void unregister_update_watcher();
123 void handle_unregister_update_watcher(int r);
124
125 void acquire_exclusive_lock();
126 void handle_acquire_exclusive_lock(int r);
127
128 void rollback();
129 void handle_rollback(int r);
130
131 void create_promote_snapshot();
132 void handle_create_promote_snapshot(int r);
133
134 void disable_non_primary_feature();
135 void handle_disable_non_primary_feature(int r);
136
137 void release_exclusive_lock();
138 void handle_release_exclusive_lock(int r);
139
140 void finish(int r);
141
142 };
143
144 } // namespace snapshot
145 } // namespace mirror
146 } // namespace librbd
147
148 extern template class librbd::mirror::snapshot::PromoteRequest<librbd::ImageCtx>;
149
150 #endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_PROMOTE_REQUEST_H