From: "Dilger, Andreas" <andreas.dilger@intel.com>
To: NeilBrown <neilb@suse.com>
Cc: "Drokin, Oleg" <oleg.drokin@intel.com>,
James Simmons <jsimmons@infradead.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"lustre-devel@lists.lustre.org" <lustre-devel@lists.lustre.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 7/9] staging: lustre: ldlm: tidy list walking in ldlm_flock()
Date: Fri, 27 Oct 2017 09:32:49 +0000 [thread overview]
Message-ID: <4DED46B3-BACE-4D6F-9A90-E35C21C3F0DC@intel.com> (raw)
In-Reply-To: <150872002980.3340.10618324564169458593.stgit@noble>
On Oct 22, 2017, at 18:53, NeilBrown <neilb@suse.com> wrote:
>
> Use list_for_each_entry variants to
> avoid the explicit list_entry() calls.
> This allows us to use list_for_each_entry_safe_from()
> instread of adding a local list-walking macro.
>
> Also improve some comments so that it is more obvious
> that the locks are sorted per-owner and that we need
> to find the insertion point.
>
> Signed-off-by: NeilBrown <neilb@suse.com>
The conversion looks a bit tricky, but appears to be correct.
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
> ---
> drivers/staging/lustre/lustre/ldlm/ldlm_flock.c | 45 ++++++++++-------------
> 1 file changed, 19 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
> index 1bf56892fcf5..0bf6dce1c5b1 100644
> --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
> +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
> @@ -59,17 +59,6 @@
> #include <linux/list.h>
> #include "ldlm_internal.h"
>
> -/**
> - * list_for_remaining_safe - iterate over the remaining entries in a list
> - * and safeguard against removal of a list entry.
> - * \param pos the &struct list_head to use as a loop counter. pos MUST
> - * have been initialized prior to using it in this macro.
> - * \param n another &struct list_head to use as temporary storage
> - * \param head the head for your list.
> - */
> -#define list_for_remaining_safe(pos, n, head) \
> - for (n = pos->next; pos != (head); pos = n, n = pos->next)
> -
> static inline int
> ldlm_same_flock_owner(struct ldlm_lock *lock, struct ldlm_lock *new)
> {
> @@ -125,8 +114,8 @@ static int ldlm_process_flock_lock(struct ldlm_lock *req)
> {
> struct ldlm_resource *res = req->l_resource;
> struct ldlm_namespace *ns = ldlm_res_to_ns(res);
> - struct list_head *tmp;
> - struct list_head *ownlocks = NULL;
> + struct ldlm_lock *tmp;
> + struct ldlm_lock *ownlocks = NULL;
> struct ldlm_lock *lock = NULL;
> struct ldlm_lock *new = req;
> struct ldlm_lock *new2 = NULL;
> @@ -151,23 +140,23 @@ static int ldlm_process_flock_lock(struct ldlm_lock *req)
> /* This loop determines where this processes locks start
> * in the resource lr_granted list.
> */
> - list_for_each(tmp, &res->lr_granted) {
> - lock = list_entry(tmp, struct ldlm_lock,
> - l_res_link);
> + list_for_each_entry(lock, &res->lr_granted, l_res_link) {
> if (ldlm_same_flock_owner(lock, req)) {
> - ownlocks = tmp;
> + ownlocks = lock;
> break;
> }
> }
>
> - /* Scan the locks owned by this process that overlap this request.
> + /* Scan the locks owned by this process to find the insertion point
> + * (as locks are ordered), and to handle overlaps.
> * We may have to merge or split existing locks.
> */
> - if (!ownlocks)
> - ownlocks = &res->lr_granted;
> -
> - list_for_remaining_safe(ownlocks, tmp, &res->lr_granted) {
> - lock = list_entry(ownlocks, struct ldlm_lock, l_res_link);
> + if (ownlocks)
> + lock = ownlocks;
> + else
> + lock = list_entry(&res->lr_granted,
> + struct ldlm_lock, l_res_link);
> + list_for_each_entry_safe_from(lock, tmp, &res->lr_granted, l_res_link) {
>
> if (!ldlm_same_flock_owner(lock, new))
> break;
> @@ -295,7 +284,7 @@ static int ldlm_process_flock_lock(struct ldlm_lock *req)
> lock->l_granted_mode);
>
> /* insert new2 at lock */
> - ldlm_resource_add_lock(res, ownlocks, new2);
> + ldlm_resource_add_lock(res, &lock->l_res_link, new2);
> LDLM_LOCK_RELEASE(new2);
> break;
> }
> @@ -309,8 +298,12 @@ static int ldlm_process_flock_lock(struct ldlm_lock *req)
>
> if (!added) {
> list_del_init(&req->l_res_link);
> - /* insert new lock before ownlocks in list. */
> - ldlm_resource_add_lock(res, ownlocks, req);
> + /* insert new lock before "lock", which might be the
> + * next lock for this owner, or might be the first
> + * lock for the next owner, or might not be a lock at
> + * all, but instead points at the head of the list
> + */
> + ldlm_resource_add_lock(res, &lock->l_res_link, req);
> }
>
> /* In case we're reprocessing the requested lock we can't destroy
>
>
Cheers, Andreas
--
Andreas Dilger
Lustre Principal Architect
Intel Corporation
next prev parent reply other threads:[~2017-10-27 9:32 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-23 0:53 [PATCH 0/9] Assorted cleanups for staging/.../lustre/ldlm/ldlm_flock.c NeilBrown
2017-10-23 0:53 ` [PATCH 6/9] staging: lustre: ldlm: remove 'flags' arg from ldlm_flock_destroy() NeilBrown
2017-10-27 9:23 ` Dilger, Andreas
2017-10-23 0:53 ` [PATCH 9/9] staging: lustre: ldlm: remove unused field 'fwd_generation' NeilBrown
2017-10-27 9:39 ` [lustre-devel] " Dilger, Andreas
2017-10-27 11:10 ` NeilBrown
2017-10-23 0:53 ` [PATCH 5/9] staging: lustre: ldlm: remove unused 'overlaps' variable NeilBrown
2017-10-27 9:20 ` Dilger, Andreas
2017-10-23 0:53 ` [PATCH 3/9] staging: lustre: ldlm: remove unneeded 'err' arg to ldlm_process_flock_lock() NeilBrown
2017-10-27 9:11 ` Dilger, Andreas
2017-10-23 0:53 ` [PATCH 8/9] staging: lustre: ldlm: remove unnecessary 'ownlocks' variable NeilBrown
2017-10-27 9:33 ` Dilger, Andreas
2017-10-23 0:53 ` [PATCH 7/9] staging: lustre: ldlm: tidy list walking in ldlm_flock() NeilBrown
2017-10-27 9:32 ` Dilger, Andreas [this message]
2017-10-23 0:53 ` [PATCH 2/9] staging: lustre: ldlm: remove unused 'work_list' arg from ldlm_process_flock_lock() NeilBrown
2017-10-27 9:09 ` Dilger, Andreas
2017-10-23 0:53 ` [PATCH 4/9] staging: lustre: ldlm: remove 'flags' " NeilBrown
2017-10-27 9:19 ` Dilger, Andreas
2017-10-23 0:53 ` [PATCH 1/9] staging: lustre: ldlm: remove 'first_enq' " NeilBrown
2017-10-27 9:08 ` Dilger, Andreas
2017-10-24 22:20 ` [PATCH 0/9] Assorted cleanups for staging/.../lustre/ldlm/ldlm_flock.c James Simmons
2017-10-25 21:55 ` NeilBrown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DED46B3-BACE-4D6F-9A90-E35C21C3F0DC@intel.com \
--to=andreas.dilger@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jsimmons@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lustre-devel@lists.lustre.org \
--cc=neilb@suse.com \
--cc=oleg.drokin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®