Commit 77a5fdb0 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] OProfile: allow normal user to trigger sample dumps

From: John Levon <levon@movementarian.org>

In 2.4, OProfile allowed normal users to trigger sample dumps (useful under
low sample load).  The patch below, by Will Cohen, allows this for 2.6 too.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 537bc91c
...@@ -90,7 +90,7 @@ static struct file_operations dump_fops = { ...@@ -90,7 +90,7 @@ static struct file_operations dump_fops = {
void oprofile_create_files(struct super_block * sb, struct dentry * root) void oprofile_create_files(struct super_block * sb, struct dentry * root)
{ {
oprofilefs_create_file(sb, root, "enable", &enable_fops); oprofilefs_create_file(sb, root, "enable", &enable_fops);
oprofilefs_create_file(sb, root, "dump", &dump_fops); oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops); oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size); oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed); oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
......
...@@ -165,7 +165,8 @@ static struct file_operations ulong_ro_fops = { ...@@ -165,7 +165,8 @@ static struct file_operations ulong_ro_fops = {
static struct dentry * __oprofilefs_create_file(struct super_block * sb, static struct dentry * __oprofilefs_create_file(struct super_block * sb,
struct dentry * root, char const * name, struct file_operations * fops) struct dentry * root, char const * name, struct file_operations * fops,
int perm)
{ {
struct dentry * dentry; struct dentry * dentry;
struct inode * inode; struct inode * inode;
...@@ -176,7 +177,7 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb, ...@@ -176,7 +177,7 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb,
dentry = d_alloc(root, &qname); dentry = d_alloc(root, &qname);
if (!dentry) if (!dentry)
return 0; return 0;
inode = oprofilefs_get_inode(sb, S_IFREG | 0644); inode = oprofilefs_get_inode(sb, S_IFREG | perm);
if (!inode) { if (!inode) {
dput(dentry); dput(dentry);
return 0; return 0;
...@@ -190,7 +191,8 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb, ...@@ -190,7 +191,8 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb,
int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root, int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
char const * name, unsigned long * val) char const * name, unsigned long * val)
{ {
struct dentry * d = __oprofilefs_create_file(sb, root, name, &ulong_fops); struct dentry * d = __oprofilefs_create_file(sb, root, name,
&ulong_fops, 0644);
if (!d) if (!d)
return -EFAULT; return -EFAULT;
...@@ -202,7 +204,8 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root, ...@@ -202,7 +204,8 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root, int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
char const * name, unsigned long * val) char const * name, unsigned long * val)
{ {
struct dentry * d = __oprofilefs_create_file(sb, root, name, &ulong_ro_fops); struct dentry * d = __oprofilefs_create_file(sb, root, name,
&ulong_ro_fops, 0444);
if (!d) if (!d)
return -EFAULT; return -EFAULT;
...@@ -227,7 +230,8 @@ static struct file_operations atomic_ro_fops = { ...@@ -227,7 +230,8 @@ static struct file_operations atomic_ro_fops = {
int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root, int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
char const * name, atomic_t * val) char const * name, atomic_t * val)
{ {
struct dentry * d = __oprofilefs_create_file(sb, root, name, &atomic_ro_fops); struct dentry * d = __oprofilefs_create_file(sb, root, name,
&atomic_ro_fops, 0444);
if (!d) if (!d)
return -EFAULT; return -EFAULT;
...@@ -239,7 +243,16 @@ int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root, ...@@ -239,7 +243,16 @@ int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
int oprofilefs_create_file(struct super_block * sb, struct dentry * root, int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
char const * name, struct file_operations * fops) char const * name, struct file_operations * fops)
{ {
if (!__oprofilefs_create_file(sb, root, name, fops)) if (!__oprofilefs_create_file(sb, root, name, fops, 0644))
return -EFAULT;
return 0;
}
int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
char const * name, struct file_operations * fops, int perm)
{
if (!__oprofilefs_create_file(sb, root, name, fops, perm))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
......
...@@ -65,6 +65,9 @@ extern void oprofile_add_sample(unsigned long eip, unsigned int is_kernel, ...@@ -65,6 +65,9 @@ extern void oprofile_add_sample(unsigned long eip, unsigned int is_kernel,
*/ */
int oprofilefs_create_file(struct super_block * sb, struct dentry * root, int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
char const * name, struct file_operations * fops); char const * name, struct file_operations * fops);
int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
char const * name, struct file_operations * fops, int perm);
/** Create a file for read/write access to an unsigned long. */ /** Create a file for read/write access to an unsigned long. */
int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root, int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment