2011-12-06 21:21:54 +04:00
/*
* fs / proc_namespace . c - handling of / proc / < pid > / { mounts , mountinfo , mountstats }
*
* In fact , that ' s a piece of procfs ; it ' s * almost * isolated from
* the rest of fs / proc , but has rather close relationships with
* fs / namespace . c , thus here instead of fs / proc
*
*/
# include <linux/mnt_namespace.h>
# include <linux/nsproxy.h>
# include <linux/security.h>
# include <linux/fs_struct.h>
# include "proc/internal.h" /* only for get_proc_task() in ->open() */
# include "pnode.h"
# include "internal.h"
static unsigned mounts_poll ( struct file * file , poll_table * wait )
{
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
struct seq_file * m = file - > private_data ;
struct proc_mounts * p = m - > private ;
2011-12-06 21:21:54 +04:00
struct mnt_namespace * ns = p - > ns ;
unsigned res = POLLIN | POLLRDNORM ;
2013-09-29 18:59:59 +04:00
int event ;
2011-12-06 21:21:54 +04:00
poll_wait ( file , & p - > ns - > poll , wait ) ;
2013-09-29 18:59:59 +04:00
event = ACCESS_ONCE ( ns - > event ) ;
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
if ( m - > poll_event ! = event ) {
m - > poll_event = event ;
2011-12-06 21:21:54 +04:00
res | = POLLERR | POLLPRI ;
}
return res ;
}
struct proc_fs_info {
int flag ;
const char * str ;
} ;
static int show_sb_opts ( struct seq_file * m , struct super_block * sb )
{
static const struct proc_fs_info fs_info [ ] = {
{ MS_SYNCHRONOUS , " ,sync " } ,
{ MS_DIRSYNC , " ,dirsync " } ,
{ MS_MANDLOCK , " ,mand " } ,
2015-02-02 08:37:00 +03:00
{ MS_LAZYTIME , " ,lazytime " } ,
2011-12-06 21:21:54 +04:00
{ 0 , NULL }
} ;
const struct proc_fs_info * fs_infop ;
for ( fs_infop = fs_info ; fs_infop - > flag ; fs_infop + + ) {
if ( sb - > s_flags & fs_infop - > flag )
seq_puts ( m , fs_infop - > str ) ;
}
return security_sb_show_options ( m , sb ) ;
}
static void show_mnt_opts ( struct seq_file * m , struct vfsmount * mnt )
{
static const struct proc_fs_info mnt_info [ ] = {
{ MNT_NOSUID , " ,nosuid " } ,
{ MNT_NODEV , " ,nodev " } ,
{ MNT_NOEXEC , " ,noexec " } ,
{ MNT_NOATIME , " ,noatime " } ,
{ MNT_NODIRATIME , " ,nodiratime " } ,
{ MNT_RELATIME , " ,relatime " } ,
{ 0 , NULL }
} ;
const struct proc_fs_info * fs_infop ;
for ( fs_infop = mnt_info ; fs_infop - > flag ; fs_infop + + ) {
if ( mnt - > mnt_flags & fs_infop - > flag )
seq_puts ( m , fs_infop - > str ) ;
}
}
static inline void mangle ( struct seq_file * m , const char * s )
{
seq_escape ( m , s , " \t \n \\ " ) ;
}
static void show_type ( struct seq_file * m , struct super_block * sb )
{
mangle ( m , sb - > s_type - > name ) ;
if ( sb - > s_subtype & & sb - > s_subtype [ 0 ] ) {
seq_putc ( m , ' . ' ) ;
mangle ( m , sb - > s_subtype ) ;
}
}
static int show_vfsmnt ( struct seq_file * m , struct vfsmount * mnt )
{
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
struct proc_mounts * p = m - > private ;
2011-12-06 21:21:54 +04:00
struct mount * r = real_mount ( mnt ) ;
struct path mnt_path = { . dentry = mnt - > mnt_root , . mnt = mnt } ;
2011-12-09 06:32:45 +04:00
struct super_block * sb = mnt_path . dentry - > d_sb ;
2015-11-19 00:57:52 +03:00
int err ;
2011-12-06 21:21:54 +04:00
2011-12-09 06:32:45 +04:00
if ( sb - > s_op - > show_devname ) {
err = sb - > s_op - > show_devname ( m , mnt_path . dentry ) ;
2011-12-06 21:21:54 +04:00
if ( err )
goto out ;
} else {
mangle ( m , r - > mnt_devname ? r - > mnt_devname : " none " ) ;
}
seq_putc ( m , ' ' ) ;
2014-12-16 06:59:37 +03:00
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
err = seq_path_root ( m , & mnt_path , & p - > root , " \t \n \\ " ) ;
if ( err )
goto out ;
2011-12-06 21:21:54 +04:00
seq_putc ( m , ' ' ) ;
2011-12-09 06:32:45 +04:00
show_type ( m , sb ) ;
2011-12-06 21:21:54 +04:00
seq_puts ( m , __mnt_is_readonly ( mnt ) ? " ro " : " rw " ) ;
2011-12-09 06:32:45 +04:00
err = show_sb_opts ( m , sb ) ;
2011-12-06 21:21:54 +04:00
if ( err )
goto out ;
show_mnt_opts ( m , mnt ) ;
2011-12-09 06:32:45 +04:00
if ( sb - > s_op - > show_options )
2011-12-09 06:32:45 +04:00
err = sb - > s_op - > show_options ( m , mnt_path . dentry ) ;
2011-12-06 21:21:54 +04:00
seq_puts ( m , " 0 0 \n " ) ;
out :
return err ;
}
static int show_mountinfo ( struct seq_file * m , struct vfsmount * mnt )
{
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
struct proc_mounts * p = m - > private ;
2011-12-06 21:21:54 +04:00
struct mount * r = real_mount ( mnt ) ;
struct super_block * sb = mnt - > mnt_sb ;
struct path mnt_path = { . dentry = mnt - > mnt_root , . mnt = mnt } ;
2015-11-19 00:58:20 +03:00
int err ;
2011-12-06 21:21:54 +04:00
seq_printf ( m , " %i %i %u:%u " , r - > mnt_id , r - > mnt_parent - > mnt_id ,
MAJOR ( sb - > s_dev ) , MINOR ( sb - > s_dev ) ) ;
2015-11-19 00:58:20 +03:00
if ( sb - > s_op - > show_path ) {
2011-12-09 06:37:57 +04:00
err = sb - > s_op - > show_path ( m , mnt - > mnt_root ) ;
2015-11-19 00:58:20 +03:00
if ( err )
goto out ;
} else {
2011-12-06 21:21:54 +04:00
seq_dentry ( m , mnt - > mnt_root , " \t \n \\ " ) ;
2015-11-19 00:58:20 +03:00
}
2011-12-06 21:21:54 +04:00
seq_putc ( m , ' ' ) ;
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
2012-10-17 20:29:36 +04:00
err = seq_path_root ( m , & mnt_path , & p - > root , " \t \n \\ " ) ;
2011-12-06 21:21:54 +04:00
if ( err )
goto out ;
seq_puts ( m , mnt - > mnt_flags & MNT_READONLY ? " ro " : " rw " ) ;
show_mnt_opts ( m , mnt ) ;
/* Tagged fields ("foo:X" or "bar") */
if ( IS_MNT_SHARED ( r ) )
seq_printf ( m , " shared:%i " , r - > mnt_group_id ) ;
if ( IS_MNT_SLAVE ( r ) ) {
int master = r - > mnt_master - > mnt_group_id ;
int dom = get_dominating_id ( r , & p - > root ) ;
seq_printf ( m , " master:%i " , master ) ;
if ( dom & & dom ! = master )
seq_printf ( m , " propagate_from:%i " , dom ) ;
}
if ( IS_MNT_UNBINDABLE ( r ) )
seq_puts ( m , " unbindable " ) ;
/* Filesystem specific data */
seq_puts ( m , " - " ) ;
show_type ( m , sb ) ;
seq_putc ( m , ' ' ) ;
2015-11-19 00:58:20 +03:00
if ( sb - > s_op - > show_devname ) {
2011-12-09 06:32:45 +04:00
err = sb - > s_op - > show_devname ( m , mnt - > mnt_root ) ;
2015-11-19 00:58:20 +03:00
if ( err )
goto out ;
} else {
2011-12-06 21:21:54 +04:00
mangle ( m , r - > mnt_devname ? r - > mnt_devname : " none " ) ;
2015-11-19 00:58:20 +03:00
}
2011-12-06 21:21:54 +04:00
seq_puts ( m , sb - > s_flags & MS_RDONLY ? " ro " : " rw " ) ;
err = show_sb_opts ( m , sb ) ;
if ( err )
goto out ;
if ( sb - > s_op - > show_options )
2011-12-09 06:32:45 +04:00
err = sb - > s_op - > show_options ( m , mnt - > mnt_root ) ;
2011-12-06 21:21:54 +04:00
seq_putc ( m , ' \n ' ) ;
out :
return err ;
}
static int show_vfsstat ( struct seq_file * m , struct vfsmount * mnt )
{
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
struct proc_mounts * p = m - > private ;
2011-12-06 21:21:54 +04:00
struct mount * r = real_mount ( mnt ) ;
struct path mnt_path = { . dentry = mnt - > mnt_root , . mnt = mnt } ;
2011-12-09 05:51:13 +04:00
struct super_block * sb = mnt_path . dentry - > d_sb ;
2015-11-19 00:58:32 +03:00
int err ;
2011-12-06 21:21:54 +04:00
/* device */
2011-12-09 05:51:13 +04:00
if ( sb - > s_op - > show_devname ) {
2011-12-06 21:21:54 +04:00
seq_puts ( m , " device " ) ;
2011-12-09 06:32:45 +04:00
err = sb - > s_op - > show_devname ( m , mnt_path . dentry ) ;
2015-03-19 14:10:54 +03:00
if ( err )
goto out ;
2011-12-06 21:21:54 +04:00
} else {
if ( r - > mnt_devname ) {
seq_puts ( m , " device " ) ;
mangle ( m , r - > mnt_devname ) ;
} else
seq_puts ( m , " no device " ) ;
}
/* mount point */
seq_puts ( m , " mounted on " ) ;
2014-12-16 06:59:37 +03:00
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
err = seq_path_root ( m , & mnt_path , & p - > root , " \t \n \\ " ) ;
if ( err )
goto out ;
2011-12-06 21:21:54 +04:00
seq_putc ( m , ' ' ) ;
/* file system type */
seq_puts ( m , " with fstype " ) ;
2011-12-09 05:51:13 +04:00
show_type ( m , sb ) ;
2011-12-06 21:21:54 +04:00
/* optional statistics */
2011-12-09 05:51:13 +04:00
if ( sb - > s_op - > show_stats ) {
2011-12-06 21:21:54 +04:00
seq_putc ( m , ' ' ) ;
2015-11-19 00:58:32 +03:00
err = sb - > s_op - > show_stats ( m , mnt_path . dentry ) ;
2011-12-06 21:21:54 +04:00
}
seq_putc ( m , ' \n ' ) ;
2014-12-16 06:59:37 +03:00
out :
2011-12-06 21:21:54 +04:00
return err ;
}
static int mounts_open_common ( struct inode * inode , struct file * file ,
int ( * show ) ( struct seq_file * , struct vfsmount * ) )
{
struct task_struct * task = get_proc_task ( inode ) ;
struct nsproxy * nsp ;
struct mnt_namespace * ns = NULL ;
struct path root ;
struct proc_mounts * p ;
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
struct seq_file * m ;
2011-12-06 21:21:54 +04:00
int ret = - EINVAL ;
if ( ! task )
goto err ;
2014-02-04 07:13:49 +04:00
task_lock ( task ) ;
nsp = task - > nsproxy ;
2014-01-24 03:55:44 +04:00
if ( ! nsp | | ! nsp - > mnt_ns ) {
2014-02-04 07:13:49 +04:00
task_unlock ( task ) ;
2011-12-06 21:21:54 +04:00
put_task_struct ( task ) ;
goto err ;
}
ns = nsp - > mnt_ns ;
get_mnt_ns ( ns ) ;
if ( ! task - > fs ) {
task_unlock ( task ) ;
put_task_struct ( task ) ;
ret = - ENOENT ;
goto err_put_ns ;
}
get_fs_root ( task - > fs , & root ) ;
task_unlock ( task ) ;
put_task_struct ( task ) ;
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
ret = seq_open_private ( file , & mounts_op , sizeof ( struct proc_mounts ) ) ;
if ( ret )
2011-12-06 21:21:54 +04:00
goto err_put_path ;
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
m = file - > private_data ;
m - > poll_event = ns - > event ;
2011-12-06 21:21:54 +04:00
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
p = m - > private ;
2011-12-06 21:21:54 +04:00
p - > ns = ns ;
p - > root = root ;
p - > show = show ;
2014-02-27 23:40:10 +04:00
p - > cached_event = ~ 0ULL ;
2011-12-06 21:21:54 +04:00
return 0 ;
err_put_path :
path_put ( & root ) ;
err_put_ns :
put_mnt_ns ( ns ) ;
err :
return ret ;
}
static int mounts_release ( struct inode * inode , struct file * file )
{
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
struct seq_file * m = file - > private_data ;
struct proc_mounts * p = m - > private ;
2011-12-06 21:21:54 +04:00
path_put ( & p - > root ) ;
put_mnt_ns ( p - > ns ) ;
fs: use seq_open_private() for proc_mounts
A patchset to remove support for passing pre-allocated struct seq_file to
seq_open(). Such feature is undocumented and prone to error.
In particular, if seq_release() is used in release handler, it will
kfree() a pointer which was not allocated by seq_open().
So this patchset drops support for pre-allocated struct seq_file: it's
only of use in proc_namespace.c and can be easily replaced by using
seq_open_private()/seq_release_private().
Additionally, it documents the use of file->private_data to hold pointer
to struct seq_file by seq_open().
This patch (of 3):
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.
Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Mon Nov 7 17:15:34 2005 -0500
[PATCH] allow callers of seq_open do allocation themselves
Allow caller of seq_open() to kmalloc() seq_file + whatever else they
want and set ->private_data to it. seq_open() will then abstain from
doing allocation itself.
Such behavior is only used by mounts_open_common().
In order to drop support for such uncommon feature, proc_mounts is
converted to use seq_open_private(), which take care of allocating the
proc_mounts structure, making it available through ->private in struct
seq_file.
Conversely, proc_mounts is converted to use seq_release_private(), in
order to release the private structure allocated by seq_open_private().
Then, ->private is used directly instead of proc_mounts() macro to access
to the proc_mounts structure.
Link: http://lkml.kernel.org/r/cover.1433193673.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-01 00:57:30 +03:00
return seq_release_private ( inode , file ) ;
2011-12-06 21:21:54 +04:00
}
static int mounts_open ( struct inode * inode , struct file * file )
{
return mounts_open_common ( inode , file , show_vfsmnt ) ;
}
static int mountinfo_open ( struct inode * inode , struct file * file )
{
return mounts_open_common ( inode , file , show_mountinfo ) ;
}
static int mountstats_open ( struct inode * inode , struct file * file )
{
return mounts_open_common ( inode , file , show_vfsstat ) ;
}
const struct file_operations proc_mounts_operations = {
. open = mounts_open ,
. read = seq_read ,
. llseek = seq_lseek ,
. release = mounts_release ,
. poll = mounts_poll ,
} ;
const struct file_operations proc_mountinfo_operations = {
. open = mountinfo_open ,
. read = seq_read ,
. llseek = seq_lseek ,
. release = mounts_release ,
. poll = mounts_poll ,
} ;
const struct file_operations proc_mountstats_operations = {
. open = mountstats_open ,
. read = seq_read ,
. llseek = seq_lseek ,
. release = mounts_release ,
} ;