]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/ExclusiveLock.h
update sources to 12.2.10
[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 int get_unlocked_op_error() const;
33 Context *start_op(int* ret_val);
34
35 protected:
36 void shutdown_handler(int r, Context *on_finish) override;
37 void pre_acquire_lock_handler(Context *on_finish) override;
38 void post_acquire_lock_handler(int r, Context *on_finish) override;
39 void pre_release_lock_handler(bool shutting_down,
40 Context *on_finish) override;
41 void post_release_lock_handler(bool shutting_down, int r,
42 Context *on_finish) override;
43 void post_reacquire_lock_handler(int r, Context *on_finish) override;
44
45 private:
46
47 /**
48 * @verbatim
49 *
50 * <start> * * > WAITING_FOR_REGISTER --------\
51 * | * (watch not registered) |
52 * | * |
53 * | * * > WAITING_FOR_PEER ------------\
54 * | * (request_lock busy) |
55 * | * |
56 * | * * * * * * * * * * * * * * |
57 * | * |
58 * v (init) (try_lock/request_lock) * |
59 * UNINITIALIZED -------> UNLOCKED ------------------------> ACQUIRING <--/
60 * ^ |
61 * | v
62 * RELEASING POST_ACQUIRING
63 * | |
64 * | |
65 * | (release_lock) v
66 * PRE_RELEASING <------------------------ LOCKED
67 *
68 * <LOCKED state>
69 * |
70 * v
71 * REACQUIRING -------------------------------------> <finish>
72 * . ^
73 * . |
74 * . . . > <RELEASE action> ---> <ACQUIRE action> ---/
75 *
76 * <UNLOCKED/LOCKED states>
77 * |
78 * |
79 * v
80 * PRE_SHUTTING_DOWN ---> SHUTTING_DOWN ---> SHUTDOWN ---> <finish>
81 *
82 * @endverbatim
83 */
84
85 struct C_InitComplete;
86
87 ImageCtxT& m_image_ctx;
88 Context *m_pre_post_callback = nullptr;
89
90 AsyncOpTracker m_async_op_tracker;
91
92 uint32_t m_request_blocked_count = 0;
93 int m_request_blocked_ret_val = 0;
94
95 int m_acquire_lock_peer_ret_val = 0;
96
97 bool accept_ops(const Mutex &lock) const;
98
99 void handle_init_complete(uint64_t features);
100 void handle_post_acquiring_lock(int r);
101 void handle_post_acquired_lock(int r);
102 };
103
104 } // namespace librbd
105
106 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_H