2005-04-17 00:20:36 +02:00
|
|
|
/**
|
|
|
|
* @file oprofilefs.c
|
|
|
|
*
|
|
|
|
* @remark Copyright 2002 OProfile authors
|
|
|
|
* @remark Read the file COPYING
|
|
|
|
*
|
|
|
|
* @author John Levon
|
|
|
|
*
|
|
|
|
* A simple filesystem for configuration and
|
|
|
|
* access of oprofile.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/oprofile.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include "oprof.h"
|
|
|
|
|
|
|
|
#define OPROFILEFS_MAGIC 0x6f70726f
|
|
|
|
|
|
|
|
DEFINE_SPINLOCK(oprofilefs_lock);
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
static struct inode *oprofilefs_get_inode(struct super_block *sb, int mode)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
struct inode *inode = new_inode(sb);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (inode) {
|
|
|
|
inode->i_mode = mode;
|
|
|
|
inode->i_uid = 0;
|
|
|
|
inode->i_gid = 0;
|
|
|
|
inode->i_blocks = 0;
|
|
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
|
|
|
|
}
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct super_operations s_ops = {
|
|
|
|
.statfs = simple_statfs,
|
|
|
|
.drop_inode = generic_delete_inode,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
ssize_t oprofilefs_str_to_user(char const *str, char __user *buf, size_t count, loff_t *offset)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
return simple_read_from_buffer(buf, count, offset, str, strlen(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define TMPBUFSIZE 50
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user *buf, size_t count, loff_t *offset)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
char tmpbuf[TMPBUFSIZE];
|
|
|
|
size_t maxlen = snprintf(tmpbuf, TMPBUFSIZE, "%lu\n", val);
|
|
|
|
if (maxlen > TMPBUFSIZE)
|
|
|
|
maxlen = TMPBUFSIZE;
|
|
|
|
return simple_read_from_buffer(buf, count, offset, tmpbuf, maxlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
int oprofilefs_ulong_from_user(unsigned long *val, char const __user *buf, size_t count)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
char tmpbuf[TMPBUFSIZE];
|
2007-03-28 18:12:34 +02:00
|
|
|
unsigned long flags;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (count > TMPBUFSIZE - 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
memset(tmpbuf, 0x0, TMPBUFSIZE);
|
|
|
|
|
|
|
|
if (copy_from_user(tmpbuf, buf, count))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-03-28 18:12:34 +02:00
|
|
|
spin_lock_irqsave(&oprofilefs_lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
*val = simple_strtoul(tmpbuf, NULL, 0);
|
2007-03-28 18:12:34 +02:00
|
|
|
spin_unlock_irqrestore(&oprofilefs_lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
unsigned long *val = file->private_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
return oprofilefs_ulong_to_user(*val, buf, count, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
unsigned long *value = file->private_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (*offset)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
retval = oprofilefs_ulong_from_user(value, buf, count);
|
|
|
|
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
static int default_open(struct inode *inode, struct file *filp)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-09-27 10:50:46 +02:00
|
|
|
if (inode->i_private)
|
|
|
|
filp->private_data = inode->i_private;
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-12 09:55:34 +01:00
|
|
|
static const struct file_operations ulong_fops = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.read = ulong_read_file,
|
|
|
|
.write = ulong_write_file,
|
|
|
|
.open = default_open,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-12 09:55:34 +01:00
|
|
|
static const struct file_operations ulong_ro_fops = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.read = ulong_read_file,
|
|
|
|
.open = default_open,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
static struct dentry *__oprofilefs_create_file(struct super_block *sb,
|
|
|
|
struct dentry *root, char const *name, const struct file_operations *fops,
|
2005-04-17 00:20:36 +02:00
|
|
|
int perm)
|
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
struct dentry *dentry;
|
|
|
|
struct inode *inode;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
dentry = d_alloc_name(root, name);
|
|
|
|
if (!dentry)
|
|
|
|
return NULL;
|
|
|
|
inode = oprofilefs_get_inode(sb, S_IFREG | perm);
|
|
|
|
if (!inode) {
|
|
|
|
dput(dentry);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
inode->i_fop = fops;
|
|
|
|
d_add(dentry, inode);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root,
|
|
|
|
char const *name, unsigned long *val)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
struct dentry *d = __oprofilefs_create_file(sb, root, name,
|
2005-04-17 00:20:36 +02:00
|
|
|
&ulong_fops, 0644);
|
|
|
|
if (!d)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2006-09-27 10:50:46 +02:00
|
|
|
d->d_inode->i_private = val;
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root,
|
|
|
|
char const *name, unsigned long *val)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
struct dentry *d = __oprofilefs_create_file(sb, root, name,
|
2005-04-17 00:20:36 +02:00
|
|
|
&ulong_ro_fops, 0444);
|
|
|
|
if (!d)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2006-09-27 10:50:46 +02:00
|
|
|
d->d_inode->i_private = val;
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
atomic_t *val = file->private_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-12 09:55:34 +01:00
|
|
|
static const struct file_operations atomic_ro_fops = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.read = atomic_read_file,
|
|
|
|
.open = default_open,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
|
|
|
|
char const *name, atomic_t *val)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
struct dentry *d = __oprofilefs_create_file(sb, root, name,
|
2005-04-17 00:20:36 +02:00
|
|
|
&atomic_ro_fops, 0444);
|
|
|
|
if (!d)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2006-09-27 10:50:46 +02:00
|
|
|
d->d_inode->i_private = val;
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
int oprofilefs_create_file(struct super_block *sb, struct dentry *root,
|
|
|
|
char const *name, const struct file_operations *fops)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
if (!__oprofilefs_create_file(sb, root, name, fops, 0644))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root,
|
|
|
|
char const *name, const struct file_operations *fops, int perm)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
if (!__oprofilefs_create_file(sb, root, name, fops, perm))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
struct dentry *oprofilefs_mkdir(struct super_block *sb,
|
|
|
|
struct dentry *root, char const *name)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
struct dentry *dentry;
|
|
|
|
struct inode *inode;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
dentry = d_alloc_name(root, name);
|
|
|
|
if (!dentry)
|
|
|
|
return NULL;
|
|
|
|
inode = oprofilefs_get_inode(sb, S_IFDIR | 0755);
|
|
|
|
if (!inode) {
|
|
|
|
dput(dentry);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
inode->i_op = &simple_dir_inode_operations;
|
|
|
|
inode->i_fop = &simple_dir_operations;
|
|
|
|
d_add(dentry, inode);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 17:12:36 +02:00
|
|
|
static int oprofilefs_fill_super(struct super_block *sb, void *data, int silent)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-09-05 17:12:36 +02:00
|
|
|
struct inode *root_inode;
|
|
|
|
struct dentry *root_dentry;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
sb->s_blocksize = PAGE_CACHE_SIZE;
|
|
|
|
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
|
|
|
|
sb->s_magic = OPROFILEFS_MAGIC;
|
|
|
|
sb->s_op = &s_ops;
|
|
|
|
sb->s_time_gran = 1;
|
|
|
|
|
|
|
|
root_inode = oprofilefs_get_inode(sb, S_IFDIR | 0755);
|
|
|
|
if (!root_inode)
|
|
|
|
return -ENOMEM;
|
|
|
|
root_inode->i_op = &simple_dir_inode_operations;
|
|
|
|
root_inode->i_fop = &simple_dir_operations;
|
|
|
|
root_dentry = d_alloc_root(root_inode);
|
|
|
|
if (!root_dentry) {
|
|
|
|
iput(root_inode);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
sb->s_root = root_dentry;
|
|
|
|
|
|
|
|
oprofile_create_files(sb, root_dentry);
|
|
|
|
|
|
|
|
// FIXME: verify kill_litter_super removes our dentries
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 11:02:57 +02:00
|
|
|
static int oprofilefs_get_sb(struct file_system_type *fs_type,
|
|
|
|
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 11:02:57 +02:00
|
|
|
return get_sb_single(fs_type, flags, data, oprofilefs_fill_super, mnt);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct file_system_type oprofilefs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "oprofilefs",
|
|
|
|
.get_sb = oprofilefs_get_sb,
|
|
|
|
.kill_sb = kill_litter_super,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int __init oprofilefs_register(void)
|
|
|
|
{
|
|
|
|
return register_filesystem(&oprofilefs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void __exit oprofilefs_unregister(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&oprofilefs_type);
|
|
|
|
}
|