staging: lustre: lnet: Use list_for_each_entry()
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
@@ -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
Quoted 29 lines · Gargi Sharma
Use
list_for_each_entry()rather than a combination oflist_for_each()andlist_entry()since the former does not expose the list spine.Done using Coccinelle:
@a@
expression pos, n, mem;
type t;
identifier var;
iterator namelist_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
}Signed-off-by Gargi Sharma <[email protected]>--- drivers/staging/lustre/lnet/selftest/conrpc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/lustre/lnet/selftest/conrpc.c +0
-0
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
-1CDEBUG (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.
Quoted 24 lines · Julia Lawall
Quoted 19 lines · Gargi Sharma
Use
list_for_each_entry()rather than a combination oflist_for_each()andlist_entry()since the former does not expose the list spine.Done using Coccinelle:
@a@
expression pos, n, mem;
type t;
identifier var;
iterator namelist_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
Signed-off-by Gargi Sharma <[email protected]>--- 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
-4while (!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
-0CDEBUG(D_NET, "Session closed, wakeup transaction
%s\n",
Quoted 7 lines
Quoted 7 lines
drivers/staging/lustre/lnet/selftest/conrpc.c +0
-1lstcon_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
Quoted 2 lines
Quoted 2 lines
For more options, visit https://groups.google.com/d/optout.
Quoted 49 lines · Gargi Sharma
Quoted 24 lines · Julia Lawall
Quoted 19 lines · Gargi Sharma
Use
list_for_each_entry()rather than a combination oflist_for_each()andlist_entry()since the former does not expose the list spine.Done using Coccinelle:
@a@
expression pos, n, mem;
type t;
identifier var;
iterator namelist_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
Signed-off-by Gargi Sharma <[email protected]>---
ᅵ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.cQuoted 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_eachincrements the pointer to the list so that wen one iterates over the whole list,list_emptynow
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 oflist_for_each_entrythis 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 GoogleGroups "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-send-email-gs051095%40gmail.com.
Quoted 2 lines
Quoted 2 lines
For more options, visit https://groups.google.com/d/optout.
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 namelist_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
Signed-off-by Gargi Sharma <[email protected]>--- 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_emptynow
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 oflist_for_each_entrythis 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_upandschedule_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 untilschedule_timeoutis called, and thus can't interrupt thelist_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
-0CDEBUG(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
-1lstcon_rpc_trans_name(trans->tas_opc)); --2.7.4
--
You received this message because you are subscribed to the GoogleGroups "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
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.