[lustre-devel] [PATCH 07/21] lustre: use list_first_entry() in lnet/klnds subdirectory.

NeilBrown neilb at suse.com
Sun Feb 10 16:34:55 PST 2019


On Fri, Feb 08 2019, Andreas Dilger wrote:

> On Feb 6, 2019, at 17:03, NeilBrown <neilb at suse.com> wrote:
>> 
>> Convert
>>  list_entry(foo->next .....)
>> to
>>  list_first_entry(foo, ....)
>> 
>> in 'lnet/klnds
>> 
>> In several cases the call is combined with a list_empty() test and
>> list_first_entry_or_null() is used
>> 
>> Signed-off-by: NeilBrown <neilb at suse.com>
>> 
>> @@ -1853,8 +1855,9 @@ static void kiblnd_destroy_pool_list(struct list_head *head)
>> {
>> 	struct kib_pool *pool;
>> 
>> -	while (!list_empty(head)) {
>> -		pool = list_entry(head->next, struct kib_pool, po_list);
>> +	while ((pool = list_first_entry_or_null(head,
>> +						struct kib_pool,
>> +						po_list)) != NULL) {
>> 		list_del(&pool->po_list);
>> 
>> 		LASSERT(pool->po_owner);
>> @@ -1869,7 +1872,7 @@ static void kiblnd_fail_poolset(struct kib_poolset *ps, struct list_head *zombie
>> 
>> 	spin_lock(&ps->ps_lock);
>> 	while (!list_empty(&ps->ps_pool_list)) {
>> -		struct kib_pool *po = list_entry(ps->ps_pool_list.next,
>> +		struct kib_pool *po = list_first_entry(&ps->ps_pool_list,
>> 					    struct kib_pool, po_list);
>> 		po->po_failed = 1;
>> 		list_del(&po->po_list);
>
> Why not use the same style as elsewhere in the code:
>
> 	while ((po = list_first_entry_or_null(&ps->ps_pool_list,
> 					      struct kib_pool,
> 					      po_list)) != NULL) {
>

No good reason - just fatigue probably.  I could automate most of
finding these, but automating the fixing of them didn't quite seem
worth the effort.  Maybe I should play with coccinelle...

I've merged:

diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index df6b1b134709..d67a197e718d 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -1867,13 +1867,15 @@ static void kiblnd_destroy_pool_list(struct list_head *head)
 
 static void kiblnd_fail_poolset(struct kib_poolset *ps, struct list_head *zombies)
 {
+	struct kib_pool *po;
+
 	if (!ps->ps_net) /* initialized? */
 		return;
 
 	spin_lock(&ps->ps_lock);
-	while (!list_empty(&ps->ps_pool_list)) {
-		struct kib_pool *po = list_first_entry(&ps->ps_pool_list,
-					    struct kib_pool, po_list);
+	while ((po = list_first_entry_or_null(&ps->ps_pool_list,
+					      struct kib_pool,
+					      po_list)) == NULL) {
 		po->po_failed = 1;
 		list_del(&po->po_list);
 		if (!po->po_allocated)

Thanks,
NeilBrown
-------------- 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/bc4f596b/attachment.sig>


More information about the lustre-devel mailing list