diff options
author | Sunil Mushran <sunil.mushran@oracle.com> | 2011-07-24 13:26:54 -0400 |
---|---|---|
committer | Sunil Mushran <sunil.mushran@oracle.com> | 2011-07-24 13:26:54 -0400 |
commit | 8d400b81cc83b171ff872587723a37eb7fae9abe (patch) | |
tree | 443b802744cdfa1f1f9f38b3d5917fc4bc30a4e2 /fs/ocfs2/dlm/dlmmaster.c | |
parent | 0afbba13226fcdbd4327f6b13a42f6efbb8c9caf (diff) |
ocfs2/dlm: Clean up refmap helpers
Patch cleans up helpers that set/clear refmap bits and grab/drop inflight lock
ref counts.
Signed-off-by: Sunil Mushran <sunil.mushran@oracle.com>
Diffstat (limited to 'fs/ocfs2/dlm/dlmmaster.c')
-rw-r--r-- | fs/ocfs2/dlm/dlmmaster.c | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c index 9f3b093b629a..11e446ffb67a 100644 --- a/fs/ocfs2/dlm/dlmmaster.c +++ b/fs/ocfs2/dlm/dlmmaster.c | |||
@@ -631,39 +631,58 @@ error: | |||
631 | return NULL; | 631 | return NULL; |
632 | } | 632 | } |
633 | 633 | ||
634 | void __dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm, | 634 | void dlm_lockres_set_refmap_bit(struct dlm_ctxt *dlm, |
635 | struct dlm_lock_resource *res, | 635 | struct dlm_lock_resource *res, int bit) |
636 | int new_lockres, | ||
637 | const char *file, | ||
638 | int line) | ||
639 | { | 636 | { |
640 | if (!new_lockres) | 637 | assert_spin_locked(&res->spinlock); |
641 | assert_spin_locked(&res->spinlock); | 638 | |
639 | mlog(0, "res %.*s, set node %u, %ps()\n", res->lockname.len, | ||
640 | res->lockname.name, bit, __builtin_return_address(0)); | ||
641 | |||
642 | set_bit(bit, res->refmap); | ||
643 | } | ||
644 | |||
645 | void dlm_lockres_clear_refmap_bit(struct dlm_ctxt *dlm, | ||
646 | struct dlm_lock_resource *res, int bit) | ||
647 | { | ||
648 | assert_spin_locked(&res->spinlock); | ||
649 | |||
650 | mlog(0, "res %.*s, clr node %u, %ps()\n", res->lockname.len, | ||
651 | res->lockname.name, bit, __builtin_return_address(0)); | ||
652 | |||
653 | clear_bit(bit, res->refmap); | ||
654 | } | ||
655 | |||
656 | |||
657 | void dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm, | ||
658 | struct dlm_lock_resource *res) | ||
659 | { | ||
660 | assert_spin_locked(&res->spinlock); | ||
642 | 661 | ||
643 | if (!test_bit(dlm->node_num, res->refmap)) { | 662 | if (!test_bit(dlm->node_num, res->refmap)) { |
644 | BUG_ON(res->inflight_locks != 0); | 663 | BUG_ON(res->inflight_locks != 0); |
645 | dlm_lockres_set_refmap_bit(dlm->node_num, res); | 664 | dlm_lockres_set_refmap_bit(dlm, res, dlm->node_num); |
646 | } | 665 | } |
647 | res->inflight_locks++; | 666 | res->inflight_locks++; |
648 | mlog(0, "%s:%.*s: inflight++: now %u\n", | 667 | mlog(0, "%s: res %.*s, inflight++: now %u, %ps()\n", dlm->name, |
649 | dlm->name, res->lockname.len, res->lockname.name, | 668 | res->lockname.len, res->lockname.name, res->inflight_locks, |
650 | res->inflight_locks); | 669 | __builtin_return_address(0)); |
651 | } | 670 | } |
652 | 671 | ||
653 | void __dlm_lockres_drop_inflight_ref(struct dlm_ctxt *dlm, | 672 | void dlm_lockres_drop_inflight_ref(struct dlm_ctxt *dlm, |
654 | struct dlm_lock_resource *res, | 673 | struct dlm_lock_resource *res) |
655 | const char *file, | ||
656 | int line) | ||
657 | { | 674 | { |
658 | assert_spin_locked(&res->spinlock); | 675 | assert_spin_locked(&res->spinlock); |
659 | 676 | ||
660 | BUG_ON(res->inflight_locks == 0); | 677 | BUG_ON(res->inflight_locks == 0); |
678 | |||
661 | res->inflight_locks--; | 679 | res->inflight_locks--; |
662 | mlog(0, "%s:%.*s: inflight--: now %u\n", | 680 | mlog(0, "%s: res %.*s, inflight--: now %u, %ps()\n", dlm->name, |
663 | dlm->name, res->lockname.len, res->lockname.name, | 681 | res->lockname.len, res->lockname.name, res->inflight_locks, |
664 | res->inflight_locks); | 682 | __builtin_return_address(0)); |
683 | |||
665 | if (res->inflight_locks == 0) | 684 | if (res->inflight_locks == 0) |
666 | dlm_lockres_clear_refmap_bit(dlm->node_num, res); | 685 | dlm_lockres_clear_refmap_bit(dlm, res, dlm->node_num); |
667 | wake_up(&res->wq); | 686 | wake_up(&res->wq); |
668 | } | 687 | } |
669 | 688 | ||
@@ -843,8 +862,10 @@ lookup: | |||
843 | 862 | ||
844 | /* finally add the lockres to its hash bucket */ | 863 | /* finally add the lockres to its hash bucket */ |
845 | __dlm_insert_lockres(dlm, res); | 864 | __dlm_insert_lockres(dlm, res); |
846 | /* since this lockres is new it doesn't not require the spinlock */ | 865 | |
847 | dlm_lockres_grab_inflight_ref_new(dlm, res); | 866 | spin_lock(&res->spinlock); |
867 | dlm_lockres_grab_inflight_ref(dlm, res); | ||
868 | spin_unlock(&res->spinlock); | ||
848 | 869 | ||
849 | /* if this node does not become the master make sure to drop | 870 | /* if this node does not become the master make sure to drop |
850 | * this inflight reference below */ | 871 | * this inflight reference below */ |
@@ -1426,9 +1447,7 @@ way_up_top: | |||
1426 | } | 1447 | } |
1427 | 1448 | ||
1428 | if (res->owner == dlm->node_num) { | 1449 | if (res->owner == dlm->node_num) { |
1429 | mlog(0, "%s:%.*s: setting bit %u in refmap\n", | 1450 | dlm_lockres_set_refmap_bit(dlm, res, request->node_idx); |
1430 | dlm->name, namelen, name, request->node_idx); | ||
1431 | dlm_lockres_set_refmap_bit(request->node_idx, res); | ||
1432 | spin_unlock(&res->spinlock); | 1451 | spin_unlock(&res->spinlock); |
1433 | response = DLM_MASTER_RESP_YES; | 1452 | response = DLM_MASTER_RESP_YES; |
1434 | if (mle) | 1453 | if (mle) |
@@ -1493,10 +1512,8 @@ way_up_top: | |||
1493 | * go back and clean the mles on any | 1512 | * go back and clean the mles on any |
1494 | * other nodes */ | 1513 | * other nodes */ |
1495 | dispatch_assert = 1; | 1514 | dispatch_assert = 1; |
1496 | dlm_lockres_set_refmap_bit(request->node_idx, res); | 1515 | dlm_lockres_set_refmap_bit(dlm, res, |
1497 | mlog(0, "%s:%.*s: setting bit %u in refmap\n", | 1516 | request->node_idx); |
1498 | dlm->name, namelen, name, | ||
1499 | request->node_idx); | ||
1500 | } else | 1517 | } else |
1501 | response = DLM_MASTER_RESP_NO; | 1518 | response = DLM_MASTER_RESP_NO; |
1502 | } else { | 1519 | } else { |
@@ -1702,7 +1719,7 @@ again: | |||
1702 | "lockres, set the bit in the refmap\n", | 1719 | "lockres, set the bit in the refmap\n", |
1703 | namelen, lockname, to); | 1720 | namelen, lockname, to); |
1704 | spin_lock(&res->spinlock); | 1721 | spin_lock(&res->spinlock); |
1705 | dlm_lockres_set_refmap_bit(to, res); | 1722 | dlm_lockres_set_refmap_bit(dlm, res, to); |
1706 | spin_unlock(&res->spinlock); | 1723 | spin_unlock(&res->spinlock); |
1707 | } | 1724 | } |
1708 | } | 1725 | } |
@@ -2256,7 +2273,7 @@ int dlm_deref_lockres_handler(struct o2net_msg *msg, u32 len, void *data, | |||
2256 | else { | 2273 | else { |
2257 | BUG_ON(res->state & DLM_LOCK_RES_DROPPING_REF); | 2274 | BUG_ON(res->state & DLM_LOCK_RES_DROPPING_REF); |
2258 | if (test_bit(node, res->refmap)) { | 2275 | if (test_bit(node, res->refmap)) { |
2259 | dlm_lockres_clear_refmap_bit(node, res); | 2276 | dlm_lockres_clear_refmap_bit(dlm, res, node); |
2260 | cleared = 1; | 2277 | cleared = 1; |
2261 | } | 2278 | } |
2262 | } | 2279 | } |
@@ -2316,7 +2333,7 @@ static void dlm_deref_lockres_worker(struct dlm_work_item *item, void *data) | |||
2316 | BUG_ON(res->state & DLM_LOCK_RES_DROPPING_REF); | 2333 | BUG_ON(res->state & DLM_LOCK_RES_DROPPING_REF); |
2317 | if (test_bit(node, res->refmap)) { | 2334 | if (test_bit(node, res->refmap)) { |
2318 | __dlm_wait_on_lockres_flags(res, DLM_LOCK_RES_SETREF_INPROG); | 2335 | __dlm_wait_on_lockres_flags(res, DLM_LOCK_RES_SETREF_INPROG); |
2319 | dlm_lockres_clear_refmap_bit(node, res); | 2336 | dlm_lockres_clear_refmap_bit(dlm, res, node); |
2320 | cleared = 1; | 2337 | cleared = 1; |
2321 | } | 2338 | } |
2322 | spin_unlock(&res->spinlock); | 2339 | spin_unlock(&res->spinlock); |
@@ -2798,7 +2815,8 @@ static void dlm_remove_nonlocal_locks(struct dlm_ctxt *dlm, | |||
2798 | BUG_ON(!list_empty(&lock->bast_list)); | 2815 | BUG_ON(!list_empty(&lock->bast_list)); |
2799 | BUG_ON(lock->ast_pending); | 2816 | BUG_ON(lock->ast_pending); |
2800 | BUG_ON(lock->bast_pending); | 2817 | BUG_ON(lock->bast_pending); |
2801 | dlm_lockres_clear_refmap_bit(lock->ml.node, res); | 2818 | dlm_lockres_clear_refmap_bit(dlm, res, |
2819 | lock->ml.node); | ||
2802 | list_del_init(&lock->list); | 2820 | list_del_init(&lock->list); |
2803 | dlm_lock_put(lock); | 2821 | dlm_lock_put(lock); |
2804 | /* In a normal unlock, we would have added a | 2822 | /* In a normal unlock, we would have added a |
@@ -2819,7 +2837,7 @@ static void dlm_remove_nonlocal_locks(struct dlm_ctxt *dlm, | |||
2819 | mlog(0, "%s:%.*s: node %u had a ref to this " | 2837 | mlog(0, "%s:%.*s: node %u had a ref to this " |
2820 | "migrating lockres, clearing\n", dlm->name, | 2838 | "migrating lockres, clearing\n", dlm->name, |
2821 | res->lockname.len, res->lockname.name, bit); | 2839 | res->lockname.len, res->lockname.name, bit); |
2822 | dlm_lockres_clear_refmap_bit(bit, res); | 2840 | dlm_lockres_clear_refmap_bit(dlm, res, bit); |
2823 | } | 2841 | } |
2824 | bit++; | 2842 | bit++; |
2825 | } | 2843 | } |
@@ -2933,7 +2951,7 @@ static int dlm_do_migrate_request(struct dlm_ctxt *dlm, | |||
2933 | dlm->name, res->lockname.len, res->lockname.name, | 2951 | dlm->name, res->lockname.len, res->lockname.name, |
2934 | nodenum); | 2952 | nodenum); |
2935 | spin_lock(&res->spinlock); | 2953 | spin_lock(&res->spinlock); |
2936 | dlm_lockres_set_refmap_bit(nodenum, res); | 2954 | dlm_lockres_set_refmap_bit(dlm, res, nodenum); |
2937 | spin_unlock(&res->spinlock); | 2955 | spin_unlock(&res->spinlock); |
2938 | } | 2956 | } |
2939 | } | 2957 | } |
@@ -3267,7 +3285,7 @@ int dlm_finish_migration(struct dlm_ctxt *dlm, struct dlm_lock_resource *res, | |||
3267 | * mastery reference here since old_master will briefly have | 3285 | * mastery reference here since old_master will briefly have |
3268 | * a reference after the migration completes */ | 3286 | * a reference after the migration completes */ |
3269 | spin_lock(&res->spinlock); | 3287 | spin_lock(&res->spinlock); |
3270 | dlm_lockres_set_refmap_bit(old_master, res); | 3288 | dlm_lockres_set_refmap_bit(dlm, res, old_master); |
3271 | spin_unlock(&res->spinlock); | 3289 | spin_unlock(&res->spinlock); |
3272 | 3290 | ||
3273 | mlog(0, "now time to do a migrate request to other nodes\n"); | 3291 | mlog(0, "now time to do a migrate request to other nodes\n"); |