[PATCH 3/5] Add and use seq_bitmap, seq_cpumask, seq_nodemask

From: Alexey Dobriyan
Date: Wed May 07 2008 - 17:36:34 EST


Cpuset proc code is directly playing with seq_file internals, for that add
seq_bitmap() and wrappers around it: seq_cpumask() and seq_nodemask(). They
use NR_CPUS and MAX_NUMNODES bits respectively.

Also they will be used by code /proc/irq/*/{smp_affinity,spurious} code.

Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---

fs/seq_file.c | 15 +++++++++++++++
include/linux/seq_file.h | 12 ++++++++++++
kernel/cpuset.c | 12 ++++--------
3 files changed, 31 insertions(+), 8 deletions(-)

--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -554,6 +554,21 @@ int seq_puts(struct seq_file *m, const char *s)
}
EXPORT_SYMBOL(seq_puts);

+int seq_bitmap(struct seq_file *m, unsigned long *bits, unsigned int nr_bits)
+{
+ size_t len = bitmap_scnprintf_len(nr_bits);
+
+ if (m->count + len < m->size) {
+ bitmap_scnprintf(m->buf + m->count, m->size - m->count,
+ bits, nr_bits);
+ m->count += len;
+ return 0;
+ }
+ m->count = m->size;
+ return -1;
+}
+EXPORT_SYMBOL(seq_bitmap);
+
struct list_head *seq_list_start(struct list_head *head, loff_t pos)
{
struct list_head *lh;
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -4,6 +4,8 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/mutex.h>
+#include <linux/cpumask.h>
+#include <linux/nodemask.h>

struct seq_operations;
struct file;
@@ -47,6 +49,16 @@ int seq_path(struct seq_file *, struct path *, char *);
int seq_dentry(struct seq_file *, struct dentry *, char *);
int seq_path_root(struct seq_file *m, struct path *path, struct path *root,
char *esc);
+int seq_bitmap(struct seq_file *m, unsigned long *bits, unsigned int nr_bits);
+static inline int seq_cpumask(struct seq_file *m, cpumask_t *mask)
+{
+ return seq_bitmap(m, mask->bits, NR_CPUS);
+}
+
+static inline int seq_nodemask(struct seq_file *m, nodemask_t *mask)
+{
+ return seq_bitmap(m, mask->bits, MAX_NUMNODES);
+}

int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
int single_release(struct inode *, struct file *);

--
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/