Skip to contentSkip to conversation

staging: lustre: lnet: Use list_for_each_entry()

PATCH In review Gargi Sharma 2 participants 5 messages Feb 28, 2017 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: lustre: lnet: Use list_for_each_entry()

Use list_for_each_entry() rather than a combination of list_for_each() and list_entry() since the former does not expose the list spine.

Done using Coccinelle:
@a@
expression pos, n, mem;
type t;
identifier var;
iterator name list_for_each_entry, list_for_each;
@@

- list_for_each(pos, n)
+ list_for_each_entry(var, n, mem)
{
... when != var
- var = list_entry(pos, t, mem);
... when != pos
}

---
 drivers/staging/lustre/lnet/selftest/conrpc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/lustre/lnet/selftest/conrpc.c +2 -4
index c6a683b..72b6ff2 100644
@@ -1339,10 +1339,8 @@ lstcon_rpc_cleanup_wait(void)
 	LASSERT(console_session.ses_shutdown);
 
 	while (!list_empty(&console_session.ses_trans_list)) {
-		list_for_each(pacer, &console_session.ses_trans_list) {
-			trans = list_entry(pacer, struct lstcon_rpc_trans,
-					   tas_link);
-
+		list_for_each_entry(trans, &console_session.ses_trans_list,
+				    tas_link) {
 			CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
 			       lstcon_rpc_trans_name(trans->tas_opc));
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 29 lines · Gargi Sharma

Use list_for_each_entry() rather than a combination of list_for_each() and list_entry() since the former does not expose the list spine.

Done using Coccinelle:
@a@
expression pos, n, mem;
type t;
identifier var;
iterator name list_for_each_entry, list_for_each;
@@

- list_for_each(pos, n)
+ list_for_each_entry(var, n, mem)
{
... when != var
- var = list_entry(pos, t, mem);
... when != pos
}

---
 drivers/staging/lustre/lnet/selftest/conrpc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/lustre/lnet/selftest/conrpc.c +0 -0
index c6a683b..72b6ff2 100644

drivers/staging/lustre/lnet/selftest/conrpc.c lstcon_rpc_cleanup_wait(void) · line 1343

Quoted 9 lines
drivers/staging/lustre/lnet/selftest/conrpc.c +2 -4
@@ -1339,10 +1339,8 @@ lstcon_rpc_cleanup_wait(void)
 	LASSERT(console_session.ses_shutdown);
 
 	while (!list_empty(&console_session.ses_trans_list)) {
-		list_for_each(pacer, &console_session.ses_trans_list) {
-			trans = list_entry(pacer, struct lstcon_rpc_trans,
-					   tas_link);
-
+		list_for_each_entry(trans, &console_session.ses_trans_list,
+				    tas_link) {

I'm not sure to understand this code, in particular the outer while loop. Who is removing elements from the list? If that can happen with in the list_for_each/list_for_each_entry, then a safer version of the iterator is needed.

julia

Quoted 13 lines
drivers/staging/lustre/lnet/selftest/conrpc.c +0 -1
 			CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
 			       lstcon_rpc_trans_name(trans->tas_opc));
 
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488273521-29919-1-git-send-email-gs051095%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
Quoted 24 lines · Julia Lawall
Quoted 19 lines · Gargi Sharma

Use list_for_each_entry() rather than a combination of list_for_each() and list_entry() since the former does not expose the list spine.

Done using Coccinelle:
@a@
expression pos, n, mem;
type t;
identifier var;
iterator name list_for_each_entry, list_for_each;
@@

- list_for_each(pos, n)
+ list_for_each_entry(var, n, mem)
{
... when != var
- var = list_entry(pos, t, mem);
... when != pos
}

Quoted 6 lines

Review

Quoted 6 lines
---
 drivers/staging/lustre/lnet/selftest/conrpc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/lustre/lnet/selftest/conrpc.c

Quoted 6 lines
Quoted 6 lines

index c6a683b..72b6ff2 100644

drivers/staging/lustre/lnet/selftest/conrpc.c +0 -0
@@ -1339,10 +1339,8 @@ lstcon_rpc_cleanup_wait(void)
      LASSERT(console_session.ses_shutdown);
 
Quoted 6 lines

drivers/staging/lustre/lnet/selftest/conrpc.c lstcon_rpc_cleanup_wait(void)

Quoted 6 lines
drivers/staging/lustre/lnet/selftest/conrpc.c +1 -4
      while (!list_empty(&console_session.ses_trans_list)) {
-             list_for_each(pacer, &console_session.ses_trans_list) {
-                     trans = list_entry(pacer, struct lstcon_rpc_trans,
-                                        tas_link);
-
+             list_for_each_entry(trans,

&console_session.ses_trans_list,

Quoted 4 lines

drivers/staging/lustre/lnet/selftest/conrpc.c lstcon_rpc_cleanup_wait(void) · line 1343

Quoted 1 line
drivers/staging/lustre/lnet/selftest/conrpc.c +1 -0
+                                 tas_link) {

I'm not sure to understand this code, in particular the outer while loop. Who is removing elements from the list?

Actually, there is no code to remove elements from the list. I think I might have done something wrong here. From what I gather list_for_each increments the pointer to the list so that wen one iterates over the whole list, list_empty now
returns true. So, before exiting from this while loop (which is only executed once),
you execute a set of instructions(which are a timeout and setting a state in this case).
In the case of list_for_each_entry this will never happen and it'll be stuck in an infinite
loop.

gargi

Quoted 7 lines

If that can happen with in the list_for_each/list_for_each_entry, then a safer version of the iterator is needed.

julia

Quoted 1 line
drivers/staging/lustre/lnet/selftest/conrpc.c +0 -0
                      CDEBUG(D_NET, "Session closed, wakeup transaction

%s\n",

Quoted 7 lines
Quoted 7 lines
drivers/staging/lustre/lnet/selftest/conrpc.c +0 -1
                             lstcon_rpc_trans_name(trans->tas_opc));
 
--

2.7.4

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line
Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected].

Quoted 2 lines
Quoted 2 lines

To post to this group, send email to [email protected]. To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/1488273521-29919-1-git-send-email-gs051095%40gmail.com
.

Quoted 2 lines
Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

#3 lore raw
Quoted 49 lines · Gargi Sharma
Quoted 24 lines · Julia Lawall
Quoted 19 lines · Gargi Sharma

Use list_for_each_entry() rather than a combination of list_for_each() and list_entry() since the former does not expose the list spine.

Done using Coccinelle:
@a@
expression pos, n, mem;
type t;
identifier var;
iterator name list_for_each_entry, list_for_each;
@@

- list_for_each(pos, n)
+ list_for_each_entry(var, n, mem)
ᅵ {
ᅵ ... when != var
- var = list_entry(pos, t, mem);
ᅵ ... when != pos
ᅵ }

Quoted 6 lines

Review

Quoted 6 lines

---
ᅵdrivers/staging/lustre/lnet/selftest/conrpc.c | 6 ++---- ᅵ1 file changed, 2 insertions(+), 4 deletions(-)

(quoted diff) +0 -0

b/drivers/staging/lustre/lnet/selftest/conrpc.c

Quoted 6 lines
Quoted 6 lines

index c6a683b..72b6ff2 100644

drivers/staging/lustre/lnet/selftest/conrpc.c +0 -0
@@ -1339,10 +1339,8 @@ lstcon_rpc_cleanup_wait(void)
 ᅵ ᅵ ᅵ LASSERT(console_session.ses_shutdown);
 
Quoted 6 lines

drivers/staging/lustre/lnet/selftest/conrpc.c lstcon_rpc_cleanup_wait(void) · line 1342

Quoted 6 lines
drivers/staging/lustre/lnet/selftest/conrpc.c +1 -4
 ᅵ ᅵ ᅵ while (!list_empty(&console_session.ses_trans_list)) {
- ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ list_for_each(pacer, &console_session.ses_trans_list) {
- ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ trans = list_entry(pacer, struct lstcon_rpc_trans,
- ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵtas_link);
-
+ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ list_for_each_entry(trans,

&console_session.ses_trans_list,

Quoted 4 lines

drivers/staging/lustre/lnet/selftest/conrpc.c lstcon_rpc_cleanup_wait(void) · line 1343

Quoted 1 line
drivers/staging/lustre/lnet/selftest/conrpc.c +1 -0
+ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ tas_link) {

I'm not sure to understand this code, in particular the outer while loop. Who is removing elements from the list? ᅵ

Quoted 11 lines

Actually, there is no code to remove elements from the list. I think I might have done something wrong here. From what I gather list_for_each increments the pointer to the list so that wen one iterates over the whole list, list_empty now
returns true. So, before exiting from this while loop (which is only executed once),
you execute a set of instructions(which are a timeout and setting a state in this case).
In the case of list_for_each_entry this will never happen and it'll be stuck in an infinite
loop.

Something is going on with the calls to wake_up and schedule_timeout. Some other process is removing things from the list. Actually, looking further up in the code there is a comment that says "Called with hold of global mutex". So perhaps this implies that the woken up processes cannot run until schedule_timeout is called, and thus can't interrupt the list_for_each.

julia

Quoted 28 lines

gargi

Quoted 7 lines

If that can happen with in the list_for_each/list_for_each_entry, then a safer version of the iterator is needed.

julia

Quoted 1 line

ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ CDEBUG(D_NET, "Session closed, wakeup transaction

%s\n",

Quoted 7 lines
Quoted 7 lines

ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵlstcon_rpc_trans_name(trans->tas_opc));

--
2.7.4

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line
Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected].

Quoted 2 lines
Quoted 2 lines

To post to this group, send email to [email protected].
To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/1488273521-29919-1-git-s

end-email-gs051095%40gmail.com.

Quoted 2 lines
Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

#4 lore raw
Quoted 6 lines · Julia Lawall
Quoted 1 line · Gargi Sharma

On Tue, Feb 28, 2017 at 3:57 PM, Julia Lawall <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 6 lines · Gargi Sharma
Quoted 2 lines

Use list_for_each_entry() rather than a combination of

list_for_each()

Quoted 25 lines
Quoted 25 lines
Quoted 18 lines
Quoted 18 lines

and list_entry() since the former does not expose the list spine.

Done using Coccinelle:
@a@
expression pos, n, mem;
type t;
identifier var;
iterator name list_for_each_entry, list_for_each;
@@

- list_for_each(pos, n)
+ list_for_each_entry(var, n, mem)
{
... when != var
- var = list_entry(pos, t, mem);
... when != pos
}

Quoted 6 lines

Review

Quoted 6 lines
---
 drivers/staging/lustre/lnet/selftest/conrpc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/lustre/lnet/selftest/conrpc.c

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/staging/lustre/lnet/selftest/conrpc.c lstcon_rpc_cleanup_wait(void) · line 1342

Quoted 8 lines

index c6a683b..72b6ff2 100644

drivers/staging/lustre/lnet/selftest/conrpc.c +0 -1
@@ -1339,10 +1339,8 @@ lstcon_rpc_cleanup_wait(void)
      LASSERT(console_session.ses_shutdown);
 
      while (!list_empty(&console_session.ses_trans_list)) {
-             list_for_each(pacer, &console_session.ses_trans_list)

{

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/staging/lustre/lnet/selftest/conrpc.c lstcon_rpc_cleanup_wait(void) · line 1343

Quoted 1 line
drivers/staging/lustre/lnet/selftest/conrpc.c +0 -1
-                     trans = list_entry(pacer, struct

lstcon_rpc_trans,

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

drivers/staging/lustre/lnet/selftest/conrpc.c lstcon_rpc_cleanup_wait(void)

Quoted 3 lines
drivers/staging/lustre/lnet/selftest/conrpc.c +1 -2
-                                        tas_link);
-
+             list_for_each_entry(trans,

&console_session.ses_trans_list,

Quoted 3 lines

drivers/staging/lustre/lnet/selftest/conrpc.c lstcon_rpc_cleanup_wait(void) · line 1343

Quoted 1 line
drivers/staging/lustre/lnet/selftest/conrpc.c +1 -0
+                                 tas_link) {

I'm not sure to understand this code, in particular the outer while

loop.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

Who is removing elements from the list?

Actually, there is no code to remove elements from the list. I think I

might

Quoted 1 line
Quoted 1 line

have done something wrong here. From what I gather list_for_each

increments

Quoted 5 lines
Quoted 5 lines

the pointer to the list so that wen one iterates over the whole list, list_empty now
returns true. So, before exiting from this while loop (which is only executed once),
you execute a set of instructions(which are a timeout and setting a

state in

Quoted 2 lines
Quoted 2 lines

this case).
In the case of list_for_each_entry this will never happen and it'll be

stuck

Quoted 5 lines
Quoted 2 lines

in an infinite
loop.

Something is going on with the calls to wake_up and schedule_timeout. Some other process is removing things from the list.

I looked at the function body of wake_up and schedule_timeout and none of them have provisions to remove elements from the list. wake_up tries running
tasks for list head pointer passed to it and schedule_timeout simply causes the
thread to sleep until timeout.

Quoted 5 lines

Actually,
looking further up in the code there is a comment that says "Called with hold of global mutex". So perhaps this implies that the woken up processes cannot run until schedule_timeout is called, and thus can't interrupt the list_for_each.

From what I can understand, the intent is to not interrupt list_for_each, but
I still don't understand the significance/necessity of the outer while loop.

gargi

Quoted 8 lines

julia

Quoted 5 lines

gargi

Quoted 2 lines

If that can happen with in the list_for_each/list_for_each_entry, then a safer version of the

iterator is

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

needed.

julia

Quoted 1 line
drivers/staging/lustre/lnet/selftest/conrpc.c +0 -0
                      CDEBUG(D_NET, "Session closed, wakeup

transaction

Quoted 10 lines
Quoted 10 lines

%s\n",

Quoted 7 lines
Quoted 7 lines
drivers/staging/lustre/lnet/selftest/conrpc.c +0 -1
                             lstcon_rpc_trans_name(trans->tas_opc));
 
--

2.7.4

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line
Quoted 1 line

To unsubscribe from this group and stop receiving emails from it,

send

Quoted 2 lines
Quoted 2 lines

an email to [email protected].

Quoted 1 line
Quoted 1 line

To post to this group, send email to

[email protected].

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

To view this discussion on the web visithttps://

groups.google.com/d/msgid/outreachy-kernel/1488273521-29919-1-git-s

Quoted 5 lines
Quoted 5 lines

end-email-gs051095%40gmail.com.

Quoted 2 lines
Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.