Skip to contentSkip to conversation

dlm: don't kref_init rsb created for toss list

PATCH In review Alexander Aring 1 participant 11 messages Apr 23, 2024 – Apr 25, 2024 Distributed lock manager (DLM)

lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

PATCH 1/10 dlm: don't kref_init rsb created for toss list

This patch removes a kref_init() that isn't necessary because the rsb is created for toss list. Under toss list the rsb should not have any reference counting logic. If in theory the rsb gets to into keep list then a kref_init() for res_ref will be initiated.

---
 fs/dlm/lock.c | 1 -
 1 file changed, 1 deletion(-)
fs/dlm/lock.c +0 -1
index f103b8c30592..e66972ed97b1 100644
@@ -1385,7 +1385,6 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name,
 	r->res_dir_nodeid = our_nodeid;
 	r->res_master_nodeid = from_nodeid;
 	r->res_nodeid = from_nodeid;
-	kref_init(&r->res_ref);
 	rsb_set_flag(r, RSB_TOSS);
 
 	write_lock_bh(&ls->ls_rsbtbl_lock);
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 2/10 dlm: remove unused parameter in dlm_midcomms_addr

This patch removes an parameter which is currently not used by dlm_midcomms_addr().

---
 fs/dlm/config.c   | 2 +-
 fs/dlm/lowcomms.c | 2 +-
 fs/dlm/lowcomms.h | 2 +-
 fs/dlm/midcomms.c | 4 ++--
 fs/dlm/midcomms.h | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)
fs/dlm/config.c +1 -1
index 517fa975dc5a..99952234799e 100644
@@ -672,7 +672,7 @@ static ssize_t comm_addr_store(struct config_item *item, const char *buf,
 
 	memcpy(addr, buf, len);
 
-	rv = dlm_midcomms_addr(cm->nodeid, addr, len);
+	rv = dlm_midcomms_addr(cm->nodeid, addr);
 	if (rv) {
 		kfree(addr);
 		return rv;
fs/dlm/lowcomms.c +1 -1
index 6b8078085e56..591385701c7d 100644
@@ -461,7 +461,7 @@ static bool dlm_lowcomms_con_has_addr(const struct connection *con,
 	return false;
 }
 
-int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr, int len)
+int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr)
 {
 	struct connection *con;
 	bool ret, idx;
fs/dlm/lowcomms.h +1 -1
index 8deb16f8f620..fd0df604eb93 100644
@@ -46,7 +46,7 @@ void dlm_lowcomms_put_msg(struct dlm_msg *msg);
 int dlm_lowcomms_resend_msg(struct dlm_msg *msg);
 int dlm_lowcomms_connect_node(int nodeid);
 int dlm_lowcomms_nodes_set_mark(int nodeid, unsigned int mark);
-int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr, int len);
+int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr);
 void dlm_midcomms_receive_done(int nodeid);
 struct kmem_cache *dlm_lowcomms_writequeue_cache_create(void);
 struct kmem_cache *dlm_lowcomms_msg_cache_create(void);
fs/dlm/midcomms.c +2 -2
index c34f38e9ee5c..2c101bbe261a 100644
@@ -334,12 +334,12 @@ static struct midcomms_node *nodeid2node(int nodeid)
 	return __find_node(nodeid, nodeid_hash(nodeid));
 }
 
-int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr, int len)
+int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr)
 {
 	int ret, idx, r = nodeid_hash(nodeid);
 	struct midcomms_node *node;
 
-	ret = dlm_lowcomms_addr(nodeid, addr, len);
+	ret = dlm_lowcomms_addr(nodeid, addr);
 	if (ret)
 		return ret;
 
fs/dlm/midcomms.h +1 -1
index 278d26fdeb2c..7fad1d170bba 100644
@@ -19,7 +19,7 @@ int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int buflen);
 struct dlm_mhandle *dlm_midcomms_get_mhandle(int nodeid, int len, char **ppc);
 void dlm_midcomms_commit_mhandle(struct dlm_mhandle *mh, const void *name,
 				 int namelen);
-int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr, int len);
+int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr);
 void dlm_midcomms_version_wait(void);
 int dlm_midcomms_close(int nodeid);
 int dlm_midcomms_start(void);
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 3/10 dlm: make dlm_our_nodeid read mostly

In reply to Alexander Aring

The dlm_our_nodeid global variable is used a lot in the DLM stack code to check nodeids with ourself. It is only set once before DLM stack get started. This patch marks it __read_mostly that does certain cache aligned etc. to have a fast access to the variable. The function dlm_our_nodeid() will be replaced by a macro to redirect to the global dlm_our_nodeid variable.

---
 fs/dlm/config.c | 14 +++++++-------
 fs/dlm/config.h |  3 ++-
 2 files changed, 9 insertions(+), 8 deletions(-)
fs/dlm/config.c +7 -7
index 99952234799e..1d5a75d23abe 100644
@@ -33,6 +33,7 @@
  * The <cluster> level is useless, but I haven't figured out how to avoid it.
  */
 
+unsigned int dlm_our_nodeid __read_mostly;
 static struct config_group *space_list;
 static struct config_group *comm_list;
 static struct dlm_comm *local_comm;
@@ -538,8 +539,10 @@ static struct config_item *make_comm(struct config_group *g, const char *name)
 static void drop_comm(struct config_group *g, struct config_item *i)
 {
 	struct dlm_comm *cm = config_item_to_comm(i);
-	if (local_comm == cm)
+	if (local_comm == cm) {
+		dlm_our_nodeid = 0;
 		local_comm = NULL;
+	}
 	dlm_midcomms_close(cm->nodeid);
 	while (cm->addr_count--)
 		kfree(cm->addr[cm->addr_count]);
@@ -648,8 +651,10 @@ static ssize_t comm_local_store(struct config_item *item, const char *buf,
 
 	if (rc)
 		return rc;
-	if (cm->local && !local_comm)
+	if (cm->local && !local_comm) {
+		dlm_our_nodeid = cm->nodeid;
 		local_comm = cm;
+	}
 	return len;
 }
 
@@ -926,11 +931,6 @@ int dlm_comm_seq(int nodeid, uint32_t *seq)
 	return 0;
 }
 
-int dlm_our_nodeid(void)
-{
-	return local_comm ? local_comm->nodeid : 0;
-}
-
 /* num 0 is first addr, num 1 is second addr */
 int dlm_our_addr(struct sockaddr_storage *addr, int num)
 {
fs/dlm/config.h +2 -1
index ed237d910208..ff0dd13e4457 100644
@@ -21,6 +21,7 @@ struct dlm_config_node {
 	uint32_t comm_seq;
 };
 
+extern unsigned int dlm_our_nodeid __read_mostly;
 extern const struct rhashtable_params dlm_rhash_rsb_params;
 
 #define DLM_MAX_ADDR_COUNT 3
@@ -51,7 +52,7 @@ void dlm_config_exit(void);
 int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,
 		     int *count_out);
 int dlm_comm_seq(int nodeid, uint32_t *seq);
-int dlm_our_nodeid(void);
+#define dlm_our_nodeid() (dlm_our_nodeid)
 int dlm_our_addr(struct sockaddr_storage *addr, int num);
 
 #endif				/* __CONFIG_DOT_H__ */
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH 4/10 dlm: remove ls_local_handle from struct dlm_ls

In reply to Alexander Aring

This patch removes ls_local_handle from struct dlm_ls as it stores the ls pointer of the top level structure itesef and this isn't necessary. There is a lookup functionality to lookup the lockspace in dlm_find_lockspace_local() but the given input parameter is the pointer already. This might be more safe to lookup a lockspace but given a wrong lockspace pointer is a bug in the code and we save the additional lookup here. The dlm_ls structure can be still hidden by using dlm_lockspace_t handle pointer.

---
 fs/dlm/dlm_internal.h |  1 -
 fs/dlm/lockspace.c    | 16 +++-------------
 fs/dlm/user.c         |  4 ++--
 3 files changed, 5 insertions(+), 16 deletions(-)
fs/dlm/dlm_internal.h +0 -1
index 9085ba3b2f20..47e73d9838fd 100644
@@ -568,7 +568,6 @@ struct rcom_lock {
 
 struct dlm_ls {
 	struct list_head	ls_list;	/* list of lockspaces */
-	dlm_lockspace_t		*ls_local_handle;
 	uint32_t		ls_global_id;	/* global unique lockspace ID */
 	uint32_t		ls_generation;
 	uint32_t		ls_exflags;
fs/dlm/lockspace.c +3 -13
index ed23787271b1..21d8572c39c5 100644
@@ -38,7 +38,7 @@ static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len)
 
 	if (rc)
 		return rc;
-	ls = dlm_find_lockspace_local(ls->ls_local_handle);
+	ls = dlm_find_lockspace_local(ls);
 	if (!ls)
 		return -EINVAL;
 
@@ -265,18 +265,9 @@ struct dlm_ls *dlm_find_lockspace_global(uint32_t id)
 
 struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace)
 {
-	struct dlm_ls *ls;
+	struct dlm_ls *ls = lockspace;
 
-	spin_lock_bh(&lslist_lock);
-	list_for_each_entry(ls, &lslist, ls_list) {
-		if (ls->ls_local_handle == lockspace) {
-			atomic_inc(&ls->ls_count);
-			goto out;
-		}
-	}
-	ls = NULL;
- out:
-	spin_unlock_bh(&lslist_lock);
+	atomic_inc(&ls->ls_count);
 	return ls;
 }
 
@@ -495,7 +486,6 @@ static int new_lockspace(const char *name, const char *cluster,
 	idr_init(&ls->ls_recover_idr);
 	spin_lock_init(&ls->ls_recover_idr_lock);
 	ls->ls_recover_list_count = 0;
-	ls->ls_local_handle = ls;
 	init_waitqueue_head(&ls->ls_wait_general);
 	INIT_LIST_HEAD(&ls->ls_masters_list);
 	rwlock_init(&ls->ls_masters_lock);
fs/dlm/user.c +2 -2
index 3173b974e8c8..f6635a5314f4 100644
@@ -454,7 +454,7 @@ static int device_remove_lockspace(struct dlm_lspace_params *params)
 	if (params->flags & DLM_USER_LSFLG_FORCEFREE)
 		force = 2;
 
-	lockspace = ls->ls_local_handle;
+	lockspace = ls;
 	dlm_put_lockspace(ls);
 
 	/* The final dlm_release_lockspace waits for references to go to
@@ -657,7 +657,7 @@ static int device_open(struct inode *inode, struct file *file)
 		return -ENOMEM;
 	}
 
-	proc->lockspace = ls->ls_local_handle;
+	proc->lockspace = ls;
 	INIT_LIST_HEAD(&proc->asts);
 	INIT_LIST_HEAD(&proc->locks);
 	INIT_LIST_HEAD(&proc->unlocking);
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH 5/10 dlm: drop own rsb pre allocation mechanism

In reply to Alexander Aring

This patch drops the own written rsb pre allocation mechanism as this is already done by using kmem caches, we don't need another layer on top of that to running some pre allocation scheme.

---
 fs/dlm/dlm_internal.h |  9 +----
 fs/dlm/lock.c         | 92 ++++++-------------------------------------
 fs/dlm/lockspace.c    | 11 ------
 3 files changed, 13 insertions(+), 99 deletions(-)
fs/dlm/dlm_internal.h +1 -8
index 47e73d9838fd..5600365684ef 100644
@@ -322,10 +322,7 @@ struct dlm_rsb {
 	unsigned long		res_toss_time;
 	uint32_t		res_first_lkid;
 	struct list_head	res_lookup;	/* lkbs waiting on first */
-	union {
-		struct list_head	res_hashchain;
-		struct rhash_head	res_node; /* rsbtbl */
-	};
+	struct rhash_head	res_node;	/* rsbtbl */
 	struct list_head	res_grantqueue;
 	struct list_head	res_convertqueue;
 	struct list_head	res_waitqueue;
@@ -604,10 +601,6 @@ struct dlm_ls {
 	spinlock_t		ls_orphans_lock;
 	struct list_head	ls_orphans;
 
-	spinlock_t		ls_new_rsb_spin;
-	int			ls_new_rsb_count;
-	struct list_head	ls_new_rsb;	/* new rsb structs */
-
 	struct list_head	ls_nodes;	/* current nodes in ls */
 	struct list_head	ls_nodes_gone;	/* dead node list, recovery */
 	int			ls_num_nodes;	/* number of nodes in ls */
fs/dlm/lock.c +12 -80

177 lines not on this page · raw message

fs/dlm/lockspace.c +0 -11
index 21d8572c39c5..c4d4c53e5897 100644
@@ -429,9 +429,6 @@ static int new_lockspace(const char *name, const char *cluster,
 	INIT_LIST_HEAD(&ls->ls_orphans);
 	spin_lock_init(&ls->ls_orphans_lock);
 
-	INIT_LIST_HEAD(&ls->ls_new_rsb);
-	spin_lock_init(&ls->ls_new_rsb_spin);
-
 	INIT_LIST_HEAD(&ls->ls_nodes);
 	INIT_LIST_HEAD(&ls->ls_nodes_gone);
 	ls->ls_num_nodes = 0;
@@ -687,7 +684,6 @@ static void rhash_free_rsb(void *ptr, void *arg)
 
 static int release_lockspace(struct dlm_ls *ls, int force)
 {
-	struct dlm_rsb *rsb;
 	int busy, rv;
 
 	busy = lockspace_busy(ls, force);
@@ -755,13 +751,6 @@ static int release_lockspace(struct dlm_ls *ls, int force)
 	 */
 	rhashtable_free_and_destroy(&ls->ls_rsbtbl, rhash_free_rsb, NULL);
 
-	while (!list_empty(&ls->ls_new_rsb)) {
-		rsb = list_first_entry(&ls->ls_new_rsb, struct dlm_rsb,
-				       res_hashchain);
-		list_del(&rsb->res_hashchain);
-		dlm_free_rsb(rsb);
-	}
-
 	/*
 	 * Free structures on any other lists
 	 */
Signature · 1 line
2.43.0
author maintainer
#5 lore raw

PATCH 6/10 dlm: using rcu to avoid rsb lookup again

In reply to Alexander Aring

This patch converts the rsb to be protected under rcu. When the rcu lock is held it cannot be freed. In combination with the new introduced flag RSB_HASHED we can check if the rsb is still part of the ls_rsbtbl hashtable, it cannot be part of another table. If its still part of the ls_rsbtbl we can avoid a second dlm_search_rsb_tree() call.

---
 fs/dlm/dlm_internal.h |  2 ++
 fs/dlm/lock.c         | 64 ++++++++++++++++++++++++++++++-------------
 fs/dlm/memory.c       |  9 +++++-
 fs/dlm/recover.c      |  1 +
 4 files changed, 56 insertions(+), 20 deletions(-)
fs/dlm/dlm_internal.h +2 -0
index 5600365684ef..606d201c59f0 100644
@@ -333,6 +333,7 @@ struct dlm_rsb {
 	struct list_head	res_recover_list;   /* used for recovery */
 	struct list_head	res_toss_q_list;
 	int			res_recover_locks_count;
+	struct rcu_head		rcu;
 
 	char			*res_lvbptr;
 	char			res_name[DLM_RESNAME_MAXLEN+1];
@@ -366,6 +367,7 @@ enum rsb_flags {
 	RSB_RECOVER_GRANT,
 	RSB_RECOVER_LVB_INVAL,
 	RSB_TOSS,
+	RSB_HASHED,
 };
 
 static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag)
fs/dlm/lock.c +45 -19

142 lines not on this page · raw message

fs/dlm/memory.c +8 -1
index 15a8b1cee433..a7b994517bd8 100644
@@ -101,13 +101,20 @@ struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls)
 	return r;
 }
 
-void dlm_free_rsb(struct dlm_rsb *r)
+static void __dlm_free_rsb(struct rcu_head *rcu)
 {
+	struct dlm_rsb *r = container_of(rcu, struct dlm_rsb, rcu);
+
 	if (r->res_lvbptr)
 		dlm_free_lvb(r->res_lvbptr);
 	kmem_cache_free(rsb_cache, r);
 }
 
+void dlm_free_rsb(struct dlm_rsb *r)
+{
+	call_rcu(&r->rcu, __dlm_free_rsb);
+}
+
 struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
 {
 	struct dlm_lkb *lkb;
fs/dlm/recover.c +1 -0
index f493d5f30c58..75d44d51636a 100644
@@ -894,6 +894,7 @@ void dlm_clear_toss(struct dlm_ls *ls)
 		if (!list_empty(&r->res_toss_q_list))
 			list_del_init(&r->res_toss_q_list);
 
+		/* no rsb_clear_flag(r, RSB_HASHED) necessary */
 		free_toss_rsb(r);
 		count++;
 	}
Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH 7/10 dlm: move lkb idr to xarray datastructure

In reply to Alexander Aring

According to kernel doc idr is deprecated and xarrays should be used nowadays. This patch is moving the lkb idr implementation to xarrays.

---
 fs/dlm/dlm_internal.h |  5 ++--
 fs/dlm/lock.c         | 30 ++++++++++++----------
 fs/dlm/lockspace.c    | 60 +++++++++++++++++++++----------------------
 3 files changed, 49 insertions(+), 46 deletions(-)
fs/dlm/dlm_internal.h +3 -2
index 606d201c59f0..f262f53ec5fa 100644
@@ -37,6 +37,7 @@
 #include <linux/rhashtable.h>
 #include <linux/mutex.h>
 #include <linux/idr.h>
+#include <linux/xarray.h>
 #include <linux/ratelimit.h>
 #include <linux/uaccess.h>
 
@@ -579,8 +580,8 @@ struct dlm_ls {
 	unsigned long		ls_scan_time;
 	struct kobject		ls_kobj;
 
-	struct idr		ls_lkbidr;
-	rwlock_t		ls_lkbidr_lock;
+	struct xarray		ls_lkbxa;
+	rwlock_t		ls_lkbxa_lock;
 
 	struct rhashtable	ls_rsbtbl;
 	rwlock_t		ls_rsbtbl_lock;
fs/dlm/lock.c +16 -14
index 5b05b3a2f43a..1c170e284c31 100644
@@ -1460,11 +1460,15 @@ static void detach_lkb(struct dlm_lkb *lkb)
 }
 
 static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
-		       int start, int end)
+		       unsigned long start, unsigned long end)
 {
+	struct xa_limit limit;
 	struct dlm_lkb *lkb;
 	int rv;
 
+	limit.max = end;
+	limit.min = start;
+
 	lkb = dlm_allocate_lkb(ls);
 	if (!lkb)
 		return -ENOMEM;
@@ -1478,14 +1482,12 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
 	INIT_LIST_HEAD(&lkb->lkb_ownqueue);
 	INIT_LIST_HEAD(&lkb->lkb_rsb_lookup);
 
-	write_lock_bh(&ls->ls_lkbidr_lock);
-	rv = idr_alloc(&ls->ls_lkbidr, lkb, start, end, GFP_NOWAIT);
-	if (rv >= 0)
-		lkb->lkb_id = rv;
-	write_unlock_bh(&ls->ls_lkbidr_lock);
+	write_lock_bh(&ls->ls_lkbxa_lock);
+	rv = xa_alloc(&ls->ls_lkbxa, &lkb->lkb_id, lkb, limit, GFP_ATOMIC);
+	write_unlock_bh(&ls->ls_lkbxa_lock);
 
 	if (rv < 0) {
-		log_error(ls, "create_lkb idr error %d", rv);
+		log_error(ls, "create_lkb xa error %d", rv);
 		dlm_free_lkb(lkb);
 		return rv;
 	}
@@ -1496,18 +1498,18 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
 
 static int create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret)
 {
-	return _create_lkb(ls, lkb_ret, 1, 0);
+	return _create_lkb(ls, lkb_ret, 1, ULONG_MAX);
 }
 
 static int find_lkb(struct dlm_ls *ls, uint32_t lkid, struct dlm_lkb **lkb_ret)
 {
 	struct dlm_lkb *lkb;
 
-	read_lock_bh(&ls->ls_lkbidr_lock);
-	lkb = idr_find(&ls->ls_lkbidr, lkid);
+	read_lock_bh(&ls->ls_lkbxa_lock);
+	lkb = xa_load(&ls->ls_lkbxa, lkid);
 	if (lkb)
 		kref_get(&lkb->lkb_ref);
-	read_unlock_bh(&ls->ls_lkbidr_lock);
+	read_unlock_bh(&ls->ls_lkbxa_lock);
 
 	*lkb_ret = lkb;
 	return lkb ? 0 : -ENOENT;
@@ -1532,10 +1534,10 @@ static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb)
 	int rv;
 
 	rv = dlm_kref_put_write_lock_bh(&lkb->lkb_ref, kill_lkb,
-					&ls->ls_lkbidr_lock);
+					&ls->ls_lkbxa_lock);
 	if (rv) {
-		idr_remove(&ls->ls_lkbidr, lkid);
-		write_unlock_bh(&ls->ls_lkbidr_lock);
+		xa_erase(&ls->ls_lkbxa, lkid);
+		write_unlock_bh(&ls->ls_lkbxa_lock);
 
 		detach_lkb(lkb);
 
fs/dlm/lockspace.c +30 -30

115 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH 8/10 dlm: move recover idr to xarray datastructure

In reply to Alexander Aring

According to kdoc idr is deprecated and xarrays should be used nowadays. This patch is moving the recover idr implementation to xarray datastructure.

---
 fs/dlm/dlm_internal.h |  7 +++--
 fs/dlm/lockspace.c    |  8 +++---
 fs/dlm/recover.c      | 61 +++++++++++++++++++++++--------------------
 3 files changed, 40 insertions(+), 36 deletions(-)
fs/dlm/dlm_internal.h +3 -4
index f262f53ec5fa..aec99ccf2d0d 100644
@@ -36,7 +36,6 @@
 #include <linux/miscdevice.h>
 #include <linux/rhashtable.h>
 #include <linux/mutex.h>
-#include <linux/idr.h>
 #include <linux/xarray.h>
 #include <linux/ratelimit.h>
 #include <linux/uaccess.h>
@@ -317,7 +316,7 @@ struct dlm_rsb {
 	int			res_nodeid;
 	int			res_master_nodeid;
 	int			res_dir_nodeid;
-	int			res_id;		/* for ls_recover_idr */
+	unsigned long		res_id;		/* for ls_recover_xa */
 	uint32_t                res_lvbseq;
 	uint32_t		res_hash;
 	unsigned long		res_toss_time;
@@ -659,8 +658,8 @@ struct dlm_ls {
 	struct list_head	ls_recover_list;
 	spinlock_t		ls_recover_list_lock;
 	int			ls_recover_list_count;
-	struct idr		ls_recover_idr;
-	spinlock_t		ls_recover_idr_lock;
+	struct xarray		ls_recover_xa;
+	spinlock_t		ls_recover_xa_lock;
 	wait_queue_head_t	ls_wait_general;
 	wait_queue_head_t	ls_recover_lock_wait;
 	spinlock_t		ls_clear_proc_locks;
fs/dlm/lockspace.c +4 -4
index be33877d98fd..c50f7bb5a54c 100644
@@ -480,8 +480,8 @@ static int new_lockspace(const char *name, const char *cluster,
 
 	INIT_LIST_HEAD(&ls->ls_recover_list);
 	spin_lock_init(&ls->ls_recover_list_lock);
-	idr_init(&ls->ls_recover_idr);
-	spin_lock_init(&ls->ls_recover_idr_lock);
+	xa_init_flags(&ls->ls_recover_xa, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_BH);
+	spin_lock_init(&ls->ls_recover_xa_lock);
 	ls->ls_recover_list_count = 0;
 	init_waitqueue_head(&ls->ls_wait_general);
 	INIT_LIST_HEAD(&ls->ls_masters_list);
@@ -569,7 +569,7 @@ static int new_lockspace(const char *name, const char *cluster,
 	spin_lock_bh(&lslist_lock);
 	list_del(&ls->ls_list);
 	spin_unlock_bh(&lslist_lock);
-	idr_destroy(&ls->ls_recover_idr);
+	xa_destroy(&ls->ls_recover_xa);
 	kfree(ls->ls_recover_buf);
  out_lkbxa:
 	xa_destroy(&ls->ls_lkbxa);
@@ -735,7 +735,7 @@ static int release_lockspace(struct dlm_ls *ls, int force)
 
 	dlm_delete_debug_file(ls);
 
-	idr_destroy(&ls->ls_recover_idr);
+	xa_destroy(&ls->ls_recover_xa);
 	kfree(ls->ls_recover_buf);
 
 	/*
fs/dlm/recover.c +33 -28

146 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#8 lore raw

PATCH 9/10 dlm: merge nodeid field to master_nodeid

In reply to Alexander Aring

There is a TODO in dlm_internal.h for the dlm_rsb struct:

"remove res_nodeid and only use res_master_nodeid"

The res_nodeid and res_master_nodeid should represent the same information in a different numbers mapping. This patch tries to work on this TODO by removing res_nodeid and use res_master_nodeid only. The same applies for struct lkb with it's lkb_nodeid and lkb_master_nodeid fields. It use the new representation for those numbers and introduce backwardscompability because those representation are used for debugfs and the DLM protocol. In future we might use the new number representation for res_master_nodeid only and remove the copied value in struct lkb.

---
 fs/dlm/debug_fs.c     |  33 +++++-----
 fs/dlm/dlm_internal.h |  33 ++++++++--
 fs/dlm/lock.c         | 144 ++++++++++++++++++------------------------
 fs/dlm/lock.h         |   5 +-
 fs/dlm/lockspace.c    |   2 +-
 fs/dlm/rcom.c         |   4 +-
 fs/dlm/recover.c      |  20 ++----
 fs/dlm/recoverd.c     |   2 +-
 8 files changed, 119 insertions(+), 124 deletions(-)
fs/dlm/debug_fs.c +17 -16
index 6ab3ed4074c6..40eb1696f3b6 100644
@@ -58,9 +58,10 @@ static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
 	    lkb->lkb_status == DLM_LKSTS_WAITING)
 		seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode));
 
-	if (lkb->lkb_nodeid) {
-		if (lkb->lkb_nodeid != res->res_nodeid)
-			seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid,
+	if (lkb->lkb_master_nodeid != dlm_our_nodeid()) {
+		if (lkb->lkb_master_nodeid != res->res_master_nodeid)
+			seq_printf(s, " Remote: %3d %08x",
+				   dlm_res_nodeid(lkb->lkb_master_nodeid),
 				   lkb->lkb_remid);
 		else
 			seq_printf(s, " Master:     %08x", lkb->lkb_remid);
@@ -88,16 +89,15 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s)
 			seq_printf(s, "%c", '.');
 	}
 
-	if (res->res_nodeid > 0)
-		seq_printf(s, "\"\nLocal Copy, Master is node %d\n",
-			   res->res_nodeid);
-	else if (res->res_nodeid == 0)
-		seq_puts(s, "\"\nMaster Copy\n");
-	else if (res->res_nodeid == -1)
+
+	if (res->res_master_nodeid == 0)
 		seq_printf(s, "\"\nLooking up master (lkid %x)\n",
 			   res->res_first_lkid);
+	else if (res->res_master_nodeid == dlm_our_nodeid())
+		seq_puts(s, "\"\nMaster Copy\n");
 	else
-		seq_printf(s, "\"\nInvalid master %d\n", res->res_nodeid);
+		seq_printf(s, "\"\nLocal Copy, Master is node %d\n",
+			   res->res_master_nodeid);
 	if (seq_has_overflowed(s))
 		goto out;
 
@@ -184,7 +184,7 @@ static void print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
 
 	seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n",
 		   lkb->lkb_id,
-		   lkb->lkb_nodeid,
+		   dlm_res_nodeid(lkb->lkb_master_nodeid),
 		   lkb->lkb_remid,
 		   lkb->lkb_ownpid,
 		   (unsigned long long)xid,
@@ -194,7 +194,7 @@ static void print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
 		   lkb->lkb_grmode,
 		   lkb->lkb_rqmode,
 		   (unsigned long long)us,
-		   r->res_nodeid,
+		   dlm_res_nodeid(r->res_master_nodeid),
 		   r->res_length,
 		   r->res_name);
 }
@@ -238,7 +238,7 @@ static void print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
 
 	seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n",
 		   lkb->lkb_id,
-		   lkb->lkb_nodeid,
+		   dlm_res_nodeid(lkb->lkb_master_nodeid),
 		   lkb->lkb_remid,
 		   lkb->lkb_ownpid,
 		   (unsigned long long)xid,
@@ -265,7 +265,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s)
 
 	seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ",
 		   r,
-		   r->res_nodeid,
+		   dlm_res_nodeid(r->res_master_nodeid),
 		   r->res_first_lkid,
 		   r->res_flags,
 		   !list_empty(&r->res_root_list),
@@ -341,7 +341,7 @@ static void print_format4(struct dlm_rsb *r, struct seq_file *s)
 
 	seq_printf(s, "rsb %p %d %d %d %d %lu %lx %d ",
 		   r,
-		   r->res_nodeid,
+		   dlm_res_nodeid(r->res_master_nodeid),
 		   r->res_master_nodeid,
 		   r->res_dir_nodeid,
 		   our_nodeid,
@@ -611,7 +611,8 @@ static ssize_t waiters_read(struct file *file, char __user *userbuf,
 	list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
 		ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n",
 			       lkb->lkb_id, lkb->lkb_wait_type,
-			       lkb->lkb_nodeid, lkb->lkb_resource->res_name);
+			       dlm_res_nodeid(lkb->lkb_master_nodeid),
+			       lkb->lkb_resource->res_name);
 		if (ret >= len - pos)
 			break;
 		pos += ret;
fs/dlm/dlm_internal.h +28 -5
index aec99ccf2d0d..f2b5a61d6477 100644
@@ -253,7 +253,7 @@ struct dlm_callback {
 struct dlm_lkb {
 	struct dlm_rsb		*lkb_resource;	/* the rsb */
 	struct kref		lkb_ref;
-	int			lkb_nodeid;	/* copied from rsb */
+	unsigned int		lkb_master_nodeid;	/* copied from rsb */
 	int			lkb_ownpid;	/* pid of lock owner */
 	uint32_t		lkb_id;		/* our lock ID */
 	uint32_t		lkb_remid;	/* lock ID on remote partner */
@@ -303,18 +303,41 @@ struct dlm_lkb {
  *
  * res_nodeid is "odd": -1 is unset/invalid, zero means our_nodeid,
  * greater than zero when another nodeid.
- *
- * (TODO: remove res_nodeid and only use res_master_nodeid)
  */
 
+/* For backwards compatibility, see above.
+ * The protocol is still using res_nodeid.
+ */
+static inline int dlm_res_nodeid(unsigned int res_master_nodeid)
+{
+	if (res_master_nodeid == 0)
+		return -1;
+	else if (res_master_nodeid == dlm_our_nodeid())
+		return 0;
+	else
+		return res_master_nodeid;
+}
+
+/* For backwards compatibility, see above.
+ * The protocol is still using res_nodeid.
+ */
+static inline int dlm_res_master_nodeid(int res_nodeid)
+{
+	if (res_nodeid == -1)
+		return 0;
+	else if (res_nodeid == 0)
+		return dlm_our_nodeid();
+	else
+		return res_nodeid;
+}
+
 struct dlm_rsb {
 	struct dlm_ls		*res_ls;	/* the lockspace */
 	struct kref		res_ref;
 	spinlock_t		res_lock;
 	unsigned long		res_flags;
 	int			res_length;	/* length of rsb name */
-	int			res_nodeid;
-	int			res_master_nodeid;
+	unsigned int		res_master_nodeid;
 	int			res_dir_nodeid;
 	unsigned long		res_id;		/* for ls_recover_xa */
 	uint32_t                res_lvbseq;
fs/dlm/lock.c +61 -83

455 lines not on this page · raw message

fs/dlm/lock.h +3 -2
index 8de9dee4c058..e59161d2fe84 100644
@@ -61,13 +61,14 @@ int dlm_user_purge(struct dlm_ls *ls, struct dlm_user_proc *proc,
 int dlm_user_deadlock(struct dlm_ls *ls, uint32_t flags, uint32_t lkid);
 void dlm_clear_proc_locks(struct dlm_ls *ls, struct dlm_user_proc *proc);
 int dlm_debug_add_lkb(struct dlm_ls *ls, uint32_t lkb_id, char *name, int len,
-		      int lkb_nodeid, unsigned int lkb_flags, int lkb_status);
+		      int lkb_master_nodeid, unsigned int lkb_flags,
+		      int lkb_status);
 int dlm_debug_add_lkb_to_waiters(struct dlm_ls *ls, uint32_t lkb_id,
 				 int mstype, int to_nodeid);
 
 static inline int is_master(struct dlm_rsb *r)
 {
-	return !r->res_nodeid;
+	return r->res_master_nodeid == dlm_our_nodeid();
 }
 
 static inline void lock_rsb(struct dlm_rsb *r)
fs/dlm/lockspace.c +1 -1
index c50f7bb5a54c..20b8eb4647ed 100644
@@ -659,7 +659,7 @@ static int lockspace_busy(struct dlm_ls *ls, int force)
 		}
 	} else if (force == 1) {
 		xa_for_each(&ls->ls_lkbxa, id, lkb) {
-			if (lkb->lkb_nodeid == 0 &&
+			if (lkb->lkb_master_nodeid == dlm_our_nodeid() &&
 			    lkb->lkb_grmode != DLM_LOCK_IV) {
 				rv = 1;
 				break;
fs/dlm/rcom.c +2 -2
index be1a71a6303a..b545cd7a23cd 100644
@@ -455,8 +455,8 @@ int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb, uint64_t seq)
 	if (lkb->lkb_lvbptr)
 		len += ls->ls_lvblen;
 
-	error = create_rcom(ls, r->res_nodeid, DLM_RCOM_LOCK, len, &rc, &mh,
-			    seq);
+	error = create_rcom(ls, r->res_master_nodeid, DLM_RCOM_LOCK, len, &rc,
+			    &mh, seq);
 	if (error)
 		goto out;
 
fs/dlm/recover.c +6 -14
index 4f5b2d4eb41a..b6eda679793f 100644
@@ -408,7 +408,7 @@ static void set_lock_master(struct list_head *queue, int nodeid)
 
 	list_for_each_entry(lkb, queue, lkb_statequeue) {
 		if (!test_bit(DLM_IFL_MSTCPY_BIT, &lkb->lkb_iflags)) {
-			lkb->lkb_nodeid = nodeid;
+			lkb->lkb_master_nodeid = nodeid;
 			lkb->lkb_remid = 0;
 		}
 	}
@@ -416,9 +416,9 @@ static void set_lock_master(struct list_head *queue, int nodeid)
 
 static void set_master_lkbs(struct dlm_rsb *r)
 {
-	set_lock_master(&r->res_grantqueue, r->res_nodeid);
-	set_lock_master(&r->res_convertqueue, r->res_nodeid);
-	set_lock_master(&r->res_waitqueue, r->res_nodeid);
+	set_lock_master(&r->res_grantqueue, r->res_master_nodeid);
+	set_lock_master(&r->res_convertqueue, r->res_master_nodeid);
+	set_lock_master(&r->res_waitqueue, r->res_master_nodeid);
 }
 
 /*
@@ -455,7 +455,7 @@ static int recover_master(struct dlm_rsb *r, unsigned int *count, uint64_t seq)
 	if (is_master(r))
 		return 0;
 
-	is_removed = dlm_is_removed(ls, r->res_nodeid);
+	is_removed = dlm_is_removed(ls, r->res_master_nodeid);
 
 	if (!is_removed && !rsb_flag(r, RSB_NEW_MASTER))
 		return 0;
@@ -464,10 +464,8 @@ static int recover_master(struct dlm_rsb *r, unsigned int *count, uint64_t seq)
 	dir_nodeid = dlm_dir_nodeid(r);
 
 	if (dir_nodeid == our_nodeid) {
-		if (is_removed) {
+		if (is_removed)
 			r->res_master_nodeid = our_nodeid;
-			r->res_nodeid = 0;
-		}
 
 		/* set master of lkbs to ourself when is_removed, or to
 		   another new master which we set along with NEW_MASTER
@@ -501,14 +499,9 @@ static int recover_master(struct dlm_rsb *r, unsigned int *count, uint64_t seq)
 static int recover_master_static(struct dlm_rsb *r, unsigned int *count)
 {
 	int dir_nodeid = dlm_dir_nodeid(r);
-	int new_master = dir_nodeid;
-
-	if (dir_nodeid == dlm_our_nodeid())
-		new_master = 0;
 
 	dlm_purge_mstcpy_locks(r);
 	r->res_master_nodeid = dir_nodeid;
-	r->res_nodeid = new_master;
 	set_new_master(r);
 	(*count)++;
 	return 0;
@@ -584,7 +577,6 @@ int dlm_recover_master_reply(struct dlm_ls *ls, const struct dlm_rcom *rc)
 
 	lock_rsb(r);
 	r->res_master_nodeid = ret_nodeid;
-	r->res_nodeid = new_master;
 	set_new_master(r);
 	unlock_rsb(r);
 	recover_xa_del(r);
fs/dlm/recoverd.c +1 -1
index 17a40d1e6036..06959b128bd0 100644
@@ -34,7 +34,7 @@ static int dlm_create_masters_list(struct dlm_ls *ls)
 
 	read_lock_bh(&ls->ls_rsbtbl_lock);
 	list_for_each_entry(r, &ls->ls_keep, res_rsbs_list) {
-		if (r->res_nodeid)
+		if (r->res_master_nodeid != dlm_our_nodeid())
 			continue;
 
 		list_add(&r->res_masters_list, &ls->ls_masters_list);
Signature · 1 line
2.43.0
author maintainer
#9 lore raw

Re: [PATCH dlm/next 09/10] dlm: merge nodeid field to master_nodeid

Hi,

Quoted 151 lines · Alexander Aring

There is a TODO in dlm_internal.h for the dlm_rsb struct:

"remove res_nodeid and only use res_master_nodeid"

The res_nodeid and res_master_nodeid should represent the same information in a different numbers mapping. This patch tries to work on this TODO by removing res_nodeid and use res_master_nodeid only. The same applies for struct lkb with it's lkb_nodeid and lkb_master_nodeid fields. It use the new representation for those numbers and introduce backwardscompability because those representation are used for debugfs and the DLM protocol. In future we might use the new number representation for res_master_nodeid only and remove the copied value in struct lkb.

---
 fs/dlm/debug_fs.c     |  33 +++++-----
 fs/dlm/dlm_internal.h |  33 ++++++++--
 fs/dlm/lock.c         | 144 ++++++++++++++++++------------------------
 fs/dlm/lock.h         |   5 +-
 fs/dlm/lockspace.c    |   2 +-
 fs/dlm/rcom.c         |   4 +-
 fs/dlm/recover.c      |  20 ++----
 fs/dlm/recoverd.c     |   2 +-
 8 files changed, 119 insertions(+), 124 deletions(-)
fs/dlm/debug_fs.c +17 -16
index 6ab3ed4074c6..40eb1696f3b6 100644
@@ -58,9 +58,10 @@ static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
            lkb->lkb_status == DLM_LKSTS_WAITING)
                seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode));
 
-       if (lkb->lkb_nodeid) {
-               if (lkb->lkb_nodeid != res->res_nodeid)
-                       seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid,
+       if (lkb->lkb_master_nodeid != dlm_our_nodeid()) {
+               if (lkb->lkb_master_nodeid != res->res_master_nodeid)
+                       seq_printf(s, " Remote: %3d %08x",
+                                  dlm_res_nodeid(lkb->lkb_master_nodeid),
                                   lkb->lkb_remid);
                else
                        seq_printf(s, " Master:     %08x", lkb->lkb_remid);
@@ -88,16 +89,15 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s)
                        seq_printf(s, "%c", '.');
        }
 
-       if (res->res_nodeid > 0)
-               seq_printf(s, "\"\nLocal Copy, Master is node %d\n",
-                          res->res_nodeid);
-       else if (res->res_nodeid == 0)
-               seq_puts(s, "\"\nMaster Copy\n");
-       else if (res->res_nodeid == -1)
+
+       if (res->res_master_nodeid == 0)
                seq_printf(s, "\"\nLooking up master (lkid %x)\n",
                           res->res_first_lkid);
+       else if (res->res_master_nodeid == dlm_our_nodeid())
+               seq_puts(s, "\"\nMaster Copy\n");
        else
-               seq_printf(s, "\"\nInvalid master %d\n", res->res_nodeid);
+               seq_printf(s, "\"\nLocal Copy, Master is node %d\n",
+                          res->res_master_nodeid);
        if (seq_has_overflowed(s))
                goto out;
 
@@ -184,7 +184,7 @@ static void print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
 
        seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n",
                   lkb->lkb_id,
-                  lkb->lkb_nodeid,
+                  dlm_res_nodeid(lkb->lkb_master_nodeid),
                   lkb->lkb_remid,
                   lkb->lkb_ownpid,
                   (unsigned long long)xid,
@@ -194,7 +194,7 @@ static void print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
                   lkb->lkb_grmode,
                   lkb->lkb_rqmode,
                   (unsigned long long)us,
-                  r->res_nodeid,
+                  dlm_res_nodeid(r->res_master_nodeid),
                   r->res_length,
                   r->res_name);
 }
@@ -238,7 +238,7 @@ static void print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
 
        seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n",
                   lkb->lkb_id,
-                  lkb->lkb_nodeid,
+                  dlm_res_nodeid(lkb->lkb_master_nodeid),
                   lkb->lkb_remid,
                   lkb->lkb_ownpid,
                   (unsigned long long)xid,
@@ -265,7 +265,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s)
 
        seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ",
                   r,
-                  r->res_nodeid,
+                  dlm_res_nodeid(r->res_master_nodeid),
                   r->res_first_lkid,
                   r->res_flags,
                   !list_empty(&r->res_root_list),
@@ -341,7 +341,7 @@ static void print_format4(struct dlm_rsb *r, struct seq_file *s)
 
        seq_printf(s, "rsb %p %d %d %d %d %lu %lx %d ",
                   r,
-                  r->res_nodeid,
+                  dlm_res_nodeid(r->res_master_nodeid),
                   r->res_master_nodeid,
                   r->res_dir_nodeid,
                   our_nodeid,
@@ -611,7 +611,8 @@ static ssize_t waiters_read(struct file *file, char __user *userbuf,
        list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
                ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n",
                               lkb->lkb_id, lkb->lkb_wait_type,
-                              lkb->lkb_nodeid, lkb->lkb_resource->res_name);
+                              dlm_res_nodeid(lkb->lkb_master_nodeid),
+                              lkb->lkb_resource->res_name);
                if (ret >= len - pos)
                        break;
                pos += ret;
fs/dlm/dlm_internal.h +8 -3
index aec99ccf2d0d..f2b5a61d6477 100644
@@ -253,7 +253,7 @@ struct dlm_callback {
 struct dlm_lkb {
        struct dlm_rsb          *lkb_resource;  /* the rsb */
        struct kref             lkb_ref;
-       int                     lkb_nodeid;     /* copied from rsb */
+       unsigned int            lkb_master_nodeid;      /* copied from rsb */
        int                     lkb_ownpid;     /* pid of lock owner */
        uint32_t                lkb_id;         /* our lock ID */
        uint32_t                lkb_remid;      /* lock ID on remote partner */
@@ -303,18 +303,41 @@ struct dlm_lkb {
  *
  * res_nodeid is "odd": -1 is unset/invalid, zero means our_nodeid,
  * greater than zero when another nodeid.
- *
- * (TODO: remove res_nodeid and only use res_master_nodeid)
  */
 
+/* For backwards compatibility, see above.
+ * The protocol is still using res_nodeid.
+ */
+static inline int dlm_res_nodeid(unsigned int res_master_nodeid)
+{
+       if (res_master_nodeid == 0)
+               return -1;

fs/dlm/dlm_internal.h struct dlm_lkb { · line 324

Quoted 10 lines
fs/dlm/dlm_internal.h +10 -0
+       else if (res_master_nodeid == dlm_our_nodeid())
+               return 0;
+       else
+               return res_master_nodeid;
+}
+
+/* For backwards compatibility, see above.
+ * The protocol is still using res_nodeid.
+ */
+static inline int dlm_res_master_nodeid(int res_nodeid)

I changed this to "unsigned int", but when I would follow net/ then this needed to be __le32 as nodeid is a addressing scheme on the wire. This might be a change for future patches.

fs/dlm/dlm_internal.h struct dlm_lkb { · line 333

Quoted 9 lines
fs/dlm/dlm_internal.h +9 -0
+{
+       if (res_nodeid == -1)
+               return 0;
+       else if (res_nodeid == 0)
+               return dlm_our_nodeid();
+       else
+               return res_nodeid;
+}
+

- Alex

author maintainer
#10 lore raw

PATCH 10/10 dlm: use is_master() where it's prossible

In reply to Alexander Aring

There are numbers of checks to check if the node itself of a rsb is the master or not. There is a helper is_master() for it. This patch changes various places to use this helper.

---
 fs/dlm/lock.c     | 9 ++++-----
 fs/dlm/recoverd.c | 2 +-
 2 files changed, 5 insertions(+), 6 deletions(-)
fs/dlm/lock.c +4 -5
index 5063d3a60834..5b19c246d308 100644
@@ -242,7 +242,7 @@ static inline int is_granted(struct dlm_lkb *lkb)
 static inline int is_remote(struct dlm_rsb *r)
 {
 	DLM_ASSERT(r->res_master_nodeid != 0, dlm_print_rsb(r););
-	return r->res_master_nodeid != dlm_our_nodeid();
+	return !is_master(r);
 }
 
 static inline int is_process_copy(struct dlm_lkb *lkb)
@@ -3978,7 +3978,7 @@ static int receive_request(struct dlm_ls *ls, const struct dlm_message *ms)
 
 	lock_rsb(r);
 
-	if (r->res_master_nodeid != dlm_our_nodeid()) {
+	if (!is_master(r)) {
 		error = validate_master_nodeid(ls, r, from_nodeid);
 		if (error) {
 			unlock_rsb(r);
@@ -4400,8 +4400,7 @@ static int receive_request_reply(struct dlm_ls *ls,
 			  from_nodeid, result, r->res_master_nodeid,
 			  r->res_dir_nodeid, r->res_first_lkid, r->res_name);
 
-		if (r->res_dir_nodeid != dlm_our_nodeid() &&
-		    r->res_master_nodeid != dlm_our_nodeid()) {
+		if (r->res_dir_nodeid != dlm_our_nodeid() && !is_master(r)) {
 			/* cause _request_lock->set_master->send_lookup */
 			r->res_master_nodeid = 0;
 			lkb->lkb_master_nodeid = 0;
@@ -4415,7 +4414,7 @@ static int receive_request_reply(struct dlm_ls *ls,
 		} else {
 			_request_lock(r, lkb);
 
-			if (r->res_master_nodeid == dlm_our_nodeid())
+			if (is_master(r))
 				confirm_master(r, 0);
 		}
 		break;
fs/dlm/recoverd.c +1 -1
index 06959b128bd0..98d83f90a0db 100644
@@ -34,7 +34,7 @@ static int dlm_create_masters_list(struct dlm_ls *ls)
 
 	read_lock_bh(&ls->ls_rsbtbl_lock);
 	list_for_each_entry(r, &ls->ls_keep, res_rsbs_list) {
-		if (r->res_master_nodeid != dlm_our_nodeid())
+		if (!is_master(r))
 			continue;
 
 		list_add(&r->res_masters_list, &ls->ls_masters_list);
Signature · 1 line
2.43.0