]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/ExclusiveLock.h
add subtree-ish sources for 12.0.3
[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 "librbd/ImageCtx.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) const;
22
23 void block_requests(int r);
24 void unblock_requests();
25
26 void init(uint64_t features, Context *on_init);
27 void shut_down(Context *on_shutdown);
28
29 void handle_peer_notification(int r);
30
31 protected:
32 void shutdown_handler(int r, Context *on_finish) override;
33 void pre_acquire_lock_handler(Context *on_finish) override;
34 void post_acquire_lock_handler(int r, Context *on_finish) override;
35 void pre_release_lock_handler(bool shutting_down,
36 Context *on_finish) override;
37 void post_release_lock_handler(bool shutting_down, int r,
38 Context *on_finish) override;
39
40 private:
41
42 /**
43 * @verbatim
44 *
45 * <start> * * > WAITING_FOR_REGISTER --------\
46 * | * (watch not registered) |
47 * | * |
48 * | * * > WAITING_FOR_PEER ------------\
49 * | * (request_lock busy) |
50 * | * |
51 * | * * * * * * * * * * * * * * |
52 * | * |
53 * v (init) (try_lock/request_lock) * |
54 * UNINITIALIZED -------> UNLOCKED ------------------------> ACQUIRING <--/
55 * ^ |
56 * | v
57 * RELEASING POST_ACQUIRING
58 * | |
59 * | |
60 * | (release_lock) v
61 * PRE_RELEASING <------------------------ LOCKED
62 *
63 * <LOCKED state>
64 * |
65 * v
66 * REACQUIRING -------------------------------------> <finish>
67 * . ^
68 * . |
69 * . . . > <RELEASE action> ---> <ACQUIRE action> ---/
70 *
71 * <UNLOCKED/LOCKED states>
72 * |
73 * |
74 * v
75 * PRE_SHUTTING_DOWN ---> SHUTTING_DOWN ---> SHUTDOWN ---> <finish>
76 *
77 * @endverbatim
78 */
79
80 struct C_InitComplete;
81
82 ImageCtxT& m_image_ctx;
83 Context *m_pre_post_callback = nullptr;
84
85 uint32_t m_request_blocked_count = 0;
86 int m_request_blocked_ret_val = 0;
87
88 int m_acquire_lock_peer_ret_val = 0;
89
90 void handle_init_complete(uint64_t features);
91 void handle_post_acquiring_lock(int r);
92 void handle_post_acquired_lock(int r);
93 };
94
95 } // namespace librbd
96
97 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_H