From: NeilBrown <neilb@suse.com> To: Oleg Drokin <oleg.drokin@intel.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, James Simmons <jsimmons@infradead.org>, Andreas Dilger <andreas.dilger@intel.com> Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, Lustre Development List <lustre-devel@lists.lustre.org> Subject: [PATCH 02/11] staging: lustre: change lock_matches() to return bool. Date: Wed, 06 Jun 2018 16:05:18 +1000 [thread overview] Message-ID: <152826511895.16761.11859115039331359491.stgit@noble> (raw) In-Reply-To: <152826510267.16761.14361003167157833896.stgit@noble> The name of the function lock_matches() sounds like it performs a test (it does) and so should return a bool. Returning a bool gives a slight code simplification (in search_queue) and more simplification in future patches. Signed-off-by: NeilBrown <neilb@suse.com> --- drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 37 ++++++++++++------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c index 13b1b5fdada9..034935e06393 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c @@ -1053,20 +1053,20 @@ struct lock_match_data { * \param lock test-against this lock * \param data parameters */ -static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) +static bool lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) { union ldlm_policy_data *lpol = &lock->l_policy_data; enum ldlm_mode match; if (lock == data->lmd_old) - return INTERVAL_ITER_STOP; + return true; /* * Check if this lock can be matched. * Used by LU-2919(exclusive open) for open lease lock */ if (ldlm_is_excl(lock)) - return INTERVAL_ITER_CONT; + return false; /* * llite sometimes wants to match locks that will be @@ -1078,26 +1078,26 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) */ if (ldlm_is_cbpending(lock) && !(data->lmd_flags & LDLM_FL_CBPENDING)) - return INTERVAL_ITER_CONT; + return false; if (!data->lmd_unref && ldlm_is_cbpending(lock) && !lock->l_readers && !lock->l_writers) - return INTERVAL_ITER_CONT; + return false; if (!(lock->l_req_mode & *data->lmd_mode)) - return INTERVAL_ITER_CONT; + return false; match = lock->l_req_mode; switch (lock->l_resource->lr_type) { case LDLM_EXTENT: if (lpol->l_extent.start > data->lmd_policy->l_extent.start || lpol->l_extent.end < data->lmd_policy->l_extent.end) - return INTERVAL_ITER_CONT; + return false; if (unlikely(match == LCK_GROUP) && data->lmd_policy->l_extent.gid != LDLM_GID_ANY && lpol->l_extent.gid != data->lmd_policy->l_extent.gid) - return INTERVAL_ITER_CONT; + return false; break; case LDLM_IBITS: /* @@ -1107,7 +1107,7 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) if ((lpol->l_inodebits.bits & data->lmd_policy->l_inodebits.bits) != data->lmd_policy->l_inodebits.bits) - return INTERVAL_ITER_CONT; + return false; break; default: break; @@ -1117,10 +1117,10 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) * of bits. */ if (!data->lmd_unref && LDLM_HAVE_MASK(lock, GONE)) - return INTERVAL_ITER_CONT; + return false; if (!equi(data->lmd_flags & LDLM_FL_LOCAL_ONLY, ldlm_is_local(lock))) - return INTERVAL_ITER_CONT; + return false; if (data->lmd_flags & LDLM_FL_TEST_LOCK) { LDLM_LOCK_GET(lock); @@ -1132,15 +1132,17 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) *data->lmd_mode = match; data->lmd_lock = lock; - return INTERVAL_ITER_STOP; + return true; } static enum interval_iter itree_overlap_cb(struct interval_node *in, void *args) { struct lock_match_data *data = args; - struct ldlm_lock *lock = container_of(in, struct ldlm_lock, l_tree_node); + struct ldlm_lock *lock = container_of(in, struct ldlm_lock, + l_tree_node); - return lock_matches(lock, data); + return lock_matches(lock, data) ? + INTERVAL_ITER_STOP : INTERVAL_ITER_CONT; } /** @@ -1187,13 +1189,10 @@ static struct ldlm_lock *search_queue(struct list_head *queue, struct lock_match_data *data) { struct ldlm_lock *lock; - int rc; - list_for_each_entry(lock, queue, l_res_link) { - rc = lock_matches(lock, data); - if (rc == INTERVAL_ITER_STOP) + list_for_each_entry(lock, queue, l_res_link) + if (lock_matches(lock, data)) return data->lmd_lock; - } return NULL; }
WARNING: multiple messages have this Message-ID (diff)
From: NeilBrown <neilb@suse.com> To: Oleg Drokin <oleg.drokin@intel.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, James Simmons <jsimmons@infradead.org>, Andreas Dilger <andreas.dilger@intel.com> Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, Lustre Development List <lustre-devel@lists.lustre.org> Subject: [lustre-devel] [PATCH 02/11] staging: lustre: change lock_matches() to return bool. Date: Wed, 06 Jun 2018 16:05:18 +1000 [thread overview] Message-ID: <152826511895.16761.11859115039331359491.stgit@noble> (raw) In-Reply-To: <152826510267.16761.14361003167157833896.stgit@noble> The name of the function lock_matches() sounds like it performs a test (it does) and so should return a bool. Returning a bool gives a slight code simplification (in search_queue) and more simplification in future patches. Signed-off-by: NeilBrown <neilb@suse.com> --- drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 37 ++++++++++++------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c index 13b1b5fdada9..034935e06393 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c @@ -1053,20 +1053,20 @@ struct lock_match_data { * \param lock test-against this lock * \param data parameters */ -static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) +static bool lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) { union ldlm_policy_data *lpol = &lock->l_policy_data; enum ldlm_mode match; if (lock == data->lmd_old) - return INTERVAL_ITER_STOP; + return true; /* * Check if this lock can be matched. * Used by LU-2919(exclusive open) for open lease lock */ if (ldlm_is_excl(lock)) - return INTERVAL_ITER_CONT; + return false; /* * llite sometimes wants to match locks that will be @@ -1078,26 +1078,26 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) */ if (ldlm_is_cbpending(lock) && !(data->lmd_flags & LDLM_FL_CBPENDING)) - return INTERVAL_ITER_CONT; + return false; if (!data->lmd_unref && ldlm_is_cbpending(lock) && !lock->l_readers && !lock->l_writers) - return INTERVAL_ITER_CONT; + return false; if (!(lock->l_req_mode & *data->lmd_mode)) - return INTERVAL_ITER_CONT; + return false; match = lock->l_req_mode; switch (lock->l_resource->lr_type) { case LDLM_EXTENT: if (lpol->l_extent.start > data->lmd_policy->l_extent.start || lpol->l_extent.end < data->lmd_policy->l_extent.end) - return INTERVAL_ITER_CONT; + return false; if (unlikely(match == LCK_GROUP) && data->lmd_policy->l_extent.gid != LDLM_GID_ANY && lpol->l_extent.gid != data->lmd_policy->l_extent.gid) - return INTERVAL_ITER_CONT; + return false; break; case LDLM_IBITS: /* @@ -1107,7 +1107,7 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) if ((lpol->l_inodebits.bits & data->lmd_policy->l_inodebits.bits) != data->lmd_policy->l_inodebits.bits) - return INTERVAL_ITER_CONT; + return false; break; default: break; @@ -1117,10 +1117,10 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) * of bits. */ if (!data->lmd_unref && LDLM_HAVE_MASK(lock, GONE)) - return INTERVAL_ITER_CONT; + return false; if (!equi(data->lmd_flags & LDLM_FL_LOCAL_ONLY, ldlm_is_local(lock))) - return INTERVAL_ITER_CONT; + return false; if (data->lmd_flags & LDLM_FL_TEST_LOCK) { LDLM_LOCK_GET(lock); @@ -1132,15 +1132,17 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data) *data->lmd_mode = match; data->lmd_lock = lock; - return INTERVAL_ITER_STOP; + return true; } static enum interval_iter itree_overlap_cb(struct interval_node *in, void *args) { struct lock_match_data *data = args; - struct ldlm_lock *lock = container_of(in, struct ldlm_lock, l_tree_node); + struct ldlm_lock *lock = container_of(in, struct ldlm_lock, + l_tree_node); - return lock_matches(lock, data); + return lock_matches(lock, data) ? + INTERVAL_ITER_STOP : INTERVAL_ITER_CONT; } /** @@ -1187,13 +1189,10 @@ static struct ldlm_lock *search_queue(struct list_head *queue, struct lock_match_data *data) { struct ldlm_lock *lock; - int rc; - list_for_each_entry(lock, queue, l_res_link) { - rc = lock_matches(lock, data); - if (rc == INTERVAL_ITER_STOP) + list_for_each_entry(lock, queue, l_res_link) + if (lock_matches(lock, data)) return data->lmd_lock; - } return NULL; }
next prev parent reply other threads:[~2018-06-06 6:11 UTC|newest] Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-06 6:05 [md PATCH 00/11] staging: More lustre cleanup - particularly interval-trees NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-06 6:05 ` [PATCH 01/11] staging: lustre: simplify use of interval-tree NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-16 3:00 ` James Simmons 2018-06-16 3:00 ` [lustre-devel] " James Simmons 2018-06-16 22:49 ` NeilBrown 2018-06-16 22:49 ` [lustre-devel] " NeilBrown 2018-07-06 1:36 ` James Simmons 2018-07-06 1:36 ` [lustre-devel] " James Simmons 2018-06-06 6:05 ` NeilBrown [this message] 2018-06-06 6:05 ` [lustre-devel] [PATCH 02/11] staging: lustre: change lock_matches() to return bool NeilBrown 2018-06-06 6:05 ` [PATCH 10/11] staging: lustre: move ldlm into ptlrpc NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-07 4:51 ` James Simmons 2018-06-07 9:48 ` NeilBrown 2018-06-07 9:48 ` [lustre-devel] " NeilBrown 2018-06-07 18:21 ` Ben Evans 2018-06-07 18:21 ` Ben Evans 2018-06-07 20:50 ` NeilBrown 2018-06-07 20:50 ` NeilBrown 2018-06-08 6:59 ` NeilBrown 2018-06-08 6:59 ` [lustre-devel] " NeilBrown 2018-06-06 6:05 ` [PATCH 05/11] staging: lustre: convert ldlm extent locks to linux extent-tree NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-06 6:05 ` [PATCH 06/11] staging: lustre: remove interval_tree NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-06 6:05 ` [PATCH 09/11] staging: lustre: discard WIRE_ATTR NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-14 2:38 ` James Simmons 2018-06-14 2:38 ` [lustre-devel] " James Simmons 2018-06-06 6:05 ` [PATCH 03/11] staging: lustre: move interval_insert call from ldlm_lock to ldlm_extent NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-06 6:05 ` [PATCH 04/11] staging: lustre: convert range_lock to linux interval_trees NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-06 6:05 ` [PATCH 07/11] staging: lustre: fold lprocfs_call_handler functionality into lnet_debugfs_* NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-14 2:38 ` James Simmons 2018-06-14 2:38 ` [lustre-devel] " James Simmons 2018-06-06 6:05 ` [PATCH 08/11] staging: lustre: obdclass: move linux/linux-foo.c to foo.c NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-14 2:40 ` James Simmons 2018-06-14 2:40 ` [lustre-devel] " James Simmons 2018-06-06 6:05 ` [PATCH 11/11] staging: lustre: centralize setting of subdir-ccflags-y NeilBrown 2018-06-06 6:05 ` [lustre-devel] " NeilBrown 2018-06-13 21:38 ` James Simmons 2018-06-13 21:38 ` [lustre-devel] " James Simmons 2018-06-13 23:21 ` NeilBrown 2018-06-13 23:21 ` [lustre-devel] " 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=152826511895.16761.11859115039331359491.stgit@noble \ --to=neilb@suse.com \ --cc=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=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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.