lkml.org 
[lkml]   [2007]   [Aug]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 3/4] maps: introduce generic_maps_open()
Introduce generic_maps_open(). It is an extended version of do_maps_open().
The new function supports batch_size and custom sized seqfile/private buffers.
This function will be reused by pmaps.

Cc: Matt Mackall <mpm@selenic.com>
Signed-off-by: Fengguang Wu <wfg@mail.ustc.edu.cn>
---
fs/proc/task_mmu.c | 51 ++++++++++++++++++++++++++++++-------------
1 file changed, 36 insertions(+), 15 deletions(-)

--- linux-2.6.23-rc2-mm2.orig/fs/proc/task_mmu.c
+++ linux-2.6.23-rc2-mm2/fs/proc/task_mmu.c
@@ -176,24 +176,45 @@ static void m_stop(struct seq_file *m, v
put_task_struct(priv->task);
}

+static int generic_maps_open(struct inode *inode, struct file *file,
+ struct seq_operations *ops, unsigned long batch_size,
+ int bufsize, int privsize)
+{
+ struct seq_file *m;
+ struct proc_maps_private *priv = NULL;
+ char *buf = NULL;
+ int ret = -ENOMEM;
+
+ priv = kzalloc(privsize, GFP_KERNEL);
+ if (!priv)
+ goto out;
+
+ buf = kmalloc(bufsize, GFP_KERNEL);
+ if (!buf)
+ goto out;
+
+ ret = seq_open(file, ops);
+ if (ret)
+ goto out;
+
+ m = file->private_data;
+ m->private = priv;
+ m->buf = buf;
+ m->size = bufsize;
+ priv->pid = proc_pid(inode);
+ priv->batch_size = batch_size;
+ return 0;
+out:
+ kfree(priv);
+ kfree(buf);
+ return ret;
+}
+
static int do_maps_open(struct inode *inode, struct file *file,
struct seq_operations *ops)
{
- struct proc_maps_private *priv;
- int ret = -ENOMEM;
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
- if (priv) {
- priv->pid = proc_pid(inode);
- priv->batch_size = ~0;
- ret = seq_open(file, ops);
- if (!ret) {
- struct seq_file *m = file->private_data;
- m->private = priv;
- } else {
- kfree(priv);
- }
- }
- return ret;
+ return generic_maps_open(inode, file, ops, ~0, 2 * PAGE_SIZE,
+ sizeof(struct proc_maps_private));
}

static int show_map(struct seq_file *m, void *v)
--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-08-19 09:59    [W:0.340 / U:0.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site