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
);
32 int get_unlocked_op_error() const;
33 Context
*start_op(int* ret_val
);
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
;
50 * <start> * * > WAITING_FOR_REGISTER --------\
51 * | * (watch not registered) |
53 * | * * > WAITING_FOR_PEER ------------\
54 * | * (request_lock busy) |
56 * | * * * * * * * * * * * * * * |
58 * v (init) (try_lock/request_lock) * |
59 * UNINITIALIZED -------> UNLOCKED ------------------------> ACQUIRING <--/
62 * RELEASING POST_ACQUIRING
66 * PRE_RELEASING <------------------------ LOCKED
71 * REACQUIRING -------------------------------------> <finish>
74 * . . . > <RELEASE action> ---> <ACQUIRE action> ---/
76 * <UNLOCKED/LOCKED states>
80 * PRE_SHUTTING_DOWN ---> SHUTTING_DOWN ---> SHUTDOWN ---> <finish>
85 struct C_InitComplete
;
87 ImageCtxT
& m_image_ctx
;
88 Context
*m_pre_post_callback
= nullptr;
90 AsyncOpTracker m_async_op_tracker
;
92 uint32_t m_request_blocked_count
= 0;
93 int m_request_blocked_ret_val
= 0;
95 int m_acquire_lock_peer_ret_val
= 0;
97 bool accept_ops(const Mutex
&lock
) const;
99 void handle_init_complete(uint64_t features
);
100 void handle_post_acquiring_lock(int r
);
101 void handle_post_acquired_lock(int r
);
104 } // namespace librbd
106 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_H