dlm: resend list iterator patches
Alexander Aring
maintainercover dlm: resend list iterator patches
Hi,
this is a resend of Jakob Koschels list iterator patches rebased on current pending dlm patches. We had a lot of change in the plock handling of dlm.
*little change that lkb is named "big_lkb" to remain the "big lock" information in variable name of function recover_lvb(). Otherwise it should be the same.
Thanks.
- Alex
Jakob Koschel (2):
dlm: remove usage of list iterator for list_add() after the loop body
dlm: replace usage of found with dedicated list iterator variable
fs/dlm/lock.c | 65 ++++++++++++++++++++++++------------------------ fs/dlm/plock.c | 24 +++++++++--------- fs/dlm/recover.c | 39 ++++++++++++++--------------- 3 files changed, 64 insertions(+), 64 deletions(-)
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 1/2 dlm: remove usage of list iterator for list_add() after the loop body
From: Jakob Koschel <[email protected]>
In preparation to limit the scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1].
Before, the code implicitly used the head when no element was found when using &pos->list. Since the new variable is only set if an element was found, the list_add() is performed within the loop and only done after the loop if it is done on the list head directly.
--- fs/dlm/lock.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/dlm/lock.c +8 -4
@@ -1321,13 +1321,17 @@ static inline void unhold_lkb(struct dlm_lkb *lkb)static void lkb_add_ordered (struct list_head *new,struct list_head *head,int mode) { -struct dlm_lkb *lkb =NULL ; +struct dlm_lkb *lkb =NULL , *iter; -list_for_each_entry (lkb, head, lkb_statequeue) -if (lkb->lkb_rqmode < mode) +list_for_each_entry (iter, head, lkb_statequeue) +if (iter->lkb_rqmode < mode) { + lkb = iter; +list_add_tail (new, &iter->lkb_statequeue);break ; + } -__list_add (new, lkb->lkb_statequeue.prev, &lkb->lkb_statequeue); +if (!lkb) +list_add_tail (new, head); }/* add/remove lkb to rsb's grant/convert/wait queue */
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 2/2 dlm: replace usage of found with dedicated list iterator variable
In reply to Alexander AringFrom: Jakob Koschel <[email protected]>
To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body.
To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean [1].
This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit.
--- fs/dlm/lock.c | 53 +++++++++++++++++++++++------------------------- fs/dlm/plock.c | 24 +++++++++++----------- fs/dlm/recover.c | 39 +++++++++++++++++------------------ 3 files changed, 56 insertions(+), 60 deletions(-)
fs/dlm/lock.c +25 -28
@@ -1885,7 +1885,7 @@ static void del_timeout(struct dlm_lkb *lkb)void dlm_scan_timeout (struct dlm_ls *ls) {struct dlm_rsb *r; -struct dlm_lkb *lkb; +struct dlm_lkb *lkb =NULL , *iter;int do_cancel, do_warn;s64 wait_us;
@@ -1896,27 +1896,28 @@ void dlm_scan_timeout(struct dlm_ls *ls) do_cancel =0 ; do_warn =0 ;mutex_lock (&ls->ls_timeout_mutex); -list_for_each_entry (lkb, &ls->ls_timeout, lkb_time_list) { +list_for_each_entry (iter, &ls->ls_timeout, lkb_time_list) { wait_us =ktime_to_us (ktime_sub (ktime_get (), - lkb->lkb_timestamp)); + iter->lkb_timestamp)); -if ((lkb->lkb_exflags &DLM_LKF_TIMEOUT ) && - wait_us >= (lkb->lkb_timeout_cs *10000 )) +if ((iter->lkb_exflags &DLM_LKF_TIMEOUT ) && + wait_us >= (iter->lkb_timeout_cs *10000 )) do_cancel =1 ; -if ((lkb->lkb_flags &DLM_IFL_WATCH_TIMEWARN ) && +if ((iter->lkb_flags &DLM_IFL_WATCH_TIMEWARN ) && wait_us >= dlm_config.ci_timewarn_cs *10000 ) do_warn =1 ;if (!do_cancel && !do_warn)continue ; -hold_lkb (lkb); +hold_lkb (iter); + lkb = iter;break ; }mutex_unlock (&ls->ls_timeout_mutex); -if (!do_cancel && !do_warn) +if (!lkb)break ; r = lkb->lkb_resource;
@@ -5292,21 +5293,18 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls)static struct dlm_lkb *find_resend_waiter (struct dlm_ls *ls) { -struct dlm_lkb *lkb; -int found =0 ; +struct dlm_lkb *lkb =NULL , *iter;mutex_lock (&ls->ls_waiters_mutex); -list_for_each_entry (lkb, &ls->ls_waiters, lkb_wait_reply) { -if (lkb->lkb_flags &DLM_IFL_RESEND ) { -hold_lkb (lkb); - found =1 ; +list_for_each_entry (iter, &ls->ls_waiters, lkb_wait_reply) { +if (iter->lkb_flags &DLM_IFL_RESEND ) { +hold_lkb (iter); + lkb = iter;break ; } }mutex_unlock (&ls->ls_waiters_mutex); -if (!found) - lkb =NULL ;return lkb; }
@@ -5964,37 +5962,36 @@ int dlm_user_adopt_orphan(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, int mode, uint32_t flags, void *name, unsigned int namelen, unsigned long timeout_cs, uint32_t *lkid) { - struct dlm_lkb *lkb; + struct dlm_lkb *lkb = NULL, *iter;struct dlm_user_args *ua;int found_other_mode =0 ; -int found =0 ;int rv =0 ;mutex_lock (&ls->ls_orphans_mutex); -list_for_each_entry (lkb, &ls->ls_orphans, lkb_ownqueue) { -if (lkb->lkb_resource->res_length != namelen) +list_for_each_entry (iter, &ls->ls_orphans, lkb_ownqueue) { +if (iter->lkb_resource->res_length != namelen)continue ; -if (memcmp (lkb->lkb_resource->res_name, name, namelen)) +if (memcmp (iter->lkb_resource->res_name, name, namelen))continue ; -if (lkb->lkb_grmode != mode) { +if (iter->lkb_grmode != mode) { found_other_mode =1 ;continue ; } - found =1 ; -list_del_init (&lkb->lkb_ownqueue); - lkb->lkb_flags &= ~DLM_IFL_ORPHAN ; - *lkid = lkb->lkb_id; + lkb = iter; +list_del_init (&iter->lkb_ownqueue); + iter->lkb_flags &= ~DLM_IFL_ORPHAN ; + *lkid = iter->lkb_id;break ; }mutex_unlock (&ls->ls_orphans_mutex); -if (!found && found_other_mode) { +if (!lkb && found_other_mode) { rv = -EAGAIN ; goto out; } -if (!found) { +if (!lkb) { rv = -ENOENT ; goto out; }
fs/dlm/plock.c +12 -12
@@ -407,9 +407,9 @@ static ssize_t dev_read(struct file *file, char __user *u, size_t count,static ssize_t dev_write (struct file *file,const char __user *u,size_t count,loff_t *ppos) { +struct plock_op *op =NULL , *iter;struct dlm_plock_info info; -struct plock_op *op; -int found =0 , do_callback =0 ; +int do_callback =0 ;if (count !=sizeof (info))return -EINVAL ;
@@ -421,23 +421,23 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count,return -EINVAL ;spin_lock (&ops_lock); -list_for_each_entry (op, &recv_list, list) { -if (op->info.fsid == info.fsid && - op->info.number == info.number && - op->info.owner == info.owner) { -list_del_init (&op->list); -memcpy (&op->info, &info,sizeof (info)); -if (op->data) +list_for_each_entry (iter, &recv_list, list) { +if (iter->info.fsid == info.fsid && + iter->info.number == info.number && + iter->info.owner == info.owner) { +list_del_init (&iter->list); +memcpy (&iter->info, &info,sizeof (info)); +if (iter->data) do_callback =1 ;else - op->done =1 ; - found =1 ; + iter->done =1 ; + op = iter;break ; } }spin_unlock (&ops_lock); -if (found) { +if (op) {if (do_callback)dlm_plock_callback (op);else
fs/dlm/recover.c +19 -20
@@ -732,10 +732,9 @@ void dlm_recovered_lock(struct dlm_rsb *r)static void recover_lvb (struct dlm_rsb *r) { -struct dlm_lkb *lkb, *high_lkb =NULL ; +struct dlm_lkb *big_lkb =NULL , *iter, *high_lkb =NULL ;uint32_t high_seq =0 ;int lock_lvb_exists =0 ; -int big_lock_exists =0 ;int lvblen = r->res_ls->ls_lvblen; if (!rsb_flag(r, RSB_NEW_MASTER2) &&
@@ -751,37 +750,37 @@ static void recover_lvb(struct dlm_rsb *r)/* we are the new master, so figure out if VALNOTVALID should be set, and set the rsb lvb from the best lkb available. */ -list_for_each_entry (lkb, &r->res_grantqueue, lkb_statequeue) { -if (!(lkb->lkb_exflags &DLM_LKF_VALBLK )) +list_for_each_entry (iter, &r->res_grantqueue, lkb_statequeue) { +if (!(iter->lkb_exflags &DLM_LKF_VALBLK ))continue ; lock_lvb_exists =1 ; -if (lkb->lkb_grmode >DLM_LOCK_CR ) { - big_lock_exists =1 ; +if (iter->lkb_grmode >DLM_LOCK_CR ) { + big_lkb = iter; goto setflag; } -if (((int )lkb->lkb_lvbseq - (int )high_seq) >=0 ) { - high_lkb = lkb; - high_seq = lkb->lkb_lvbseq; +if (((int )iter->lkb_lvbseq - (int )high_seq) >=0 ) { + high_lkb = iter; + high_seq = iter->lkb_lvbseq; } } -list_for_each_entry (lkb, &r->res_convertqueue, lkb_statequeue) { -if (!(lkb->lkb_exflags &DLM_LKF_VALBLK )) +list_for_each_entry (iter, &r->res_convertqueue, lkb_statequeue) { +if (!(iter->lkb_exflags &DLM_LKF_VALBLK ))continue ; lock_lvb_exists =1 ; -if (lkb->lkb_grmode >DLM_LOCK_CR ) { - big_lock_exists =1 ; +if (iter->lkb_grmode >DLM_LOCK_CR ) { + big_lkb = iter; goto setflag; } -if (((int )lkb->lkb_lvbseq - (int )high_seq) >=0 ) { - high_lkb = lkb; - high_seq = lkb->lkb_lvbseq; +if (((int )iter->lkb_lvbseq - (int )high_seq) >=0 ) { + high_lkb = iter; + high_seq = iter->lkb_lvbseq; } }
@@ -790,7 +789,7 @@ static void recover_lvb(struct dlm_rsb *r) goto out;/* lvb is invalidated if only NL/CR locks remain */ -if (!big_lock_exists) +if (!big_lkb)rsb_set_flag (r,RSB_VALNOTVALID );if (!r->res_lvbptr) {
@@ -799,9 +798,9 @@ static void recover_lvb(struct dlm_rsb *r) goto out; } -if (big_lock_exists) { - r->res_lvbseq = lkb->lkb_lvbseq; -memcpy (r->res_lvbptr, lkb->lkb_lvbptr, lvblen); +if (big_lkb) { + r->res_lvbseq = big_lkb->lkb_lvbseq; +memcpy (r->res_lvbptr, big_lkb->lkb_lvbptr, lvblen); }else if (high_lkb) { r->res_lvbseq = high_lkb->lkb_lvbseq;memcpy (r->res_lvbptr, high_lkb->lkb_lvbptr, lvblen);
Signature · 1 line
2.31.1