(4/4) [PATCH] cpuset -- seqfile change

From: Stephen Hemminger
Date: Tue Oct 21 2003 - 18:24:55 EST


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;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/