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 "librbd/ImageCtx.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
) const;
23 void block_requests(int r
);
24 void unblock_requests();
26 void init(uint64_t features
, Context
*on_init
);
27 void shut_down(Context
*on_shutdown
);
29 void handle_peer_notification(int r
);
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
;
45 * <start> * * > WAITING_FOR_REGISTER --------\
46 * | * (watch not registered) |
48 * | * * > WAITING_FOR_PEER ------------\
49 * | * (request_lock busy) |
51 * | * * * * * * * * * * * * * * |
53 * v (init) (try_lock/request_lock) * |
54 * UNINITIALIZED -------> UNLOCKED ------------------------> ACQUIRING <--/
57 * RELEASING POST_ACQUIRING
61 * PRE_RELEASING <------------------------ LOCKED
66 * REACQUIRING -------------------------------------> <finish>
69 * . . . > <RELEASE action> ---> <ACQUIRE action> ---/
71 * <UNLOCKED/LOCKED states>
75 * PRE_SHUTTING_DOWN ---> SHUTTING_DOWN ---> SHUTDOWN ---> <finish>
80 struct C_InitComplete
;
82 ImageCtxT
& m_image_ctx
;
83 Context
*m_pre_post_callback
= nullptr;
85 uint32_t m_request_blocked_count
= 0;
86 int m_request_blocked_ret_val
= 0;
88 int m_acquire_lock_peer_ret_val
= 0;
90 void handle_init_complete(uint64_t features
);
91 void handle_post_acquiring_lock(int r
);
92 void handle_post_acquired_lock(int r
);
97 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_H