Skip to contentSkip to conversation

fs: dlm: remove unnecessary error assign

PATCH New Alexander Aring 1 participant 3 messages May 2, 2022 Distributed lock manager (DLM)

lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

PATCH 1/3 fs: dlm: remove unnecessary error assign

This patch removes unnecessary error assigns to 0 at places we know that error is zero because it was checked on non-zero before.

---
 fs/dlm/lock.c | 3 ---
 1 file changed, 3 deletions(-)
fs/dlm/lock.c +0 -3
index d19cfa03c9bb..97ca728dc194 100644
@@ -602,7 +602,6 @@ static int find_rsb_dir(struct dlm_ls *ls, char *name, int len,
 	 */
 
 	kref_get(&r->res_ref);
-	error = 0;
 	goto out_unlock;
 
 
@@ -1091,7 +1090,6 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, char *name, int len,
 	if (result)
 		*result = DLM_LU_ADD;
 	*r_nodeid = from_nodeid;
-	error = 0;
  out_unlock:
 	spin_unlock(&ls->ls_rsbtbl[b].lock);
 	return error;
@@ -5747,7 +5745,6 @@ int dlm_recover_master_copy(struct dlm_ls *ls, struct dlm_rcom *rc)
 
 	attach_lkb(r, lkb);
 	add_lkb(r, lkb, rl->rl_status);
-	error = 0;
 	ls->ls_recover_locks_in++;
 
 	if (!list_empty(&r->res_waitqueue) || !list_empty(&r->res_convertqueue))
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 2/3 fs: dlm: use kref_put_lock in put_rsb

This patch will optimize put_rsb() by using kref_put_lock(). The function kref_put_lock() will only held the lock if the reference is going to be zero, if not the lock will never be hold.

---
 fs/dlm/lock.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/dlm/lock.c +5 -3
index 97ca728dc194..a331210434b2 100644
@@ -350,10 +350,12 @@ static void put_rsb(struct dlm_rsb *r)
 {
 	struct dlm_ls *ls = r->res_ls;
 	uint32_t bucket = r->res_bucket;
+	int rv;
 
-	spin_lock(&ls->ls_rsbtbl[bucket].lock);
-	kref_put(&r->res_ref, toss_rsb);
-	spin_unlock(&ls->ls_rsbtbl[bucket].lock);
+	rv = kref_put_lock(&r->res_ref, toss_rsb,
+			   &ls->ls_rsbtbl[bucket].lock);
+	if (rv)
+		spin_unlock(&ls->ls_rsbtbl[bucket].lock);
 }
 
 void dlm_put_rsb(struct dlm_rsb *r)
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH 3/3 fs: dlm: use kref_put_lock in __put_lkb

In reply to Alexander Aring

This patch will optimize __put_lkb() by using kref_put_lock(). The function kref_put_lock() will only held the lock if the reference is going to be zero, if not the lock will never be hold.

---
 fs/dlm/lock.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fs/dlm/lock.c +6 -6
index a331210434b2..226822f49d30 100644
@@ -1268,9 +1268,11 @@ 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;
 
-	spin_lock(&ls->ls_lkbidr_spin);
-	if (kref_put(&lkb->lkb_ref, kill_lkb)) {
+	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);
 
@@ -1280,11 +1282,9 @@ static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb)
 		if (lkb->lkb_lvbptr && is_master_copy(lkb))
 			dlm_free_lvb(lkb->lkb_lvbptr);
 		dlm_free_lkb(lkb);
-		return 1;
-	} else {
-		spin_unlock(&ls->ls_lkbidr_spin);
-		return 0;
 	}
+
+	return rv;
 }
 
 int dlm_put_lkb(struct dlm_lkb *lkb)
Signature · 1 line
2.31.1