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 "common/AsyncOpTracker.h"
8 #include "librbd/ManagedLock.h"
9 #include "librbd/exclusive_lock/Policy.h"
10 #include "common/RefCountedObj.h"
14 template <typename ImageCtxT
= ImageCtx
>
15 class ExclusiveLock
: public RefCountedObject
,
16 public ManagedLock
<ImageCtxT
> {
18 static ExclusiveLock
*create(ImageCtxT
&image_ctx
) {
19 return new ExclusiveLock
<ImageCtxT
>(image_ctx
);
22 ExclusiveLock(ImageCtxT
&image_ctx
);
24 bool accept_request(exclusive_lock::OperationRequestType request_type
,
26 bool accept_ops() const;
28 void block_requests(int r
);
29 void unblock_requests();
31 void init(uint64_t features
, Context
*on_init
);
32 void shut_down(Context
*on_shutdown
);
34 void handle_peer_notification(int r
);
36 int get_unlocked_op_error() const;
37 Context
*start_op(int* ret_val
);
40 void shutdown_handler(int r
, Context
*on_finish
) override
;
41 void pre_acquire_lock_handler(Context
*on_finish
) override
;
42 void post_acquire_lock_handler(int r
, Context
*on_finish
) override
;
43 void pre_release_lock_handler(bool shutting_down
,
44 Context
*on_finish
) override
;
45 void post_release_lock_handler(bool shutting_down
, int r
,
46 Context
*on_finish
) override
;
47 void post_reacquire_lock_handler(int r
, Context
*on_finish
) override
;
54 * <start> * * > WAITING_FOR_REGISTER --------\
55 * | * (watch not registered) |
57 * | * * > WAITING_FOR_PEER ------------\
58 * | * (request_lock busy) |
60 * | * * * * * * * * * * * * * * |
62 * v (init) (try_lock/request_lock) * |
63 * UNINITIALIZED -------> UNLOCKED ------------------------> ACQUIRING <--/
66 * RELEASING POST_ACQUIRING
70 * PRE_RELEASING <------------------------ LOCKED
75 * REACQUIRING -------------------------------------> <finish>
78 * . . . > <RELEASE action> ---> <ACQUIRE action> ---/
80 * <UNLOCKED/LOCKED states>
84 * PRE_SHUTTING_DOWN ---> SHUTTING_DOWN ---> SHUTDOWN ---> <finish>
89 struct C_InitComplete
;
91 ImageCtxT
& m_image_ctx
;
92 Context
*m_pre_post_callback
= nullptr;
94 AsyncOpTracker m_async_op_tracker
;
96 uint32_t m_request_blocked_count
= 0;
97 int m_request_blocked_ret_val
= 0;
99 int m_acquire_lock_peer_ret_val
= 0;
101 bool accept_ops(const ceph::mutex
&lock
) const;
103 void handle_init_complete(uint64_t features
);
104 void handle_post_acquiring_lock(int r
);
105 void handle_post_acquired_lock(int r
);
108 } // namespace librbd
110 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_H