All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vasily Averin <vvs@virtuozzo.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH v3 4/4] ocfs2: sc_seq_ops should properly handle position index
Date: Tue, 14 Apr 2020 09:17:30 +0300	[thread overview]
Message-ID: <9994b940-bb66-3334-9a47-f821cc197e5d@virtuozzo.com> (raw)
In-Reply-To: <085dc97b-de01-1d95-799d-dc795eec7818@virtuozzo.com>

Currently sc_seq_ops ignores position index argument,
and it leads to incorrect output in case of read with offset.

By design .start function should skip first *pos elements,
and .next function must update position index unconditionally.

Cc: stable at vger.kernel.org
Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code ...")
Link: https://urldefense.com/v3/__https://bugzilla.kernel.org/show_bug.cgi?id=206283__;!!GqivPVa7Brio!MJIyl9g4rZXkCRJpUtfNR70zABIYk0zKHrl00gKDdYZpx41lpyanlE7z50esOWCIqgd95w$ 
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
 fs/ocfs2/cluster/netdebug.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/ocfs2/cluster/netdebug.c b/fs/ocfs2/cluster/netdebug.c
index 8ca8a407781b..832fd762e4ef 100644
--- a/fs/ocfs2/cluster/netdebug.c
+++ b/fs/ocfs2/cluster/netdebug.c
@@ -213,7 +213,8 @@ struct o2net_sock_debug {
 };
 
 static struct o2net_sock_container
-			*next_sc(struct o2net_sock_container *sc_start)
+			*next_sc(struct o2net_sock_container *sc_start,
+				 loff_t pos)
 {
 	struct o2net_sock_container *sc, *ret = NULL;
 
@@ -226,7 +227,7 @@ static struct o2net_sock_container
 			break;
 
 		/* use sc_page to detect real scs in the list */
-		if (sc->sc_page != NULL) {
+		if ((sc->sc_page != NULL) && (pos-- == 0)) {
 			ret = sc;
 			break;
 		}
@@ -241,7 +242,7 @@ static void *sc_seq_start(struct seq_file *seq, loff_t *pos)
 	struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock;
 
 	spin_lock(&o2net_debug_lock);
-	sc = next_sc(dummy_sc);
+	sc = next_sc(dummy_sc, *pos);
 	spin_unlock(&o2net_debug_lock);
 
 	return sc;
@@ -252,8 +253,9 @@ static void *sc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 	struct o2net_sock_debug *sd = seq->private;
 	struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock;
 
+	++(*pos);
 	spin_lock(&o2net_debug_lock);
-	sc = next_sc(dummy_sc);
+	sc = next_sc(dummy_sc, 0);
 	list_del_init(&dummy_sc->sc_net_debug_item);
 	if (sc)
 		list_add(&dummy_sc->sc_net_debug_item, &sc->sc_net_debug_item);
@@ -354,7 +356,7 @@ static int sc_seq_show(struct seq_file *seq, void *v)
 	struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock;
 
 	spin_lock(&o2net_debug_lock);
-	sc = next_sc(dummy_sc);
+	sc = next_sc(dummy_sc, 0);
 
 	if (sc) {
 		if (sd->dbg_ctxt == SHOW_SOCK_CONTAINERS)
-- 
2.17.1

  parent reply	other threads:[~2020-04-14  6:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ca1497b7-6a6e-8043-63c7-b17c094ebc05@virtuozzo.com>
2020-01-26  2:21 ` [Ocfs2-devel] [PATCH 1/4] lockres_seq_next should increase position index Joseph Qi
2020-02-26  6:52   ` [Ocfs2-devel] [PATCH v2 0/4] ocfs2: seq_file .next functions " Vasily Averin
2020-02-26  8:32     ` Joseph Qi
2020-03-09 11:32       ` piaojun
     [not found]       ` <e954f783-5a1c-8847-7b0d-298825ee06a4@huawei.com>
2020-03-21  4:24         ` [Ocfs2-devel] Fwd: " lishan
2020-03-22  7:27           ` Vasily Averin
2020-04-14  6:16             ` [Ocfs2-devel] [PATCH v3 0/4] ocfs2: seq_operation should properly handle " Vasily Averin
2020-04-14  6:17             ` [Ocfs2-devel] [PATCH v3 1/4] ocfs2: debug_lockres_ops " Vasily Averin
2020-04-14  6:17             ` [Ocfs2-devel] [PATCH v3 2/4] ocfs2: ocfs2_dlm_seq_ops " Vasily Averin
2020-04-14  6:17             ` [Ocfs2-devel] [PATCH v3 3/4] ocfs2: nst_seq_ops " Vasily Averin
2020-04-14  6:17             ` Vasily Averin [this message]
2020-02-26  6:53   ` [Ocfs2-devel] [PATCH v2 1/4] lockres_seq_next should increase " Vasily Averin
2020-02-26  6:53   ` [Ocfs2-devel] [PATCH v2 2/4] ocfs2_dlm_seq_next " Vasily Averin
2020-02-26  6:53   ` [Ocfs2-devel] [PATCH v2 3/4] nst_seq_next " Vasily Averin
2020-02-26  6:54   ` [Ocfs2-devel] [PATCH v2 4/4] sc_seq_next " Vasily Averin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9994b940-bb66-3334-9a47-f821cc197e5d@virtuozzo.com \
    --to=vvs@virtuozzo.com \
    --cc=ocfs2-devel@oss.oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.