dlm: remove scand leftovers
Alexander Aring
maintainerPATCH 1/11 dlm: remove scand leftovers
This patch removes some leftover related code from dlm_scand that was dropped in commit b1f2381c1a8d ("dlm: drop dlm_scand kthread and use timers").
--- fs/dlm/dlm_internal.h | 8 -------- fs/dlm/lockspace.c | 1 - 2 files changed, 9 deletions(-)
fs/dlm/dlm_internal.h +0 -8
@@ -559,13 +559,6 @@ struct rcom_lock {char rl_lvb[]; }; -/* -* The max number of resources per rsbtbl bucket that shrink will attempt -* to remove in each iteration. -*/ - -#define DLM_REMOVE_NAMES_MAX 8 -struct dlm_ls {struct list_head ls_list;/* list of lockspaces */ dlm_lockspace_t *ls_local_handle;
@@ -578,7 +571,6 @@ struct dlm_ls {wait_queue_head_t ls_count_wait;int ls_create_count;/* create/release refcount */ unsigned long ls_flags;/* LSFL_ */ -unsigned long ls_scan_time;struct kobject ls_kobj;struct idr ls_lkbidr;
fs/dlm/lockspace.c +0 -1
@@ -410,7 +410,6 @@ static int new_lockspace(const char *name, const char *cluster,atomic_set (&ls->ls_count,0 );init_waitqueue_head (&ls->ls_count_wait); ls->ls_flags =0 ; - ls->ls_scan_time = jiffies;if (ops && dlm_config.ci_recover_callbacks) { ls->ls_ops = ops;
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 2/11 dlm: don't kref_init rsbs 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
@@ -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
Alexander Aring
maintainerPATCH 3/11 dlm: remove unused parameter in dlm_midcomms_addr
In reply to Alexander AringThis 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Alexander Aring
maintainerPATCH 4/11 dlm: remove ls_local_handle from struct dlm_ls
In reply to Alexander AringThis 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
@@ -561,7 +561,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
@@ -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; }
@@ -496,7 +487,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
@@ -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
Alexander Aring
maintainerPATCH 5/11 dlm: rename dlm_find_lockspace_local to dlm_get_lockspace
In reply to Alexander AringPrevious patch got rid of the unnecessary loop to lookup the lockspace pointer but the pointer to lookup was already the pointer that was looking for. The purpose of dlm_find_lockspace_local() is more a dlm_get_lockspace() to avoid lockspace releases. There is another question if dlm_get_lockspace() is really necessary to call as it is called in a lockspace resource itself and during this time the lockspace cannot be freed as it is used by e.g. udev. Another questionable current handling is refcounting when calling dlm api that might be an DLM user problem because calling dlm_lockspace_release() when there are still pending API calls around. However this might need more of a full code review in future to remove some of them.
--- fs/dlm/lock.c | 4 ++-- fs/dlm/lockspace.c | 8 ++++---- fs/dlm/lockspace.h | 2 +- fs/dlm/plock.c | 8 ++++---- fs/dlm/recoverd.c | 4 ++-- fs/dlm/user.c | 12 ++++++------ 6 files changed, 19 insertions(+), 19 deletions(-)
fs/dlm/lock.c +2 -2
@@ -3391,7 +3391,7 @@ int dlm_lock(dlm_lockspace_t *lockspace,struct dlm_args args;int error, convert = flags &DLM_LKF_CONVERT ; - ls =dlm_find_lockspace_local (lockspace); + ls =dlm_get_lockspace (lockspace);if (!ls)return -EINVAL ;
@@ -3443,7 +3443,7 @@ int dlm_unlock(dlm_lockspace_t *lockspace,struct dlm_args args;int error; - ls =dlm_find_lockspace_local (lockspace); + ls =dlm_get_lockspace (lockspace);if (!ls)return -EINVAL ;
fs/dlm/lockspace.c +4 -4
@@ -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 =dlm_get_lockspace (ls);if (!ls)return -EINVAL ;
@@ -263,7 +263,7 @@ struct dlm_ls *dlm_find_lockspace_global(uint32_t id)return ls; } -struct dlm_ls *dlm_find_lockspace_local (dlm_lockspace_t *lockspace) +struct dlm_ls *dlm_get_lockspace (dlm_lockspace_t *lockspace) {struct dlm_ls *ls = lockspace;
@@ -794,12 +794,12 @@ static int release_lockspace(struct dlm_ls *ls, int force)* 3 - destroy lockspace as part of a forced shutdown */ -int dlm_release_lockspace (void *lockspace,int force) +int dlm_release_lockspace (dlm_lockspace_t *lockspace,int force) {struct dlm_ls *ls;int error; - ls =dlm_find_lockspace_local (lockspace); + ls =dlm_get_lockspace (lockspace);if (!ls)return -EINVAL ;dlm_put_lockspace (ls);
fs/dlm/lockspace.h +1 -1
@@ -23,7 +23,7 @@int dlm_lockspace_init (void );void dlm_lockspace_exit (void );struct dlm_ls *dlm_find_lockspace_global (uint32_t id); -struct dlm_ls *dlm_find_lockspace_local (void *id); +struct dlm_ls *dlm_get_lockspace (dlm_lockspace_t *lockspace);struct dlm_ls *dlm_find_lockspace_device (int minor);void dlm_put_lockspace (struct dlm_ls *ls);void dlm_stop_lockspaces (void );
fs/dlm/plock.c +4 -4
@@ -127,7 +127,7 @@ int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file,struct plock_op *op;int rv; - ls =dlm_find_lockspace_local (lockspace); + ls =dlm_get_lockspace (lockspace);if (!ls)return -EINVAL ;
@@ -293,7 +293,7 @@ int dlm_posix_unlock(dlm_lockspace_t *lockspace, u64 number, struct file *file,int rv;unsigned char saved_flags = fl->c.flc_flags; - ls =dlm_find_lockspace_local (lockspace); + ls =dlm_get_lockspace (lockspace);if (!ls)return -EINVAL ;
@@ -370,7 +370,7 @@ int dlm_posix_cancel(dlm_lockspace_t *lockspace, u64 number, struct file *file,if (WARN_ON_ONCE (!fl->fl_lmops || !fl->fl_lmops->lm_grant))return -EOPNOTSUPP ; - ls =dlm_find_lockspace_local (lockspace); + ls =dlm_get_lockspace (lockspace);if (!ls)return -EINVAL ;
@@ -426,7 +426,7 @@ int dlm_posix_get(dlm_lockspace_t *lockspace, u64 number, struct file *file,struct plock_op *op;int rv; - ls =dlm_find_lockspace_local (lockspace); + ls =dlm_get_lockspace (lockspace);if (!ls)return -EINVAL ;
fs/dlm/recoverd.c +2 -2
@@ -389,9 +389,9 @@ static void do_ls_recovery(struct dlm_ls *ls)static int dlm_recoverd (void *arg) { -struct dlm_ls *ls; +struct dlm_ls *ls = arg; - ls =dlm_find_lockspace_local (arg); + ls =dlm_get_lockspace (arg);if (!ls) {log_print ("dlm_recoverd: no lockspace %p" , arg);return -1 ;
fs/dlm/user.c +6 -6
@@ -259,7 +259,7 @@ static int device_user_lock(struct dlm_user_proc *proc,uint32_t lkid;int error = -ENOMEM ; - ls =dlm_find_lockspace_local (proc->lockspace); + ls =dlm_get_lockspace (proc->lockspace);if (!ls)return -ENOENT ;
@@ -309,7 +309,7 @@ static int device_user_unlock(struct dlm_user_proc *proc,struct dlm_user_args *ua;int error = -ENOMEM ; - ls =dlm_find_lockspace_local (proc->lockspace); + ls =dlm_get_lockspace (proc->lockspace);if (!ls)return -ENOENT ;
@@ -337,7 +337,7 @@ static int device_user_deadlock(struct dlm_user_proc *proc,struct dlm_ls *ls;int error; - ls =dlm_find_lockspace_local (proc->lockspace); + ls =dlm_get_lockspace (proc->lockspace);if (!ls)return -ENOENT ;
@@ -398,7 +398,7 @@ static int device_user_purge(struct dlm_user_proc *proc,struct dlm_ls *ls;int error; - ls =dlm_find_lockspace_local (proc->lockspace); + ls =dlm_get_lockspace (proc->lockspace);if (!ls)return -ENOENT ;
@@ -423,7 +423,7 @@ static int device_create_lockspace(struct dlm_lspace_params *params)if (error)return error; - ls =dlm_find_lockspace_local (lockspace); + ls =dlm_get_lockspace (lockspace);if (!ls)return -ENOENT ;
@@ -674,7 +674,7 @@ static int device_close(struct inode *inode, struct file *file)struct dlm_user_proc *proc = file->private_data;struct dlm_ls *ls; - ls =dlm_find_lockspace_local (proc->lockspace); + ls =dlm_get_lockspace (proc->lockspace);if (!ls)return -ENOENT ;
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 6/11 dlm: drop own rsb pre allocation mechanism
In reply to Alexander AringThis 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
@@ -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;
@@ -596,10 +593,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
@@ -428,9 +428,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 ;
@@ -688,7 +685,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);
@@ -756,13 +752,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
Alexander Aring
maintainerPATCH 7/11 dlm: using rcu to avoid rsb lookup again
In reply to Alexander AringThis 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 +++++- 3 files changed, 55 insertions(+), 20 deletions(-)
fs/dlm/dlm_internal.h +2 -0
@@ -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
@@ -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;
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 8/11 dlm: move lkb idr to xarray datastructure
In reply to Alexander AringAccording 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
@@ -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>
@@ -571,8 +572,8 @@ struct dlm_ls {unsigned long ls_flags;/* LSFL_ */ 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
@@ -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
Alexander Aring
maintainerPATCH 9/11 dlm: move recover idr to xarray datastructure
In reply to Alexander AringAccording 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
@@ -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;
@@ -651,8 +650,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
@@ -481,8 +481,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);
@@ -570,7 +570,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);
@@ -736,7 +736,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
Alexander Aring
maintainerPATCH 10/11 dlm: merge nodeid field to master_nodeid
In reply to Alexander AringThere 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
@@ -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
@@ -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 unsigned 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
@@ -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
@@ -660,7 +660,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
@@ -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
@@ -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
@@ -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
Alexander Aring
maintainerPATCH 11/11 dlm: use is_master() where it's prossible
In reply to Alexander AringThere 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
@@ -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
@@ -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