fs: dlm: move assert into release function
Alexander Aring
maintainerPATCH 1/3 fs: dlm: move assert into release function
This patch moves the assert if unhold_lkb() hits lkb->lkb_ref zero into the release function. Instead of kill_lkb() which has an assert if lkb->lkb_status is non-zero. The assert in kill_lkb() has nothing todo with unhold a lkb and probably was only used here to call something if it it's zero. The unhold_lkb() should never release a lkb so we move the assert to the release functionality.
--- fs/dlm/lock.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/dlm/lock.c +8 -3
@@ -1310,6 +1310,13 @@ static inline void hold_lkb(struct dlm_lkb *lkb)kref_get (&lkb->lkb_ref); } +static void unhold_lkb_assert (struct kref *kref) +{ + struct dlm_lkb *lkb = container_of(kref, struct dlm_lkb, lkb_ref); + + DLM_ASSERT(false, dlm_print_lkb(lkb);); +} +/* This is called when we need to remove a reference and are certain it's not the last ref. e.g. del_lkb is always called between a find_lkb/put_lkb and is always the inverse of a previous add_lkb.
@@ -1317,9 +1324,7 @@ static inline void hold_lkb(struct dlm_lkb *lkb)static inline void unhold_lkb (struct dlm_lkb *lkb) { -int rv; - rv =kref_put (&lkb->lkb_ref, kill_lkb); - DLM_ASSERT(!rv, dlm_print_lkb(lkb);); +kref_put (&lkb->lkb_ref, unhold_lkb_assert); } static void lkb_add_ordered(struct list_head *new, struct list_head *head,
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 2/3 fs: dlm: fix context imbalance warning in __put_lkb()
This patch fixes the following sparse warning:
warning: context imbalance in '__put_lkb' - unexpected unlock
it does this by unlock the ls_lkbidr_spin lock inside of the release functionality of kref_put_lock() and do a __releases() annotation at the release function. The kref_put_lock() for __put_lkb() has a special requirement to pass an additional dlm_ls pointer to the release callback, this is done by providing an own implementation of kref_put_lock() that is named dlm_kref_put_lock() and can pass an additional parameter.
--- fs/dlm/lock.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-)
fs/dlm/lock.c +27 -19
@@ -1256,7 +1256,8 @@ static int find_lkb(struct dlm_ls *ls, uint32_t lkid, struct dlm_lkb **lkb_ret)return lkb ?0 : -ENOENT ; } -static void kill_lkb (struct kref *kref) +static void kill_lkb (struct kref *kref,struct dlm_ls *ls) + __releases(&ls->ls_lkbidr_spin) { struct dlm_lkb *lkb = container_of(kref, struct dlm_lkb, lkb_ref);
@@ -1264,6 +1265,29 @@ static void kill_lkb(struct kref *kref)can release the write_lock before the detach_lkb */ DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); + +idr_remove (&ls->ls_lkbidr, lkb->lkb_id); +spin_unlock (&ls->ls_lkbidr_spin); + +detach_lkb (lkb); + +/* for local/process lkbs, lvbptr points to caller's lksb */ +if (lkb->lkb_lvbptr &&is_master_copy (lkb)) +dlm_free_lvb (lkb->lkb_lvbptr); +dlm_free_lkb (lkb); +} + +static inline int dlm_kref_put_lock (struct kref *kref, +void (*release)(struct kref *kref, +struct dlm_ls *ls), +spinlock_t *lock, +struct dlm_ls *ls) +{ +if (refcount_dec_and_lock (&kref->refcount, lock)) { +release (kref, ls); +return 1 ; + } +return 0 ; }/* __put_lkb() is used when an lkb may not have an rsb attached to
@@ -1271,24 +1295,8 @@ static void kill_lkb(struct kref *kref)static int __put_lkb (struct dlm_ls *ls,struct dlm_lkb *lkb) { -uint32_t lkid = lkb->lkb_id; -int rv; - - rv =kref_put_lock (&lkb->lkb_ref, kill_lkb, - &ls->ls_lkbidr_spin); -if (rv) { -idr_remove (&ls->ls_lkbidr, lkid); -spin_unlock (&ls->ls_lkbidr_spin); - -detach_lkb (lkb); - -/* for local/process lkbs, lvbptr points to caller's lksb */ -if (lkb->lkb_lvbptr &&is_master_copy (lkb)) -dlm_free_lvb (lkb->lkb_lvbptr); -dlm_free_lkb (lkb); - } - -return rv; +return dlm_kref_put_lock (&lkb->lkb_ref, kill_lkb, + &ls->ls_lkbidr_spin, ls); }int dlm_put_lkb (struct dlm_lkb *lkb)
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 3/3 fs: dlm: fix context imbalance warning in put_rsb()
In reply to Alexander AringThis patch fixes the following sparse warning:
warning: context imbalance in 'put_rsb' - unexpected unlock
it does this by unlock the ls_rsbtbl[bucket].lock lock inside of the release functionality of kref_put_lock() and do a __releases() annotation at the release function.
--- fs/dlm/lock.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
fs/dlm/lock.c +9 -8
@@ -352,12 +352,9 @@ static void put_rsb(struct dlm_rsb *r) {struct dlm_ls *ls = r->res_ls;uint32_t bucket = r->res_bucket; -int rv; - rv =kref_put_lock (&r->res_ref, toss_rsb, - &ls->ls_rsbtbl[bucket].lock); -if (rv) -spin_unlock (&ls->ls_rsbtbl[bucket].lock); +kref_put_lock (&r->res_ref, toss_rsb, + &ls->ls_rsbtbl[bucket].lock); }void dlm_put_rsb (struct dlm_rsb *r)
@@ -1140,20 +1137,24 @@ void dlm_dump_rsb_name(struct dlm_ls *ls, char *name, int len) }static void toss_rsb (struct kref *kref) + __releases(&ls->ls_rsbtbl[bucket].lock) { struct dlm_rsb *r = container_of(kref, struct dlm_rsb, res_ref); +uint32_t bucket = r->res_bucket;struct dlm_ls *ls = r->res_ls; DLM_ASSERT(list_empty(&r->res_root_list), dlm_print_rsb(r););kref_init (&r->res_ref); -rb_erase (&r->res_hashnode, &ls->ls_rsbtbl[r->res_bucket].keep); -rsb_insert (r, &ls->ls_rsbtbl[r->res_bucket].toss); +rb_erase (&r->res_hashnode, &ls->ls_rsbtbl[bucket].keep); +rsb_insert (r, &ls->ls_rsbtbl[bucket].toss); r->res_toss_time = jiffies; - ls->ls_rsbtbl[r->res_bucket].flags |=DLM_RTF_SHRINK ; + ls->ls_rsbtbl[bucket].flags |=DLM_RTF_SHRINK ;if (r->res_lvbptr) {dlm_free_lvb (r->res_lvbptr); r->res_lvbptr =NULL ; } + +spin_unlock (&ls->ls_rsbtbl[bucket].lock); }/* See comment for unhold_lkb */
Signature · 1 line
2.31.1