linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@osdl.org>
To: Simon Derr <Simon.Derr@bull.net>
Cc: linux-kernel@vger.kernel.org
Subject: (4/4) [PATCH] cpuset -- seqfile change
Date: Tue, 21 Oct 2003 16:20:34 -0700	[thread overview]
Message-ID: <20031021162034.7665533b.shemminger@osdl.org> (raw)
In-Reply-To: <Pine.A41.4.53.0310131503500.173334@isabelle.frec.bull.fr>

Printing the header in seq_start is not the way other callers to
seq_file interface do it, and it seems like it might be a problem
with seeking and other possibilities.

diff -Nru a/kernel/cpuset.c b/kernel/cpuset.c
--- a/kernel/cpuset.c	Tue Oct 21 15:53:11 2003
+++ b/kernel/cpuset.c	Tue Oct 21 15:53:11 2003
@@ -661,29 +661,33 @@
  */
 #ifdef CONFIG_CPUSETS_PROC
 
+static struct cpuset *proc_cpusets_idx(loff_t n)
+{
+	struct cpuset *set;
+	
+	list_for_each_entry(set, &top_cpuset, list) {
+		if (n-- == 0)
+			return set;
+	}
+	return NULL;
+}
+
 static void *proc_cpusets_start(struct seq_file *m, loff_t *pos)
 {
-        loff_t n = *pos;
-        struct list_head *p;
 
 	read_lock(&cpuset_lock); 
-        if (!n) seq_puts(m, "cpusets info \n");
-        
-	p = &top_cpuset.list;
-        while (n--) {
-                p = p->next;
-                if (p == &top_cpuset.list)
-                        return NULL;
-        }
-        return list_entry(p, struct cpuset, list);
+	return (*pos == 0) ? SEQ_START_TOKEN : proc_cpusets_idx(*pos);
 }
 
 static void *proc_cpusets_next(struct seq_file *m, void *p, loff_t *pos)
 {
-        struct cpuset * cs = p;
+        struct cpuset * cs;
         ++*pos;
-        return cs->list.next == &top_cpuset.list ? NULL
-                : list_entry(cs->list.next, struct cpuset, list);
+
+	cs = (p == SEQ_START_TOKEN) ? top_cpuset.list.next
+		: ((struct cpuset *)p)->list.next;
+
+	return (cs == &top_cpuset.list) ? NULL : cs;
 }
 
 /* How many chars needed to print a long (as a mask) ? */
@@ -713,25 +717,28 @@
 #else
 	char maskbuf[CFL + 1];
 #endif
+	if (p == SEQ_START_TOKEN) 
+		seq_puts(m, "cpusets info \n");
+	else {
+		seq_printf(m, "cpuset %d {\n"
+			   "\tparent = %d\n"
+			   "\tflags = %d\n"
+			   "\tcount = %d\n"
+			   "\thba = %d\n"
+			   "\tuid & suid = %d & %d\n",
+			   cs->id, cs->parent ? cs->parent->id : -1, 
+			   cs->flags, atomic_read(&cs->count), cs->has_been_attached,
+			   cs->uid, cs->suid);
+
+		sprint_mask(maskbuf, cs->cpus_allowed);
+		seq_printf(m,"\tcpus_allowed = %s\n", maskbuf);
+		sprint_mask(maskbuf, cs->cpus_reserved);
+		seq_printf(m,"\tcpus_reserved = %s\n", maskbuf);
+		sprint_mask(maskbuf, cs->cpus_strictly_reserved);
+		seq_printf(m,"\tcpus_strictly_reserved = %s\n", maskbuf);
 
-	seq_printf(m, "cpuset %d {\n"
-		"\tparent = %d\n"
-		"\tflags = %d\n"
-		"\tcount = %d\n"
-		"\thba = %d\n"
-		"\tuid & suid = %d & %d\n",
-		cs->id, cs->parent ? cs->parent->id : -1, 
-		cs->flags, atomic_read(&cs->count), cs->has_been_attached,
-		cs->uid, cs->suid);
-
-	sprint_mask(maskbuf, cs->cpus_allowed);
-	seq_printf(m,"\tcpus_allowed = %s\n", maskbuf);
-	sprint_mask(maskbuf, cs->cpus_reserved);
-	seq_printf(m,"\tcpus_reserved = %s\n", maskbuf);
-	sprint_mask(maskbuf, cs->cpus_strictly_reserved);
-	seq_printf(m,"\tcpus_strictly_reserved = %s\n", maskbuf);
-
-	seq_printf(m, "}\n\n");
+		seq_printf(m, "}\n\n");
+	}
 
 	return 0;
 }

      parent reply	other threads:[~2003-10-21 23:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-13 13:07 [RFC] cpuset proposal Simon Derr
2003-10-21 23:20 ` (1/4) [PATCH] cpuset -- 2.6.0-test8 Stephen Hemminger
2003-10-22  0:08   ` William Lee Irwin III
2003-10-22 14:34     ` Simon Derr
2003-10-22 14:57       ` William Lee Irwin III
2003-10-21 23:20 ` (2/4) [PATCH] cpuset - Kconfig Stephen Hemminger
2003-10-21 23:20 ` (3/4) [PATCH] cpuset - build without CPUSET configured Stephen Hemminger
2003-10-21 23:20 ` Stephen Hemminger [this message]

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=20031021162034.7665533b.shemminger@osdl.org \
    --to=shemminger@osdl.org \
    --cc=Simon.Derr@bull.net \
    --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;
as well as URLs for NNTP newsgroup(s).