From: Fengguang Wu <wfg@mail.ustc.edu.cn>
To: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
Randy Dunlap <rddunlap@osdl.org>,
Martin Bligh <mbligh@google.com>
Subject: Re: [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators
Date: Wed, 15 Aug 2007 11:39:45 +0800 [thread overview]
Message-ID: <387149185.77275@ustc.edu.cn> (raw)
Message-ID: <20070815033945.GA13134@mail.ustc.edu.cn> (raw)
In-Reply-To: <20070812151039.996081605@polymtl.ca>
On Sun, Aug 12, 2007 at 11:08:46AM -0400, Mathieu Desnoyers wrote:
>
> static void *m_next(struct seq_file *m, void *p, loff_t *pos)
> {
> - return seq_list_next(p, &modules, pos);
> + return seq_sorted_list_next(p, &modules, &m->private);
> }
In theory it is not safe to use something other than the passed in
*pos as an position indicator. Because seq_file do not always call
->next() to advance to the next item. Look at seq_file.c, it sometimes
increase the pos/index directly! Which also prevents pos to skip
forward, which is preferred in your case.
The attached patch tries to fix it.
The seq_file.c is so twisted!
Fengguang
===
seqfile: remove seq_file's assumption about iterators
The seq_file implementation has some hardcoded index++/pos++ lines,
which assumes iterators to be *continuous* integers.
This patch replaces the index++ lines with calls to m->next(), so that
seq_file users can freely use discrete forms of iterators, such as
ascending addresses.
Cc: Randy Dunlap <rddunlap@osdl.org>
Cc: Martin Bligh <mbligh@google.com>
Signed-off-by: Wu Fengguang <wfg@mail.ustc.edu.cn>
---
fs/seq_file.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
--- linux-2.6.22-git15.orig/fs/seq_file.c
+++ linux-2.6.22-git15/fs/seq_file.c
@@ -13,6 +13,8 @@
#include <asm/uaccess.h>
#include <asm/page.h>
+#define SEQFILE_SHOW_NEXT LONG_MAX
+
/**
* seq_open - initialize sequential file
* @file: file we initialize
@@ -93,6 +95,7 @@ ssize_t seq_read(struct file *file, char
/* if not empty - flush it first */
if (m->count) {
n = min(m->count, size);
+ BUG_ON(m->from == SEQFILE_SHOW_NEXT);
err = copy_to_user(buf, m->buf + m->from, n);
if (err)
goto Efault;
@@ -102,7 +105,7 @@ ssize_t seq_read(struct file *file, char
buf += n;
copied += n;
if (!m->count)
- m->index++;
+ m->from = SEQFILE_SHOW_NEXT;
if (!size)
goto Done;
}
@@ -113,9 +116,11 @@ ssize_t seq_read(struct file *file, char
err = PTR_ERR(p);
if (!p || IS_ERR(p))
break;
- err = m->op->show(m, p);
- if (err)
- break;
+ if (m->from != SEQFILE_SHOW_NEXT) {
+ err = m->op->show(m, p);
+ if (err)
+ break;
+ }
if (m->count < m->size)
goto Fill;
m->op->stop(m, p);
@@ -156,7 +161,7 @@ Fill:
if (m->count)
m->from = n;
else
- pos++;
+ m->from = SEQFILE_SHOW_NEXT;
m->index = pos;
Done:
if (!copied)
@@ -211,12 +216,9 @@ static int traverse(struct seq_file *m,
}
pos += m->count;
m->count = 0;
- if (pos == offset) {
- index++;
- m->index = index;
- break;
- }
p = m->op->next(m, p, &index);
+ if (pos == offset)
+ break;
}
m->op->stop(m, p);
return error;
next prev parent reply other threads:[~2007-08-15 3:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-12 15:08 [patch 0/2] Sorted seq_file Mathieu Desnoyers
2007-08-12 15:08 ` [patch 1/2] Seq_file add support for sorted list Mathieu Desnoyers
2007-08-12 15:08 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
[not found] ` <20070815033945.GA13134@mail.ustc.edu.cn>
2007-08-15 3:39 ` Fengguang Wu [this message]
2007-08-15 4:18 ` Al Viro
[not found] ` <20070815063741.GB5175@mail.ustc.edu.cn>
2007-08-15 6:37 ` Fengguang Wu
2007-08-15 6:53 ` Al Viro
[not found] ` <20070815083645.GA6544@mail.ustc.edu.cn>
2007-08-15 8:36 ` Fengguang Wu
[not found] ` <20070815084625.GA18892@mail.ustc.edu.cn>
2007-08-15 8:46 ` Fengguang Wu
2007-08-18 15:56 ` Mathieu Desnoyers
2007-08-18 16:09 ` [PATCH] Fix f_version type: should be u64 instead of unsigned long Mathieu Desnoyers
2007-08-24 15:39 ` [PATCH] Sort module list - use ppos instead of m->private Mathieu Desnoyers
2007-08-24 23:34 ` Andrew Morton
2007-08-25 0:05 ` Mathieu Desnoyers
-- strict thread matches above, loose matches on Subject: below --
2007-08-20 20:26 [patch 0/2] Sort module list Mathieu Desnoyers
2007-08-20 20:26 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
2007-08-21 0:08 ` Rusty Russell
2007-08-24 15:45 ` Mathieu Desnoyers
2007-08-25 21:44 ` Rusty Russell
2007-08-25 21:53 ` Mathieu Desnoyers
2007-08-27 16:02 [patch 0/2] Sort module list for /proc/modules seq file reads Mathieu Desnoyers
2007-08-27 16:02 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
2007-09-06 20:05 [patch 0/2] Sort module list for /proc/modules Mathieu Desnoyers
2007-09-06 20:05 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
2007-09-17 18:43 [patch 0/2] Sort module list Mathieu Desnoyers
2007-09-17 18:43 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
2007-09-18 21:09 [patch 0/2] Sorted Module List for 2.6.23-rc6-mm1 Mathieu Desnoyers
2007-09-18 21:09 ` [patch 2/2] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
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=387149185.77275@ustc.edu.cn \
--to=wfg@mail.ustc.edu.cn \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@polymtl.ca \
--cc=mbligh@google.com \
--cc=rddunlap@osdl.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox