some minor glock improvements
Andreas Gruenbacher
maintainercover some minor glock improvements
Here are some minor glock improvements I came up with while trying to figure out a customer problem in this area. Please review.
Thanks,
Andreas
Andreas Gruenbacher (3):
gfs2: sanitize the gdlm_ast -> finish_xmote interface
gfs2: simplify finish_xmote
gfs2: a minor finish_xmote cleanup
fs/gfs2/glock.c | 42 ++++++++++++++++++++---------------------- fs/gfs2/glock.h | 10 ++++++++++ fs/gfs2/lock_dlm.c | 9 ++++++--- 3 files changed, 36 insertions(+), 25 deletions(-)
Signature · 1 line
2.50.0
Andreas Gruenbacher
maintainerPATCH 1/3 gfs2: sanitize the gdlm_ast -> finish_xmote interface
When gdlm_ast() is called with a non-zero status code, this means that the requested operation did not succeed and the current lock state didn't change. Turn that into a non-zero LM_OUT_* status code (with ret & ~LM_OUT_ST_MASK != 0) instead of pretending that dlm returned the now-current lock state.
Similarly, in do_xmote(), don't pretend that the current lock state changed when ->lm_lock() fails.
That way, we can change finish_xmote() to only update gl->gl_state when dlm has actually replied with the lock's new current state.
--- fs/gfs2/glock.c | 31 +++++++++++++++++++------------ fs/gfs2/glock.h | 10 ++++++++++ fs/gfs2/lock_dlm.c | 9 ++++++--- 3 files changed, 35 insertions(+), 15 deletions(-)
fs/gfs2/glock.c +19 -12
@@ -590,20 +590,25 @@ static void gfs2_demote_wake(struct gfs2_glock *gl)static void finish_xmote (struct gfs2_glock *gl,unsigned int ret) {const struct gfs2_glock_operations *glops = gl->gl_ops; -struct gfs2_holder *gh; -unsigned state = ret &LM_OUT_ST_MASK ; -trace_gfs2_glock_state_change (gl, state); -state_change (gl, state); - gh =find_first_waiter (gl); +if (!(ret & ~LM_OUT_ST_MASK )) { +unsigned state = ret &LM_OUT_ST_MASK ; + +trace_gfs2_glock_state_change (gl, state); +state_change (gl, state); + } +/* Demote to UN request arrived during demote to SH or DF */ if (test_bit (GLF_DEMOTE_IN_PROGRESS , &gl->gl_flags) && - state !=LM_ST_UNLOCKED && gl->gl_demote_state ==LM_ST_UNLOCKED ) + gl->gl_state !=LM_ST_UNLOCKED && + gl->gl_demote_state ==LM_ST_UNLOCKED ) gl->gl_target =LM_ST_UNLOCKED ;/* Check for state != intended state */ -if (unlikely (state != gl->gl_target)) { +if (unlikely (gl->gl_state != gl->gl_target)) { +struct gfs2_holder *gh =find_first_waiter (gl); +if (gh && (ret &LM_OUT_CANCELED ))gfs2_holder_wake (gh);if (gh && !test_bit (GLF_DEMOTE_IN_PROGRESS , &gl->gl_flags)) {
@@ -629,7 +634,7 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret) goto out; } } -switch (state) { +switch (gl->gl_state) {/* Unlocked due to conversion deadlock, try again */ case LM_ST_UNLOCKED :do_xmote (gl, gh, gl->gl_target);
@@ -640,8 +645,10 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)do_xmote (gl, gh,LM_ST_UNLOCKED );break ;default :/* Everything else */ -fs_err (gl->gl_name.ln_sbd,"wanted %u got %u\n" , - gl->gl_target, state); +fs_err (gl->gl_name.ln_sbd, +"glock %u:%llu wanted=%u ret=%u\n" , + gl->gl_name.ln_type, gl->gl_name.ln_number, + gl->gl_target, ret);GLOCK_BUG_ON (gl,1 ); }return ;
@@ -650,7 +657,7 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)/* Fast path - we got what we asked for */ if (test_and_clear_bit (GLF_DEMOTE_IN_PROGRESS , &gl->gl_flags))gfs2_demote_wake (gl); -if (state !=LM_ST_UNLOCKED ) { +if (gl->gl_state !=LM_ST_UNLOCKED ) {if (glops->go_xmote_bh) {int rv;
@@ -826,7 +833,7 @@ __acquires(&gl->gl_lockref.lock)*/ }else if (ret) {fs_err (sdp,"lm_lock ret %d\n" , ret); - target = gl->gl_state |LM_OUT_ERROR ; + target =LM_OUT_ERROR ; }else {/* The operation will be completed asynchronously. */ return ;
fs/gfs2/glock.h +10 -0
@@ -92,12 +92,22 @@ enum {* LM_OUT_ST_MASK * Masks the lower two bits of lock state in the returned value. * +* LM_OUT_TRY_AGAIN +* The trylock request failed. +* +* LM_OUT_DEADLOCK +* The lock request failed because it would deadlock. +* * LM_OUT_CANCELED * The lock request was canceled. * +* LM_OUT_ERROR +* The lock request timed out or failed. */ #define LM_OUT_ST_MASK 0x00000003 +#define LM_OUT_TRY_AGAIN 0x00000020 +#define LM_OUT_DEADLOCK 0x00000010#define LM_OUT_CANCELED 0x00000008#define LM_OUT_ERROR 0x00000004
fs/gfs2/lock_dlm.c +6 -3
@@ -119,7 +119,7 @@ static inline void gfs2_update_request_times(struct gfs2_glock *gl)static void gdlm_ast (void *arg) {struct gfs2_glock *gl = arg; -unsigned ret = gl->gl_state; +unsigned ret;/* If the glock is dead, we only react to a dlm_unlock() reply. */ if (__lockref_is_dead(&gl->gl_lockref) &&
@@ -139,13 +139,16 @@ static void gdlm_ast(void *arg)gfs2_glock_free (gl);return ;case -DLM_ECANCEL :/* Cancel while getting lock */ - ret |=LM_OUT_CANCELED ; + ret =LM_OUT_CANCELED ; goto out;case -EAGAIN :/* Try lock fails */ + ret =LM_OUT_TRY_AGAIN ; + goto out;case -EDEADLK :/* Deadlock detected */ + ret =LM_OUT_DEADLOCK ; goto out;case -ETIMEDOUT :/* Canceled due to timeout */ - ret |=LM_OUT_ERROR ; + ret =LM_OUT_ERROR ; goto out;case 0 :/* Success */ break ;
Signature · 1 line
2.50.0
Andreas Gruenbacher
maintainerPATCH 2/3 gfs2: simplify finish_xmote
In reply to Andreas GruenbacherAs a follow-up to commit a431d49243a0 ("gfs2: Fix request cancelation bug"), it turns out that any call to finish_xmote() is always followed by a call to run_queue(), either
* directly when glock_work_func() calls finish_xmote() before calling run_queue(), or
* indirectly when do_xmote() calls finish_xmote() before calling gfs2_glock_queue_work(), which queues a call to glock_work_func() in work queue context,
so remove the code in finish_xmote() that duplicates the functionality of run_queue().
In addition, the code this commit removes is missing a check for the GLF_DEMOTE flag which indicates that no further promotes should be performed, so if that code didn't get removed, that check would have to be added.
--- fs/gfs2/glock.c | 8 -------- 1 file changed, 8 deletions(-)
fs/gfs2/glock.c +0 -8
@@ -616,14 +616,6 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)list_del_init (&gh->gh_list);trace_gfs2_glock_queue (gh,0 ); gl->gl_target = gl->gl_state; - gh =find_first_waiter (gl); -if (gh) { - gl->gl_target = gh->gh_state; -if (do_promote (gl)) - goto out; -do_xmote (gl, gh, gl->gl_target); -return ; - } goto out; }/* Some error or failed "try lock" - report it */
Signature · 1 line
2.50.0
Andreas Gruenbacher
maintainerPATCH 3/3 gfs2: a minor finish_xmote cleanup
In reply to Andreas GruenbacherAs a minor clean-up to commit 1fc05c8d8426 ("gfs2: cancel timed-out glock requests"), when a demote request is in progress in finish_xmote(), there is no point in waking up the glock holder at the head of the queue because the reply from dlm cannot be on behalf of that glock holder.
--- fs/gfs2/glock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/gfs2/glock.c +1 -2
@@ -609,12 +609,11 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)if (unlikely (gl->gl_state != gl->gl_target)) {struct gfs2_holder *gh =find_first_waiter (gl); -if (gh && (ret &LM_OUT_CANCELED )) -gfs2_holder_wake (gh);if (gh && !test_bit (GLF_DEMOTE_IN_PROGRESS , &gl->gl_flags)) {if (ret &LM_OUT_CANCELED ) {list_del_init (&gh->gh_list);trace_gfs2_glock_queue (gh,0 ); +gfs2_holder_wake (gh); gl->gl_target = gl->gl_state; goto out; }
Signature · 1 line
2.50.0