diff options
author | Sunil Mushran <sunil.mushran@oracle.com> | 2008-12-16 18:49:22 -0500 |
---|---|---|
committer | Mark Fasheh <mfasheh@suse.com> | 2009-01-05 11:40:35 -0500 |
commit | b0d4f817ba5de8adb875ace594554a96d7737710 (patch) | |
tree | 2e64d3240d6ad879c4ffa1c01ca1696abf3bb2fb /fs/ocfs2/dlm/dlmdebug.c | |
parent | d4f7e650e55af6b235871126f747da88600e8040 (diff) |
ocfs2/dlm: Fix race in adding/removing lockres' to/from the tracking list
This patch adds a new lock, dlm->tracking_lock, to protect adding/removing
lockres' to/from the dlm->tracking_list. We were previously using dlm->spinlock
for the same, but that proved inadequate as we could be freeing a lockres from
a context that did not hold that lock. As the new lock only protects this list,
we can explicitly take it when removing the lockres from the tracking list.
This bug was exposed when testing multiple processes concurrently flock() the
same file.
Signed-off-by: Sunil Mushran <sunil.mushran@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs/ocfs2/dlm/dlmdebug.c')
-rw-r--r-- | fs/ocfs2/dlm/dlmdebug.c | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/fs/ocfs2/dlm/dlmdebug.c b/fs/ocfs2/dlm/dlmdebug.c index 1b81dcba175..b32f60a5acf 100644 --- a/fs/ocfs2/dlm/dlmdebug.c +++ b/fs/ocfs2/dlm/dlmdebug.c | |||
@@ -630,43 +630,38 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos) | |||
630 | { | 630 | { |
631 | struct debug_lockres *dl = m->private; | 631 | struct debug_lockres *dl = m->private; |
632 | struct dlm_ctxt *dlm = dl->dl_ctxt; | 632 | struct dlm_ctxt *dlm = dl->dl_ctxt; |
633 | struct dlm_lock_resource *oldres = dl->dl_res; | ||
633 | struct dlm_lock_resource *res = NULL; | 634 | struct dlm_lock_resource *res = NULL; |
635 | struct list_head *track_list; | ||
634 | 636 | ||
635 | spin_lock(&dlm->spinlock); | 637 | spin_lock(&dlm->track_lock); |
638 | if (oldres) | ||
639 | track_list = &oldres->tracking; | ||
640 | else | ||
641 | track_list = &dlm->tracking_list; | ||
636 | 642 | ||
637 | if (dl->dl_res) { | 643 | list_for_each_entry(res, track_list, tracking) { |
638 | list_for_each_entry(res, &dl->dl_res->tracking, tracking) { | 644 | if (&res->tracking == &dlm->tracking_list) |
639 | if (dl->dl_res) { | 645 | res = NULL; |
640 | dlm_lockres_put(dl->dl_res); | 646 | else |
641 | dl->dl_res = NULL; | ||
642 | } | ||
643 | if (&res->tracking == &dlm->tracking_list) { | ||
644 | mlog(0, "End of list found, %p\n", res); | ||
645 | dl = NULL; | ||
646 | break; | ||
647 | } | ||
648 | dlm_lockres_get(res); | 647 | dlm_lockres_get(res); |
649 | dl->dl_res = res; | 648 | break; |
650 | break; | ||
651 | } | ||
652 | } else { | ||
653 | if (!list_empty(&dlm->tracking_list)) { | ||
654 | list_for_each_entry(res, &dlm->tracking_list, tracking) | ||
655 | break; | ||
656 | dlm_lockres_get(res); | ||
657 | dl->dl_res = res; | ||
658 | } else | ||
659 | dl = NULL; | ||
660 | } | 649 | } |
650 | spin_unlock(&dlm->track_lock); | ||
661 | 651 | ||
662 | if (dl) { | 652 | if (oldres) |
663 | spin_lock(&dl->dl_res->spinlock); | 653 | dlm_lockres_put(oldres); |
664 | dump_lockres(dl->dl_res, dl->dl_buf, dl->dl_len - 1); | ||
665 | spin_unlock(&dl->dl_res->spinlock); | ||
666 | } | ||
667 | 654 | ||
668 | spin_unlock(&dlm->spinlock); | 655 | dl->dl_res = res; |
656 | |||
657 | if (res) { | ||
658 | spin_lock(&res->spinlock); | ||
659 | dump_lockres(res, dl->dl_buf, dl->dl_len - 1); | ||
660 | spin_unlock(&res->spinlock); | ||
661 | } else | ||
662 | dl = NULL; | ||
669 | 663 | ||
664 | /* passed to seq_show */ | ||
670 | return dl; | 665 | return dl; |
671 | } | 666 | } |
672 | 667 | ||