]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/ExclusiveLock.h
update sources to v12.1.0
[ceph.git] / ceph / src / librbd / ExclusiveLock.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_EXCLUSIVE_LOCK_H
5 #define CEPH_LIBRBD_EXCLUSIVE_LOCK_H
6
7 #include "librbd/ManagedLock.h"
8 #include "common/AsyncOpTracker.h"
9
10 namespace librbd {
11
12 template <typename ImageCtxT = ImageCtx>
13 class ExclusiveLock : public ManagedLock<ImageCtxT> {
14 public:
15 static ExclusiveLock *create(ImageCtxT &image_ctx) {
16 return new ExclusiveLock<ImageCtxT>(image_ctx);
17 }
18
19 ExclusiveLock(ImageCtxT &image_ctx);
20
21 bool accept_requests(int *ret_val = nullptr) const;
22 bool accept_ops() const;
23
24 void block_requests(int r);
25 void unblock_requests();
26
27 void init(uint64_t features, Context *on_init);
28 void shut_down(Context *on_shutdown);
29
30 void handle_peer_notification(int r);
31
32 Context *start_op();
33
34 protected:
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;
43
44 private:
45
46 /**
47 * @verbatim
48 *
49 * <start> * * > WAITING_FOR_REGISTER --------\
50 * | * (watch not registered) |
51 * | * |
52 * | * * > WAITING_FOR_PEER ------------\
53 * | * (request_lock busy) |
54 * | * |
55 * | * * * * * * * * * * * * * * |
56 * | * |
57 * v (init) (try_lock/request_lock) * |
58 * UNINITIALIZED -------> UNLOCKED ------------------------> ACQUIRING <--/
59 * ^ |
60 * | v
61 * RELEASING POST_ACQUIRING
62 * | |
63 * | |
64 * | (release_lock) v
65 * PRE_RELEASING <------------------------ LOCKED
66 *
67 * <LOCKED state>
68 * |
69 * v
70 * REACQUIRING -------------------------------------> <finish>
71 * . ^
72 * . |
73 * . . . > <RELEASE action> ---> <ACQUIRE action> ---/
74 *
75 * <UNLOCKED/LOCKED states>
76 * |
77 * |
78 * v
79 * PRE_SHUTTING_DOWN ---> SHUTTING_DOWN ---> SHUTDOWN ---> <finish>
80 *
81 * @endverbatim
82 */
83
84 struct C_InitComplete;
85
86 ImageCtxT& m_image_ctx;
87 Context *m_pre_post_callback = nullptr;
88
89 AsyncOpTracker m_async_op_tracker;
90
91 uint32_t m_request_blocked_count = 0;
92 int m_request_blocked_ret_val = 0;
93
94 int m_acquire_lock_peer_ret_val = 0;
95
96 bool accept_ops(const Mutex &lock) const;
97
98 void handle_init_complete(uint64_t features);
99 void handle_post_acquiring_lock(int r);
100 void handle_post_acquired_lock(int r);
101 };
102
103 } // namespace librbd
104
105 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_H