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_MIRROR_SNAPSHOT_PROMOTE_REQUEST_H
5 #define CEPH_LIBRBD_MIRROR_SNAPSHOT_PROMOTE_REQUEST_H
7 #include "include/buffer.h"
8 #include "include/rbd/librbd.hpp"
9 #include "librbd/internal.h"
24 template <typename ImageCtxT
= librbd::ImageCtx
>
25 class PromoteRequest
{
27 static PromoteRequest
*create(ImageCtxT
*image_ctx
,
28 const std::string
& global_image_id
,
30 return new PromoteRequest(image_ctx
, global_image_id
, on_finish
);
33 PromoteRequest(ImageCtxT
*image_ctx
, const std::string
& global_image_id
,
35 : m_image_ctx(image_ctx
), m_global_image_id(global_image_id
),
36 m_on_finish(on_finish
) {
48 * |\----------------------------------------\
51 * v (skip if not needed) |
52 * CREATE_ORPHAN_SNAPSHOT |
54 * | /-- UNREGISTER_UPDATE_WATCHER <-\ |
56 * LIST_WATCHERS ----> WAIT_UPDATE_NOTIFY --/ |
60 * ACQUIRE_EXCLUSIVE_LOCK |
61 * | (skip if not needed) |
66 * CREATE_PROMOTE_SNAPSHOT <--------------------/
69 * DISABLE_NON_PRIMARY_FEATURE
72 * RELEASE_EXCLUSIVE_LOCK (skip if not needed)
80 ImageCtxT
*m_image_ctx
;
81 std::string m_global_image_id
;
84 uint64_t m_rollback_snap_id
= CEPH_NOSNAP
;
85 bool m_lock_acquired
= false;
86 NoOpProgressContext m_progress_ctx
;
88 class UpdateWatchCtx
: public librbd::UpdateWatchCtx
{
90 UpdateWatchCtx(PromoteRequest
*promote_request
)
91 : promote_request(promote_request
) {
94 void handle_notify() {
95 promote_request
->handle_update_notify();
99 PromoteRequest
*promote_request
;
101 } m_update_watch_ctx
= {this};
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;
109 void refresh_image();
110 void handle_refresh_image(int r
);
112 void create_orphan_snapshot();
113 void handle_create_orphan_snapshot(int r
);
115 void list_watchers();
116 void handle_list_watchers(int r
);
118 void wait_update_notify();
119 void handle_update_notify();
120 void scheduler_unregister_update_watcher();
122 void unregister_update_watcher();
123 void handle_unregister_update_watcher(int r
);
125 void acquire_exclusive_lock();
126 void handle_acquire_exclusive_lock(int r
);
129 void handle_rollback(int r
);
131 void create_promote_snapshot();
132 void handle_create_promote_snapshot(int r
);
134 void disable_non_primary_feature();
135 void handle_disable_non_primary_feature(int r
);
137 void release_exclusive_lock();
138 void handle_release_exclusive_lock(int r
);
144 } // namespace snapshot
145 } // namespace mirror
146 } // namespace librbd
148 extern template class librbd::mirror::snapshot::PromoteRequest
<librbd::ImageCtx
>;
150 #endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_PROMOTE_REQUEST_H