From: NeilBrown <neilb@suse.com>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH 04/21] lustre: use list*entry macros in place of container_of()
Date: Mon, 11 Feb 2019 14:14:15 +1100 [thread overview]
Message-ID: <8736ovggoo.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <alpine.LFD.2.21.1902110057200.24975@casper.infradead.org>
On Mon, Feb 11 2019, James Simmons wrote:
>> There are a number of places that use container_of() but where
>> list_first_entry(), or list_last_entry() make the meaning more clear.
>> So change them over.
>
> I have to say normally the patches you see genernally use the basic
> functionality of the linux list implementation. I wonder if a deep
> dive on LUG's developers day would be a good idea.
It is possible to take the "new macro for subtly different case"
exercise too far, though in this particular case, I think using
replacing container_of with list_entry is a clear win.
Maybe a broader discussion would help
>
> Reviewed-by: James Simmons <jsimmons@infradead.org>
Thanks,
NeilBrown
>
>> Signed-off-by: NeilBrown <neilb@suse.com>
>> ---
>> drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 4 ++--
>> drivers/staging/lustre/lustre/obdclass/cl_io.c | 4 ++--
>> drivers/staging/lustre/lustre/obdclass/cl_object.c | 13 ++++++++-----
>> drivers/staging/lustre/lustre/obdclass/cl_page.c | 4 ++--
>> drivers/staging/lustre/lustre/obdclass/lu_object.c | 7 +++----
>> 5 files changed, 17 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
>> index 85c5047f4ba2..74c7644d6ef8 100644
>> --- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
>> +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
>> @@ -987,8 +987,8 @@ struct ldlm_namespace *ldlm_namespace_first_locked(enum ldlm_side client)
>> {
>> LASSERT(mutex_is_locked(ldlm_namespace_lock(client)));
>> LASSERT(!list_empty(ldlm_namespace_list(client)));
>> - return container_of(ldlm_namespace_list(client)->next,
>> - struct ldlm_namespace, ns_list_chain);
>> + return list_first_entry(ldlm_namespace_list(client),
>> + struct ldlm_namespace, ns_list_chain);
>> }
>>
>> /** Create and initialize new resource. */
>> diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c
>> index 7bf02350f19d..34b4e63e7d1a 100644
>> --- a/drivers/staging/lustre/lustre/obdclass/cl_io.c
>> +++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c
>> @@ -93,8 +93,8 @@ void cl_io_fini(const struct lu_env *env, struct cl_io *io)
>> LINVRNT(cl_io_invariant(io));
>>
>> while (!list_empty(&io->ci_layers)) {
>> - slice = container_of(io->ci_layers.prev, struct cl_io_slice,
>> - cis_linkage);
>> + slice = list_last_entry(&io->ci_layers, struct cl_io_slice,
>> + cis_linkage);
>> list_del_init(&slice->cis_linkage);
>> if (slice->cis_iop->op[io->ci_type].cio_fini)
>> slice->cis_iop->op[io->ci_type].cio_fini(env, slice);
>> diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
>> index 05d784ae7a6c..f724b2d62df1 100644
>> --- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
>> +++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
>> @@ -649,8 +649,8 @@ static struct lu_env *cl_env_obtain(void *debug)
>> if (cl_envs[cpu].cec_count > 0) {
>> int rc;
>>
>> - cle = container_of(cl_envs[cpu].cec_envs.next, struct cl_env,
>> - ce_linkage);
>> + cle = list_first_entry(&cl_envs[cpu].cec_envs, struct cl_env,
>> + ce_linkage);
>> list_del_init(&cle->ce_linkage);
>> cl_envs[cpu].cec_count--;
>> read_unlock(&cl_envs[cpu].cec_guard);
>> @@ -748,9 +748,12 @@ unsigned int cl_env_cache_purge(unsigned int nr)
>>
>> for_each_possible_cpu(i) {
>> write_lock(&cl_envs[i].cec_guard);
>> - for (; !list_empty(&cl_envs[i].cec_envs) && nr > 0; --nr) {
>> - cle = container_of(cl_envs[i].cec_envs.next,
>> - struct cl_env, ce_linkage);
>> + for (; nr >0 &&
>> + (cle = list_first_entry_or_null(
>> + &cl_envs[i].cec_envs,
>> + struct cl_env,
>> + ce_linkage)) != NULL;
>> + --nr) {
>> list_del_init(&cle->ce_linkage);
>> LASSERT(cl_envs[i].cec_count > 0);
>> cl_envs[i].cec_count--;
>> diff --git a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c
>> index b1b4dc7ea22f..d025ea55818f 100644
>> --- a/drivers/staging/lustre/lustre/obdclass/cl_page.c
>> +++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c
>> @@ -690,8 +690,8 @@ int cl_page_is_vmlocked(const struct lu_env *env, const struct cl_page *pg)
>> const struct cl_page_slice *slice;
>> int result;
>>
>> - slice = container_of(pg->cp_layers.next,
>> - const struct cl_page_slice, cpl_linkage);
>> + slice = list_first_entry(&pg->cp_layers,
>> + const struct cl_page_slice, cpl_linkage);
>> PASSERT(env, pg, slice->cpl_ops->cpo_is_vmlocked);
>> /*
>> * Call ->cpo_is_vmlocked() directly instead of going through
>> diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c
>> index 3bd48748f46c..639c298b6a90 100644
>> --- a/drivers/staging/lustre/lustre/obdclass/lu_object.c
>> +++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c
>> @@ -349,7 +349,7 @@ static void lu_object_free(const struct lu_env *env, struct lu_object *o)
>> * lives as long as possible and ->loo_object_free() methods
>> * can look at its contents.
>> */
>> - o = container_of(splice.prev, struct lu_object, lo_linkage);
>> + o = list_last_entry(&splice, struct lu_object, lo_linkage);
>> list_del_init(&o->lo_linkage);
>> o->lo_ops->loo_object_free(env, o);
>> }
>> @@ -432,9 +432,8 @@ int lu_site_purge_objects(const struct lu_env *env, struct lu_site *s,
>> * Free everything on the dispose list. This is safe against
>> * races due to the reasons described in lu_object_put().
>> */
>> - while (!list_empty(&dispose)) {
>> - h = container_of(dispose.next,
>> - struct lu_object_header, loh_lru);
>> + while ((h = list_first_entry_or_null(
>> + &dispose, struct lu_object_header, loh_lru)) != NULL) {
>> list_del_init(&h->loh_lru);
>> lu_object_free(env, lu_object_top(h));
>> lprocfs_counter_incr(s->ls_stats, LU_SS_LRU_PURGED);
>>
>>
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20190211/b5cb43a0/attachment.sig>
next prev parent reply other threads:[~2019-02-11 3:14 UTC|newest]
Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-07 0:03 [lustre-devel] [PATCH 00/21] lustre: Assorted cleanups for obdclass NeilBrown
2019-02-07 0:03 ` [lustre-devel] [PATCH 05/21] lustre: use list_first_entry() in lustre subdirectory NeilBrown
2019-02-08 0:31 ` Andreas Dilger
2019-02-11 0:13 ` NeilBrown
2019-02-11 1:45 ` James Simmons
2019-02-11 3:08 ` NeilBrown
2019-02-07 0:03 ` [lustre-devel] [PATCH 04/21] lustre: use list*entry macros in place of container_of() NeilBrown
2019-02-08 0:25 ` Andreas Dilger
2019-02-11 1:32 ` James Simmons
2019-02-11 3:14 ` NeilBrown [this message]
2019-02-07 0:03 ` [lustre-devel] [PATCH 06/21] lustre: use list_first_entry() in lnet/lnet subdirectory NeilBrown
2019-02-08 0:44 ` Andreas Dilger
2019-02-11 1:46 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 01/21] lustre: obdclass: discard csi_end_io NeilBrown
2019-02-07 0:20 ` Andreas Dilger
2019-02-11 0:19 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 02/21] lustre: obd_class: remove csi_barrier from struct cl_sync_io NeilBrown
2019-02-08 0:09 ` Andreas Dilger
2019-02-11 0:24 ` NeilBrown
2019-02-11 0:34 ` James Simmons
2019-02-11 1:09 ` NeilBrown
2019-02-07 0:03 ` [lustre-devel] [PATCH 03/21] lustre: obdclass: use list_sort() to sort a list NeilBrown
2019-02-08 0:13 ` Andreas Dilger
2019-02-11 0:39 ` James Simmons
2019-02-11 1:05 ` NeilBrown
2019-02-07 0:03 ` [lustre-devel] [PATCH 15/21] lustre: obdclass: char obd_ioctl_getdata type NeilBrown
2019-02-08 5:56 ` Andreas Dilger
2019-02-11 0:52 ` NeilBrown
2019-02-11 4:03 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 21/21] lustre: make exp_refcount in obd_export a refcount_t NeilBrown
2019-02-08 7:07 ` Andreas Dilger
2019-02-11 4:18 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 09/21] lustre: use list_last_entry() throughout NeilBrown
2019-02-08 1:07 ` Andreas Dilger
2019-02-11 1:48 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 12/21] lustre: cl_page.c: remove PINVRNT() NeilBrown
2019-02-08 5:43 ` Andreas Dilger
2019-02-11 4:01 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 11/21] lustre: cl_object: remove vestigial debugging NeilBrown
2019-02-08 1:31 ` Andreas Dilger
2019-02-11 0:48 ` NeilBrown
2019-02-11 2:04 ` James Simmons
2019-02-11 3:25 ` NeilBrown
2019-02-12 5:19 ` James Simmons
2019-02-12 13:56 ` Patrick Farrell
2019-02-12 22:12 ` NeilBrown
2019-02-13 0:19 ` James Simmons
2019-02-13 0:29 ` NeilBrown
2019-02-07 0:03 ` [lustre-devel] [PATCH 18/21] lustre: move debug.c from obdclass to obdecho NeilBrown
2019-02-08 6:02 ` Andreas Dilger
2019-02-11 4:17 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 10/21] lustre: obdclass: use cl_object_for_each where appropriate NeilBrown
2019-02-08 1:10 ` Andreas Dilger
2019-02-11 0:42 ` NeilBrown
2019-02-11 4:19 ` James Simmons
2019-02-15 18:15 ` Andreas Dilger
2019-02-11 1:57 ` James Simmons
2019-02-11 3:19 ` NeilBrown
2019-02-07 0:03 ` [lustre-devel] [PATCH 13/21] lustre: make cp_ref in cl_page a refcount_t NeilBrown
2019-02-08 5:45 ` Andreas Dilger
2019-02-11 4:00 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 08/21] lustre: use list_first_entry() throughout NeilBrown
2019-02-08 1:06 ` Andreas Dilger
2019-02-11 1:48 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 17/21] lustre: obdclass: result of try_module_get() should not be ignored NeilBrown
2019-02-08 5:58 ` Andreas Dilger
2019-02-11 4:22 ` James Simmons
2019-02-11 5:01 ` NeilBrown
2019-02-11 5:09 ` [lustre-devel] [PATCH] lustre: don't manage module refs in obd_class_open/close NeilBrown
2019-02-12 4:17 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 19/21] lustre: obdclass: avoid races in class_register_type() NeilBrown
2019-02-08 6:41 ` Andreas Dilger
2019-02-11 0:58 ` NeilBrown
2019-02-12 5:03 ` James Simmons
2019-02-14 3:43 ` NeilBrown
2019-02-07 0:03 ` [lustre-devel] [PATCH 20/21] lustre: obdclass: fix module load locking NeilBrown
2019-02-13 1:53 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 14/21] lustre: make ccc_users in cl_client_cache a refcount_t NeilBrown
2019-02-08 5:46 ` Andreas Dilger
2019-02-11 4:01 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 07/21] lustre: use list_first_entry() in lnet/klnds subdirectory NeilBrown
2019-02-08 0:59 ` Andreas Dilger
2019-02-11 0:34 ` NeilBrown
2019-02-11 1:47 ` James Simmons
2019-02-07 0:03 ` [lustre-devel] [PATCH 16/21] lustre: obdclass: normalize a switch statement NeilBrown
2019-02-08 5:57 ` Andreas Dilger
2019-02-11 4:03 ` James Simmons
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=8736ovggoo.fsf@notabene.neil.brown.name \
--to=neilb@suse.com \
--cc=lustre-devel@lists.lustre.org \
/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 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.