<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>I would also dispute the logic in this particular Coccinelle script more generally.</p>
<p><br>
</p>
<p>list_for_each_entry_safe and while(list_empty(&amp;list) ==&nbsp;0) &nbsp;(or, more clearly, while(!list_empty(&amp;list))) are NOT equivalent.</p>
<p><br>
</p>
<p>Unless I've misunderstood the &quot;for&quot; loop used, that will run once for each item in the list, 'while'&nbsp;will run until the list is empty. &nbsp;They just aren't the same thing, and can't be swapped one for one in general.&nbsp; Sure, sometimes the usage is equivalent,
 but this coccinelle script can at most flag candidates for a change (which must be checked), it can't be used to just generate patches.</p>
<p><br>
</p>
<p>- Patrick</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> lustre-devel &lt;lustre-devel-bounces@lists.lustre.org&gt; on behalf of James Simmons &lt;jsimmons@infradead.org&gt;<br>
<b>Sent:</b> Monday, March 6, 2017 9:20:49 AM<br>
<b>To:</b> simran singhal<br>
<b>Cc:</b> devel@driverdev.osuosl.org; gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org; oleg.drokin@intel.com; outreachy-kernel@googlegroups.com; lustre-devel@lists.lustre.org<br>
<b>Subject:</b> Re: [lustre-devel] [PATCH 5/5] staging: lustre: osc_page.c: Use list_for_each_entry_safe</font>
<div>&nbsp;</div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText"><br>
&gt; Doubly linked lists which are&nbsp; iterated&nbsp; using list_empty<br>
&gt; and list_entry macros have been replaced with list_for_each_entry_safe<br>
&gt; macro.<br>
&gt; This makes the iteration simpler and more readable.<br>
&gt; <br>
&gt; This patch replaces the while loop containing list_empty and list_entry<br>
&gt; with list_for_each_entry_safe.<br>
&gt; <br>
&gt; This was done with Coccinelle.<br>
&gt; <br>
&gt; @@<br>
&gt; expression E1;<br>
&gt; identifier I1, I2;<br>
&gt; type T;<br>
&gt; iterator name list_for_each_entry_safe;<br>
&gt; @@<br>
&gt; <br>
&gt; T *I1;<br>
&gt; &#43; T *tmp;<br>
&gt; ...<br>
&gt; - while (list_empty(&amp;E1) == 0)<br>
&gt; &#43; list_for_each_entry_safe (I1, tmp, &amp;E1, I2)<br>
&gt; {<br>
&gt; ...when != T *I1;<br>
&gt; - I1 = list_entry(E1.next, T, I2);<br>
&gt; ...<br>
&gt; }<br>
&gt; <br>
&gt; Signed-off-by: simran singhal &lt;singhalsimran0@gmail.com&gt;<br>
<br>
NAK!!!!!!<br>
<br>
This change was reverted in commit <br>
<br>
cd15dd6ef4ea11df87f717b8b1b83aaa738ec8af<br>
<br>
Doing these while (list_empty(..)) to list_for_entry...<br>
are not simple changes and have broken things in lustre<br>
before. Unless you really understand the state machine of<br>
the lustre code I don't recommend these kinds of change<br>
for lustre.<br>
<br>
&gt; ---<br>
&gt;&nbsp; drivers/staging/lustre/lustre/osc/osc_page.c | 11 &#43;&#43;&#43;&#43;-------<br>
&gt;&nbsp; 1 file changed, 4 insertions(&#43;), 7 deletions(-)<br>
&gt; <br>
&gt; diff --git a/drivers/staging/lustre/lustre/osc/osc_page.c b/drivers/staging/lustre/lustre/osc/osc_page.c<br>
&gt; index ed8a0dc..e8b974f 100644<br>
&gt; --- a/drivers/staging/lustre/lustre/osc/osc_page.c<br>
&gt; &#43;&#43;&#43; b/drivers/staging/lustre/lustre/osc/osc_page.c<br>
&gt; @@ -542,6 &#43;542,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct cl_object *clobj = NULL;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct cl_page **pvec;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct osc_page *opg;<br>
&gt; &#43;&nbsp;&nbsp;&nbsp;&nbsp; struct osc_page *tmp;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int maxscan = 0;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long count = 0;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int index = 0;<br>
&gt; @@ -572,7 &#43;573,7 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (force)<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cli-&gt;cl_lru_reclaim&#43;&#43;;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxscan = min(target &lt;&lt; 1, atomic_long_read(&amp;cli-&gt;cl_lru_in_list));<br>
&gt; -&nbsp;&nbsp;&nbsp;&nbsp; while (!list_empty(&amp;cli-&gt;cl_lru_list)) {<br>
&gt; &#43;&nbsp;&nbsp;&nbsp;&nbsp; list_for_each_entry_safe(opg, tmp, &amp;cli-&gt;cl_lru_list, ops_lru) {<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct cl_page *page;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool will_free = false;<br>
&gt;&nbsp; <br>
&gt; @@ -582,8 &#43;583,6 @@ long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (--maxscan &lt; 0)<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>
&gt;&nbsp; <br>
&gt; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opg = list_entry(cli-&gt;cl_lru_list.next, struct osc_page,<br>
&gt; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ops_lru);<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page = opg-&gt;ops_cl.cpl_page;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (lru_page_busy(cli, page)) {<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list_move_tail(&amp;opg-&gt;ops_lru, &amp;cli-&gt;cl_lru_list);<br>
&gt; @@ -1043,6 &#43;1042,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,<br>
&gt;&nbsp; {<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct client_obd *stop_anchor = NULL;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct client_obd *cli;<br>
&gt; &#43;&nbsp;&nbsp;&nbsp;&nbsp; struct client_obd *tmp;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct lu_env *env;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long shrank = 0;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; u16 refcheck;<br>
&gt; @@ -1059,10 &#43;1059,7 @@ unsigned long osc_cache_shrink_scan(struct shrinker *sk,<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return SHRINK_STOP;<br>
&gt;&nbsp; <br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; spin_lock(&amp;osc_shrink_lock);<br>
&gt; -&nbsp;&nbsp;&nbsp;&nbsp; while (!list_empty(&amp;osc_shrink_list)) {<br>
&gt; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cli = list_entry(osc_shrink_list.next, struct client_obd,<br>
&gt; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cl_shrink_list);<br>
&gt; -<br>
&gt; &#43;&nbsp;&nbsp;&nbsp;&nbsp; list_for_each_entry_safe(cli, tmp, &amp;osc_shrink_list, cl_shrink_list) {<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!stop_anchor)<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stop_anchor = cli;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (cli == stop_anchor)<br>
&gt; -- <br>
&gt; 2.7.4<br>
&gt; <br>
&gt; <br>
_______________________________________________<br>
lustre-devel mailing list<br>
lustre-devel@lists.lustre.org<br>
<a href="http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org">http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org</a><br>
</div>
</span></font>
</body>
</html>