Skip to content

Commit 1cd28e1

Browse files
author
Andreas Gruenbacher
committed
gfs2: finish_xmote cleanup
Currently, function finish_xmote() takes and releases the glock spinlock. However, all of its callers immediately take that spinlock again, so it makes more sense to take the spin lock before calling finish_xmote() already. With that, thaw_glock() is the only place that sets the GLF_HAVE_REPLY flag outside of the glock spinlock, but it also takes that spinlock immediately thereafter. Change that to set the bit when the spinlock is already held. This allows to switch from test_and_clear_bit() to test_bit() and clear_bit() in glock_work_func(). Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent a3730c5 commit 1cd28e1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

fs/gfs2/glock.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
625625
struct gfs2_holder *gh;
626626
unsigned state = ret & LM_OUT_ST_MASK;
627627

628-
spin_lock(&gl->gl_lockref.lock);
629628
trace_gfs2_glock_state_change(gl, state);
630629
state_change(gl, state);
631630
gh = find_first_waiter(gl);
@@ -673,7 +672,6 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
673672
gl->gl_target, state);
674673
GLOCK_BUG_ON(gl, 1);
675674
}
676-
spin_unlock(&gl->gl_lockref.lock);
677675
return;
678676
}
679677

@@ -696,7 +694,6 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
696694
}
697695
out:
698696
clear_bit(GLF_LOCK, &gl->gl_flags);
699-
spin_unlock(&gl->gl_lockref.lock);
700697
}
701698

702699
static bool is_system_glock(struct gfs2_glock *gl)
@@ -843,15 +840,19 @@ __acquires(&gl->gl_lockref.lock)
843840
if (ret == -EINVAL && gl->gl_target == LM_ST_UNLOCKED &&
844841
target == LM_ST_UNLOCKED &&
845842
test_bit(DFL_UNMOUNT, &ls->ls_recover_flags)) {
843+
spin_lock(&gl->gl_lockref.lock);
846844
finish_xmote(gl, target);
847-
gfs2_glock_queue_work(gl, 0);
845+
__gfs2_glock_queue_work(gl, 0);
846+
spin_unlock(&gl->gl_lockref.lock);
848847
} else if (ret) {
849848
fs_err(sdp, "lm_lock ret %d\n", ret);
850849
GLOCK_BUG_ON(gl, !gfs2_withdrawing_or_withdrawn(sdp));
851850
}
852851
} else { /* lock_nolock */
852+
spin_lock(&gl->gl_lockref.lock);
853853
finish_xmote(gl, target);
854-
gfs2_glock_queue_work(gl, 0);
854+
__gfs2_glock_queue_work(gl, 0);
855+
spin_unlock(&gl->gl_lockref.lock);
855856
}
856857
out:
857858
spin_lock(&gl->gl_lockref.lock);
@@ -1108,11 +1109,12 @@ static void glock_work_func(struct work_struct *work)
11081109
struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_work.work);
11091110
unsigned int drop_refs = 1;
11101111

1111-
if (test_and_clear_bit(GLF_REPLY_PENDING, &gl->gl_flags)) {
1112+
spin_lock(&gl->gl_lockref.lock);
1113+
if (test_bit(GLF_REPLY_PENDING, &gl->gl_flags)) {
1114+
clear_bit(GLF_REPLY_PENDING, &gl->gl_flags);
11121115
finish_xmote(gl, gl->gl_reply);
11131116
drop_refs++;
11141117
}
1115-
spin_lock(&gl->gl_lockref.lock);
11161118
if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
11171119
gl->gl_state != LM_ST_UNLOCKED &&
11181120
gl->gl_demote_state != LM_ST_EXCLUSIVE) {
@@ -2183,8 +2185,11 @@ static void thaw_glock(struct gfs2_glock *gl)
21832185
return;
21842186
if (!lockref_get_not_dead(&gl->gl_lockref))
21852187
return;
2188+
2189+
spin_lock(&gl->gl_lockref.lock);
21862190
set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
2187-
gfs2_glock_queue_work(gl, 0);
2191+
__gfs2_glock_queue_work(gl, 0);
2192+
spin_unlock(&gl->gl_lockref.lock);
21882193
}
21892194

21902195
/**

0 commit comments

Comments
 (0)