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 1/4] ocfs2: debug_lockres_ops should properly handle position index
Date: Tue, 14 Apr 2020 09:17:01 +0300	[thread overview]
Message-ID: <a77539f7-b602-39de-dabc-d15ad43e110e@virtuozzo.com> (raw)
In-Reply-To: <085dc97b-de01-1d95-799d-dc795eec7818@virtuozzo.com>

Currently debug_lockres_ops ignores position index argument,
and it leads to incorrect output in case of read with offset.
Link: https://oss.oracle.com/pipermail/ocfs2-devel/2020-March/014822.html

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

debug_lockres_ops was reworked to satisfy these requirements:
- .start and .next functions iterates on dlm->tracking_list
    by using seq_list_* primitives
- .show generates output related to selected dlm_lock_resource
- .stop function is used to release taken dlm_lock_resource

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!KOf5kpSuieredwp9lEzV0BQklJAQy4ix8PUtCrqkLdv2TsSnX570XW7JT9gBvV6thJkj2g$ 
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
 fs/ocfs2/dlm/dlmdebug.c | 78 ++++++++++++++++++++---------------------
 1 file changed, 39 insertions(+), 39 deletions(-)

diff --git a/fs/ocfs2/dlm/dlmdebug.c b/fs/ocfs2/dlm/dlmdebug.c
index 4b8b41d23e91..1887affbbf2c 100644
--- a/fs/ocfs2/dlm/dlmdebug.c
+++ b/fs/ocfs2/dlm/dlmdebug.c
@@ -542,63 +542,63 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
 {
 	struct debug_lockres *dl = m->private;
 	struct dlm_ctxt *dlm = dl->dl_ctxt;
-	struct dlm_lock_resource *oldres = dl->dl_res;
 	struct dlm_lock_resource *res = NULL;
-	struct list_head *track_list;
+	struct list_head *lh;
 
 	spin_lock(&dlm->track_lock);
-	if (oldres)
-		track_list = &oldres->tracking;
-	else {
-		track_list = &dlm->tracking_list;
-		if (list_empty(track_list)) {
-			dl = NULL;
-			spin_unlock(&dlm->track_lock);
-			goto bail;
-		}
-	}
-
-	list_for_each_entry(res, track_list, tracking) {
-		if (&res->tracking == &dlm->tracking_list)
-			res = NULL;
-		else
-			dlm_lockres_get(res);
-		break;
+	lh = seq_list_start(&dlm->tracking_list, *pos);
+	if (lh) {
+		res = list_entry(lh, struct dlm_lock_resource, tracking);
+		dlm_lockres_get(res);
 	}
+	dl->dl_res = res;
 	spin_unlock(&dlm->track_lock);
+	/* passed to seq_show */
+	return res ? dl : NULL;
+}
 
-	if (oldres)
-		dlm_lockres_put(oldres);
+static void *lockres_seq_next(struct seq_file *m, void *v, loff_t *pos)
+{
+	struct debug_lockres *dl = (struct debug_lockres *)v;
+	struct dlm_ctxt *dlm = dl->dl_ctxt;
+	struct dlm_lock_resource *oldres = dl->dl_res;
+	struct dlm_lock_resource *res = NULL;
+	struct list_head *lh;
 
+	spin_lock(&dlm->track_lock);
+	lh = seq_list_next(&oldres->tracking, &dlm->tracking_list, pos);
+	if (lh) {
+		res = list_entry(lh, struct dlm_lock_resource, tracking);
+		dlm_lockres_get(res);
+	}
 	dl->dl_res = res;
-
-	if (res) {
-		spin_lock(&res->spinlock);
-		dump_lockres(res, dl->dl_buf, dl->dl_len - 1);
-		spin_unlock(&res->spinlock);
-	} else
-		dl = NULL;
-
-bail:
-	/* passed to seq_show */
-	return dl;
+	spin_unlock(&dlm->track_lock);
+	dlm_lockres_put(oldres);
+	return res ? dl : NULL;
 }
 
 static void lockres_seq_stop(struct seq_file *m, void *v)
 {
-}
+	struct debug_lockres *dl = (struct debug_lockres *)v;
+	struct dlm_lock_resource *res = dl->dl_res;
 
-static void *lockres_seq_next(struct seq_file *m, void *v, loff_t *pos)
-{
-	return NULL;
+	if (res) {
+		dlm_lockres_put(res);
+		dl->dl_res = NULL;
+	}
 }
 
-static int lockres_seq_show(struct seq_file *s, void *v)
+static int lockres_seq_show(struct seq_file *m, void *v)
 {
 	struct debug_lockres *dl = (struct debug_lockres *)v;
+	struct dlm_lock_resource *res = dl->dl_res;
 
-	seq_printf(s, "%s", dl->dl_buf);
-
+	if (res) {
+		spin_lock(&res->spinlock);
+		dump_lockres(res, dl->dl_buf, dl->dl_len - 1);
+		spin_unlock(&res->spinlock);
+		seq_printf(m, "%s", dl->dl_buf);
+	}
 	return 0;
 }
 
-- 
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             ` Vasily Averin [this message]
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             ` [Ocfs2-devel] [PATCH v3 4/4] ocfs2: sc_seq_ops " Vasily Averin
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=a77539f7-b602-39de-dabc-d15ad43e110e@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.