Release 4.12 drivers/oprofile/oprofilefs.c
  
  
  
/**
 * @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 <linux/uaccess.h>
#include "oprof.h"
#define OPROFILEFS_MAGIC 0x6f70726f
DEFINE_RAW_SPINLOCK(oprofilefs_lock);
static struct inode *oprofilefs_get_inode(struct super_block *sb, int mode)
{
	struct inode *inode = new_inode(sb);
	if (inode) {
		inode->i_ino = get_next_ino();
		inode->i_mode = mode;
		inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
	}
	return inode;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 54 | 83.08% | 1 | 33.33% | 
| Christoph Hellwig | 7 | 10.77% | 1 | 33.33% | 
| Deepa Dinamani | 4 | 6.15% | 1 | 33.33% | 
| Total | 65 | 100.00% | 3 | 100.00% | 
static const struct super_operations s_ops = {
	.statfs		= simple_statfs,
	.drop_inode 	= generic_delete_inode,
};
ssize_t oprofilefs_str_to_user(char const *str, char __user *buf, size_t count, loff_t *offset)
{
	return simple_read_from_buffer(buf, count, offset, str, strlen(str));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 29 | 74.36% | 1 | 33.33% | 
| Al Viro | 10 | 25.64% | 2 | 66.67% | 
| Total | 39 | 100.00% | 3 | 100.00% | 
#define TMPBUFSIZE 50
ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user *buf, size_t count, loff_t *offset)
{
	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);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 56 | 86.15% | 1 | 33.33% | 
| Al Viro | 9 | 13.85% | 2 | 66.67% | 
| Total | 65 | 100.00% | 3 | 100.00% | 
/*
 * Note: If oprofilefs_ulong_from_user() returns 0, then *val remains
 * unchanged and might be uninitialized. This follows write syscall
 * implementation when count is zero: "If count is zero ... [and if]
 * no errors are detected, 0 will be returned without causing any
 * other effect." (man 2 write)
 */
int oprofilefs_ulong_from_user(unsigned long *val, char const __user *buf, size_t count)
{
	char tmpbuf[TMPBUFSIZE];
	unsigned long flags;
	if (!count)
		return 0;
	if (count > TMPBUFSIZE - 1)
		return -EINVAL;
	memset(tmpbuf, 0x0, TMPBUFSIZE);
	if (copy_from_user(tmpbuf, buf, count))
		return -EFAULT;
	raw_spin_lock_irqsave(&oprofilefs_lock, flags);
	*val = simple_strtoul(tmpbuf, NULL, 0);
	raw_spin_unlock_irqrestore(&oprofilefs_lock, flags);
	return count;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 92 | 88.46% | 2 | 33.33% | 
| Jiri Kosina | 8 | 7.69% | 1 | 16.67% | 
| Thomas Gleixner | 2 | 1.92% | 1 | 16.67% | 
| Robert Richter | 1 | 0.96% | 1 | 16.67% | 
| Al Viro | 1 | 0.96% | 1 | 16.67% | 
| Total | 104 | 100.00% | 6 | 100.00% | 
static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
{
	unsigned long *val = file->private_data;
	return oprofilefs_ulong_to_user(*val, buf, count, offset);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 44 | 97.78% | 2 | 66.67% | 
| Al Viro | 1 | 2.22% | 1 | 33.33% | 
| Total | 45 | 100.00% | 3 | 100.00% | 
static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
{
	unsigned long value;
	int retval;
	if (*offset)
		return -EINVAL;
	retval = oprofilefs_ulong_from_user(&value, buf, count);
	if (retval <= 0)
		return retval;
	retval = oprofile_set_ulong(file->private_data, value);
	if (retval)
		return retval;
	return count;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 60 | 73.17% | 1 | 25.00% | 
| Robert Richter | 21 | 25.61% | 2 | 50.00% | 
| Al Viro | 1 | 1.22% | 1 | 25.00% | 
| Total | 82 | 100.00% | 4 | 100.00% | 
static const struct file_operations ulong_fops = {
	.read		= ulong_read_file,
	.write		= ulong_write_file,
	.open		= simple_open,
	.llseek		= default_llseek,
};
static const struct file_operations ulong_ro_fops = {
	.read		= ulong_read_file,
	.open		= simple_open,
	.llseek		= default_llseek,
};
static int __oprofilefs_create_file(struct dentry *root, char const *name,
	const struct file_operations *fops, int perm, void *priv)
{
	struct dentry *dentry;
	struct inode *inode;
	inode_lock(d_inode(root));
	dentry = d_alloc_name(root, name);
	if (!dentry) {
		inode_unlock(d_inode(root));
		return -ENOMEM;
	}
	inode = oprofilefs_get_inode(root->d_sb, S_IFREG | perm);
	if (!inode) {
		dput(dentry);
		inode_unlock(d_inode(root));
		return -ENOMEM;
	}
	inode->i_fop = fops;
	inode->i_private = priv;
	d_add(dentry, inode);
	inode_unlock(d_inode(root));
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 81 | 57.04% | 1 | 11.11% | 
| Al Viro | 29 | 20.42% | 3 | 33.33% | 
| Robert Richter | 13 | 9.15% | 1 | 11.11% | 
| David Howells | 12 | 8.45% | 1 | 11.11% | 
| Andrew Morton | 4 | 2.82% | 1 | 11.11% | 
| James Morris | 2 | 1.41% | 1 | 11.11% | 
| Arjan van de Ven | 1 | 0.70% | 1 | 11.11% | 
| Total | 142 | 100.00% | 9 | 100.00% | 
int oprofilefs_create_ulong(struct dentry *root,
	char const *name, unsigned long *val)
{
	return __oprofilefs_create_file(root, name,
					&ulong_fops, 0644, val);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 30 | 85.71% | 1 | 33.33% | 
| Robert Richter | 3 | 8.57% | 1 | 33.33% | 
| Andrew Morton | 2 | 5.71% | 1 | 33.33% | 
| Total | 35 | 100.00% | 3 | 100.00% | 
int oprofilefs_create_ro_ulong(struct dentry *root,
	char const *name, unsigned long *val)
{
	return __oprofilefs_create_file(root, name,
					&ulong_ro_fops, 0444, val);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 30 | 85.71% | 1 | 33.33% | 
| Robert Richter | 3 | 8.57% | 1 | 33.33% | 
| Andrew Morton | 2 | 5.71% | 1 | 33.33% | 
| Total | 35 | 100.00% | 3 | 100.00% | 
static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
{
	atomic_t *val = file->private_data;
	return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 45 | 97.83% | 2 | 66.67% | 
| Al Viro | 1 | 2.17% | 1 | 33.33% | 
| Total | 46 | 100.00% | 3 | 100.00% | 
static const struct file_operations atomic_ro_fops = {
	.read		= atomic_read_file,
	.open		= simple_open,
	.llseek		= default_llseek,
};
int oprofilefs_create_ro_atomic(struct dentry *root,
	char const *name, atomic_t *val)
{
	return __oprofilefs_create_file(root, name,
					&atomic_ro_fops, 0444, val);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 29 | 85.29% | 1 | 33.33% | 
| Robert Richter | 3 | 8.82% | 1 | 33.33% | 
| Andrew Morton | 2 | 5.88% | 1 | 33.33% | 
| Total | 34 | 100.00% | 3 | 100.00% | 
int oprofilefs_create_file(struct dentry *root,
	char const *name, const struct file_operations *fops)
{
	return __oprofilefs_create_file(root, name, fops, 0644, NULL);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 26 | 74.29% | 1 | 25.00% | 
| Andrew Morton | 5 | 14.29% | 1 | 25.00% | 
| Robert Richter | 3 | 8.57% | 1 | 25.00% | 
| Arjan van de Ven | 1 | 2.86% | 1 | 25.00% | 
| Total | 35 | 100.00% | 4 | 100.00% | 
int oprofilefs_create_file_perm(struct dentry *root,
	char const *name, const struct file_operations *fops, int perm)
{
	return __oprofilefs_create_file(root, name, fops, perm, NULL);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Andrew Morton | 31 | 81.58% | 1 | 25.00% | 
| Robert Richter | 3 | 7.89% | 1 | 25.00% | 
| John Levon | 3 | 7.89% | 1 | 25.00% | 
| Arjan van de Ven | 1 | 2.63% | 1 | 25.00% | 
| Total | 38 | 100.00% | 4 | 100.00% | 
struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name)
{
	struct dentry *dentry;
	struct inode *inode;
	inode_lock(d_inode(parent));
	dentry = d_alloc_name(parent, name);
	if (!dentry) {
		inode_unlock(d_inode(parent));
		return NULL;
	}
	inode = oprofilefs_get_inode(parent->d_sb, S_IFDIR | 0755);
	if (!inode) {
		dput(dentry);
		inode_unlock(d_inode(parent));
		return NULL;
	}
	inode->i_op = &simple_dir_inode_operations;
	inode->i_fop = &simple_dir_operations;
	d_add(dentry, inode);
	inode_unlock(d_inode(parent));
	return dentry;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 87 | 66.92% | 1 | 14.29% | 
| Al Viro | 27 | 20.77% | 3 | 42.86% | 
| David Howells | 12 | 9.23% | 1 | 14.29% | 
| Mika Kukkonen | 2 | 1.54% | 1 | 14.29% | 
| James Morris | 2 | 1.54% | 1 | 14.29% | 
| Total | 130 | 100.00% | 7 | 100.00% | 
static int oprofilefs_fill_super(struct super_block *sb, void *data, int silent)
{
	struct inode *root_inode;
	sb->s_blocksize = PAGE_SIZE;
	sb->s_blocksize_bits = PAGE_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;
	sb->s_root = d_make_root(root_inode);
	if (!sb->s_root)
		return -ENOMEM;
	oprofile_create_files(sb->s_root);
	// FIXME: verify kill_litter_super removes our dentries
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 102 | 85.71% | 1 | 20.00% | 
| Al Viro | 9 | 7.56% | 2 | 40.00% | 
| Andi Kleen | 6 | 5.04% | 1 | 20.00% | 
| Kirill A. Shutemov | 2 | 1.68% | 1 | 20.00% | 
| Total | 119 | 100.00% | 5 | 100.00% | 
static struct dentry *oprofilefs_mount(struct file_system_type *fs_type,
	int flags, const char *dev_name, void *data)
{
	return mount_single(fs_type, flags, data, oprofilefs_fill_super);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 31 | 83.78% | 1 | 33.33% | 
| Al Viro | 5 | 13.51% | 1 | 33.33% | 
| Andries E. Brouwer | 1 | 2.70% | 1 | 33.33% | 
| Total | 37 | 100.00% | 3 | 100.00% | 
static struct file_system_type oprofilefs_type = {
	.owner		= THIS_MODULE,
	.name		= "oprofilefs",
	.mount		= oprofilefs_mount,
	.kill_sb	= kill_litter_super,
};
MODULE_ALIAS_FS("oprofilefs");
int __init oprofilefs_register(void)
{
	return register_filesystem(&oprofilefs_type);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 15 | 100.00% | 1 | 100.00% | 
| Total | 15 | 100.00% | 1 | 100.00% | 
void __exit oprofilefs_unregister(void)
{
	unregister_filesystem(&oprofilefs_type);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 14 | 100.00% | 1 | 100.00% | 
| Total | 14 | 100.00% | 1 | 100.00% | 
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| John Levon | 953 | 76.85% | 5 | 13.89% | 
| Al Viro | 95 | 7.66% | 9 | 25.00% | 
| Robert Richter | 51 | 4.11% | 3 | 8.33% | 
| Andrew Morton | 46 | 3.71% | 1 | 2.78% | 
| David Howells | 24 | 1.94% | 1 | 2.78% | 
| Arnd Bergmann | 15 | 1.21% | 1 | 2.78% | 
| Jiri Kosina | 8 | 0.65% | 1 | 2.78% | 
| Christoph Hellwig | 7 | 0.56% | 1 | 2.78% | 
| Arjan van de Ven | 6 | 0.48% | 2 | 5.56% | 
| Thomas Gleixner | 6 | 0.48% | 2 | 5.56% | 
| Andi Kleen | 6 | 0.48% | 1 | 2.78% | 
| Eric W. Biedermann | 5 | 0.40% | 1 | 2.78% | 
| James Morris | 4 | 0.32% | 1 | 2.78% | 
| Deepa Dinamani | 4 | 0.32% | 1 | 2.78% | 
| Stephen Boyd | 3 | 0.24% | 1 | 2.78% | 
| Mika Kukkonen | 2 | 0.16% | 1 | 2.78% | 
| Kirill A. Shutemov | 2 | 0.16% | 1 | 2.78% | 
| Andries E. Brouwer | 1 | 0.08% | 1 | 2.78% | 
| Alexey Dobriyan | 1 | 0.08% | 1 | 2.78% | 
| Linus Torvalds | 1 | 0.08% | 1 | 2.78% | 
| Total | 1240 | 100.00% | 36 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.