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 <[email protected]>
Signed-off-by: Fengguang Wu <[email protected]>
---
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]