cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH 1/2] gfs2: remove usage of list iterator variable for list_for_each_entry_continue()
@ 2022-03-31 22:38 Jakob Koschel
  2022-03-31 22:38 ` [Cluster-devel] [PATCH 2/2] gfs2: replace usage of found with dedicated list iterator variable Jakob Koschel
  2022-04-04 14:58 ` [Cluster-devel] [PATCH 1/2] gfs2: remove usage of list iterator variable for list_for_each_entry_continue() Andreas Gruenbacher
  0 siblings, 2 replies; 5+ messages in thread
From: Jakob Koschel @ 2022-03-31 22:38 UTC (permalink / raw)
  To: cluster-devel.redhat.com

In preparation to limiting the scope of a list iterator to the list
traversal loop, use a dedicated pointer to iterate through the list [1].

Since that variable should not be used past the loop iteration, a
separate variable is used to 'remember the current location within the
loop'.

To either continue iterating from that position or start a new
iteration (if the previous iteration was complete) list_prepare_entry()
is used.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w at mail.gmail.com/ [1]
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 fs/gfs2/lops.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 6ba51cbb94cf..74e6d05cee2c 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -653,7 +653,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 				bool is_databuf)
 {
 	struct gfs2_log_descriptor *ld;
-	struct gfs2_bufdata *bd1 = NULL, *bd2;
+	struct gfs2_bufdata *bd1 = NULL, *bd2, *tmp1, *tmp2;
 	struct page *page;
 	unsigned int num;
 	unsigned n;
@@ -661,7 +661,7 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 
 	gfs2_log_lock(sdp);
 	list_sort(NULL, blist, blocknr_cmp);
-	bd1 = bd2 = list_prepare_entry(bd1, blist, bd_list);
+	tmp1 = tmp2 = list_prepare_entry(bd1, blist, bd_list);
 	while(total) {
 		num = total;
 		if (total > limit)
@@ -675,14 +675,18 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 		ptr = (__be64 *)(ld + 1);
 
 		n = 0;
+		bd1 = list_prepare_entry(tmp1, blist, bd_list);
+		tmp1 = NULL;
 		list_for_each_entry_continue(bd1, blist, bd_list) {
 			*ptr++ = cpu_to_be64(bd1->bd_bh->b_blocknr);
 			if (is_databuf) {
 				gfs2_check_magic(bd1->bd_bh);
 				*ptr++ = cpu_to_be64(buffer_escaped(bd1->bd_bh) ? 1 : 0);
 			}
-			if (++n >= num)
+			if (++n >= num) {
+				tmp1 = bd1;
 				break;
+			}
 		}
 
 		gfs2_log_unlock(sdp);
@@ -690,6 +694,8 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 		gfs2_log_lock(sdp);
 
 		n = 0;
+		bd2 = list_prepare_entry(tmp2, blist, bd_list);
+		tmp2 = NULL;
 		list_for_each_entry_continue(bd2, blist, bd_list) {
 			get_bh(bd2->bd_bh);
 			gfs2_log_unlock(sdp);
@@ -712,8 +718,10 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
 				gfs2_log_write_bh(sdp, bd2->bd_bh);
 			}
 			gfs2_log_lock(sdp);
-			if (++n >= num)
+			if (++n >= num) {
+				tmp2 = bd2;
 				break;
+			}
 		}
 
 		BUG_ON(total < num);

base-commit: f82da161ea75dc4db21b2499e4b1facd36dab275
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-08  0:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-31 22:38 [Cluster-devel] [PATCH 1/2] gfs2: remove usage of list iterator variable for list_for_each_entry_continue() Jakob Koschel
2022-03-31 22:38 ` [Cluster-devel] [PATCH 2/2] gfs2: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-04 14:42   ` Andreas Gruenbacher
2022-04-04 14:58 ` [Cluster-devel] [PATCH 1/2] gfs2: remove usage of list iterator variable for list_for_each_entry_continue() Andreas Gruenbacher
2022-04-08  0:09   ` Jakob Koschel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).