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_EXCLUSIVE_LOCK_H
5 #define CEPH_LIBRBD_EXCLUSIVE_LOCK_H
7 #include "librbd/ManagedLock.h"
8 #include "common/AsyncOpTracker.h"
12 template <typename ImageCtxT = ImageCtx>
13 class ExclusiveLock : public ManagedLock<ImageCtxT> {
15 static ExclusiveLock *create(ImageCtxT &image_ctx) {
16 return new ExclusiveLock<ImageCtxT>(image_ctx);
19 ExclusiveLock(ImageCtxT &image_ctx);
21 bool accept_requests(int *ret_val = nullptr) const;
22 bool accept_ops() const;
24 void block_requests(int r);
25 void unblock_requests();
27 void init(uint64_t features, Context *on_init);
28 void shut_down(Context *on_shutdown);
30 void handle_peer_notification(int r);
35 void shutdown_handler(int r, Context *on_finish) override;
36 void pre_acquire_lock_handler(Context *on_finish) override;
37 void post_acquire_lock_handler(int r, Context *on_finish) override;
38 void pre_release_lock_handler(bool shutting_down,
39 Context *on_finish) override;
40 void post_release_lock_handler(bool shutting_down, int r,
41 Context *on_finish) override;
42 void post_reacquire_lock_handler(int r, Context *on_finish) override;
49 * <start> * * > WAITING_FOR_REGISTER --------\
50 * | * (watch not registered) |
52 * | * * > WAITING_FOR_PEER ------------\
53 * | * (request_lock busy) |
55 * | * * * * * * * * * * * * * * |
57 * v (init) (try_lock/request_lock) * |
58 * UNINITIALIZED -------> UNLOCKED ------------------------> ACQUIRING <--/
61 * RELEASING POST_ACQUIRING
65 * PRE_RELEASING <------------------------ LOCKED
70 * REACQUIRING -------------------------------------> <finish>
73 * . . . > <RELEASE action> ---> <ACQUIRE action> ---/
75 * <UNLOCKED/LOCKED states>
79 * PRE_SHUTTING_DOWN ---> SHUTTING_DOWN ---> SHUTDOWN ---> <finish>
84 struct C_InitComplete;
86 ImageCtxT& m_image_ctx;
87 Context *m_pre_post_callback = nullptr;
89 AsyncOpTracker m_async_op_tracker;
91 uint32_t m_request_blocked_count = 0;
92 int m_request_blocked_ret_val = 0;
94 int m_acquire_lock_peer_ret_val = 0;
96 bool accept_ops(const Mutex &lock) const;
98 void handle_init_complete(uint64_t features);
99 void handle_post_acquiring_lock(int r);
100 void handle_post_acquired_lock(int r);
103 } // namespace librbd
105 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_H