public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Cc: Christoph Hellwig <hch@infradead.org>,
	Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Subject: [patch 1/7] Seq_file add support for sorted list
Date: Mon, 24 Sep 2007 12:49:51 -0400	[thread overview]
Message-ID: <20070924165426.841607414@polymtl.ca> (raw)
In-Reply-To: 20070924164950.006047409@polymtl.ca

[-- Attachment #1: seq_file_sorted.patch --]
[-- Type: text/plain, Size: 3709 bytes --]

Add support for sorted list in seq_file. It aims at changing the way
/proc/modules and kallsyms iterates on the module list to remove a race between
module unload and module/symbol listing.

The list is sorted by ascending list_head pointer address.

Changelog:

When reading the data by small chunks (i.e. byte by byte), the index (ppos) is
incremented by seq_read() directly and no "next" callback is called when going
to the next module.

Therefore, use ppos instead of m->private to deal with the fact that this index
is incremented directly to pass to the next module in seq_read() after the
buffer has been emptied.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
 fs/seq_file.c            |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/seq_file.h |   20 ++++++++++++++++++++
 2 files changed, 67 insertions(+)

Index: linux-2.6-lttng/fs/seq_file.c
===================================================================
--- linux-2.6-lttng.orig/fs/seq_file.c	2007-08-25 14:39:03.000000000 -0400
+++ linux-2.6-lttng/fs/seq_file.c	2007-08-27 11:11:33.000000000 -0400
@@ -510,3 +510,50 @@ struct list_head *seq_list_next(void *v,
 }
 
 EXPORT_SYMBOL(seq_list_next);
+
+struct list_head *seq_sorted_list_start(struct list_head *head, loff_t *ppos)
+{
+	struct list_head *lh;
+
+	list_for_each(lh, head)
+		if ((unsigned long)lh >= *ppos) {
+			*ppos = (unsigned long)lh;
+			return lh;
+		}
+	return NULL;
+}
+
+EXPORT_SYMBOL(seq_sorted_list_start);
+
+struct list_head *seq_sorted_list_start_head(struct list_head *head,
+		loff_t *ppos)
+{
+	struct list_head *lh;
+
+	if (!*ppos) {
+		*ppos = (unsigned long)head;
+		return head;
+	}
+	list_for_each(lh, head)
+		if ((unsigned long)lh >= *ppos) {
+			*ppos = (long)lh->prev;
+			return lh->prev;
+		}
+	return NULL;
+}
+
+EXPORT_SYMBOL(seq_sorted_list_start_head);
+
+struct list_head *seq_sorted_list_next(void *p, struct list_head *head,
+		loff_t *ppos)
+{
+	struct list_head *lh;
+	void *next;
+
+	lh = ((struct list_head *)p)->next;
+	next = (lh == head) ? NULL : lh;
+	*ppos = next ? (unsigned long)next : -1UL;
+	return next;
+}
+
+EXPORT_SYMBOL(seq_sorted_list_next);
Index: linux-2.6-lttng/include/linux/seq_file.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/seq_file.h	2007-08-25 14:39:03.000000000 -0400
+++ linux-2.6-lttng/include/linux/seq_file.h	2007-08-27 11:11:33.000000000 -0400
@@ -63,5 +63,25 @@ extern struct list_head *seq_list_start_
 extern struct list_head *seq_list_next(void *v, struct list_head *head,
 		loff_t *ppos);
 
+/*
+ * Helpers for iteration over a list sorted by ascending head pointer address.
+ * To be used in contexts where preemption cannot be disabled to insure to
+ * continue iteration on a modified list starting at the same location where it
+ * stopped, or at a following location. It insures that the lost information
+ * will only be in elements added/removed from the list between iterations.
+ * void *pos is only used to get the next list element and may not be a valid
+ * list_head anymore when given to seq_sorted_list_start() or
+ * seq_sorted_list_start_head().
+ */
+extern struct list_head *seq_sorted_list_start(struct list_head *head,
+		loff_t *ppos);
+extern struct list_head *seq_sorted_list_start_head(struct list_head *head,
+		loff_t *ppos);
+/*
+ * next must be called with an existing p node
+ */
+extern struct list_head *seq_sorted_list_next(void *p, struct list_head *head,
+		loff_t *ppos);
+
 #endif
 #endif

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

  reply	other threads:[~2007-09-24 16:58 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-24 16:49 [patch 0/7] Linux Kernel Markers (redux) Mathieu Desnoyers
2007-09-24 16:49 ` Mathieu Desnoyers [this message]
2007-09-24 17:37   ` [patch 1/7] Seq_file add support for sorted list Christoph Hellwig
2007-09-24 17:52     ` Mathieu Desnoyers
2007-09-24 17:55       ` Christoph Hellwig
2007-09-24 16:49 ` [patch 2/7] Sort module list by pointer address to get coherent sleepable seq_file iterators Mathieu Desnoyers
2007-09-24 16:49 ` [patch 3/7] Combine instrumentation menus in kernel/Kconfig.instrumentation Mathieu Desnoyers
2007-09-24 16:49 ` [patch 4/7] Linux Kernel Markers - Architecture Independent Code Mathieu Desnoyers
2007-09-24 17:48   ` Christoph Hellwig
2007-09-24 18:15     ` Robert P. J. Day
2007-09-24 18:19       ` Christoph Hellwig
2007-09-24 18:22         ` Mathieu Desnoyers
2007-09-24 18:43     ` Mathieu Desnoyers
2007-09-24 18:45       ` Christoph Hellwig
2007-09-24 18:53         ` Mathieu Desnoyers
2007-09-24 16:49 ` [patch 5/7] Linux Kernel Markers - Use instrumentation kconfig menu Mathieu Desnoyers
2007-09-24 17:49   ` Christoph Hellwig
2007-09-24 18:45     ` Mathieu Desnoyers
2007-09-24 16:49 ` [patch 6/7] Linux Kernel Markers - Documentation Mathieu Desnoyers
2007-09-24 17:50   ` Christoph Hellwig
2007-09-24 17:56     ` Randy Dunlap
2007-09-24 18:00       ` Christoph Hellwig
2007-09-24 18:13         ` Randy Dunlap
2007-09-24 18:19           ` Christoph Hellwig
2007-09-24 18:23             ` Randy Dunlap
2007-09-24 18:30               ` Christoph Hellwig
2007-09-24 18:49                 ` Randy Dunlap
2007-09-24 18:54                   ` Christoph Hellwig
2007-09-24 18:56                     ` Randy Dunlap
2007-09-24 20:37                       ` Randy Dunlap
2007-09-24 21:08                         ` Mathieu Desnoyers
2007-09-24 21:12                           ` Randy Dunlap
2007-09-25  4:10                             ` Mathieu Desnoyers
2007-09-25  5:31                               ` Randy Dunlap
2007-09-25 11:00                                 ` Mathieu Desnoyers
2007-09-24 19:18     ` Mathieu Desnoyers
2007-09-24 19:25       ` Christoph Hellwig
2007-09-24 19:38         ` Randy Dunlap
2007-09-25  1:31     ` Steven Rostedt
2007-09-25  8:21       ` Christoph Hellwig
2007-09-24 16:49 ` [patch 7/7] Port of blktrace to the Linux Kernel Markers Mathieu Desnoyers
2007-09-24 18:11 ` [patch 0/7] Linux Kernel Markers (redux) Christoph Hellwig
2007-09-24 19:04   ` Mathieu Desnoyers
2007-09-24 19:07     ` Christoph Hellwig
2007-09-24 19:24       ` 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=20070924165426.841607414@polymtl.ca \
    --to=mathieu.desnoyers@polymtl.ca \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.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