Skip to content

Commit 60d8bae

Browse files
AstralBobAndreas Gruenbacher
authored andcommitted
gfs2: further simplify do_promote
This patch further simplifies function do_promote by eliminating some redundant code in favor of using a lock_released flag. This is just prep work for a future patch. Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent 17a6ece commit 60d8bae

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

fs/gfs2/glock.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,14 @@ __acquires(&gl->gl_lockref.lock)
487487
const struct gfs2_glock_operations *glops = gl->gl_ops;
488488
struct gfs2_holder *gh, *tmp, *first_gh;
489489
bool incompat_holders_demoted = false;
490+
bool lock_released;
490491
int ret;
491492

492493
restart:
493494
first_gh = find_first_strong_holder(gl);
494495
list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) {
495-
if (!test_bit(HIF_WAIT, &gh->gh_iflags))
496+
lock_released = false;
497+
if (test_bit(HIF_HOLDER, &gh->gh_iflags))
496498
continue;
497499
if (!may_grant(gl, first_gh, gh)) {
498500
/*
@@ -511,30 +513,31 @@ __acquires(&gl->gl_lockref.lock)
511513
first_gh = gh;
512514
}
513515
if (gh->gh_list.prev == &gl->gl_holders &&
514-
glops->go_instantiate) {
515-
if (!(gh->gh_flags & GL_SKIP)) {
516-
spin_unlock(&gl->gl_lockref.lock);
517-
/* FIXME: eliminate this eventually */
518-
ret = glops->go_instantiate(gh);
519-
spin_lock(&gl->gl_lockref.lock);
520-
if (ret) {
521-
if (ret == 1)
522-
return 2;
523-
gh->gh_error = ret;
524-
list_del_init(&gh->gh_list);
525-
trace_gfs2_glock_queue(gh, 0);
526-
gfs2_holder_wake(gh);
527-
goto restart;
528-
}
516+
!(gh->gh_flags & GL_SKIP) && glops->go_instantiate) {
517+
lock_released = true;
518+
spin_unlock(&gl->gl_lockref.lock);
519+
ret = glops->go_instantiate(gh);
520+
spin_lock(&gl->gl_lockref.lock);
521+
if (ret) {
522+
if (ret == 1)
523+
return 2;
524+
gh->gh_error = ret;
525+
list_del_init(&gh->gh_list);
526+
trace_gfs2_glock_queue(gh, 0);
527+
gfs2_holder_wake(gh);
528+
goto restart;
529529
}
530-
set_bit(HIF_HOLDER, &gh->gh_iflags);
531-
trace_gfs2_promote(gh);
532-
gfs2_holder_wake(gh);
533-
goto restart;
534530
}
535531
set_bit(HIF_HOLDER, &gh->gh_iflags);
536532
trace_gfs2_promote(gh);
537533
gfs2_holder_wake(gh);
534+
/*
535+
* If we released the gl_lockref.lock the holders list may have
536+
* changed. For that reason, we start again at the start of
537+
* the holders queue.
538+
*/
539+
if (lock_released)
540+
goto restart;
538541
}
539542
return 0;
540543
}

0 commit comments

Comments
 (0)