mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] OProfile: allow normal user to trigger sample dumps
@ 2004-06-21 16:32 John Levon
  2004-06-22 11:28 ` Philippe Elie
  0 siblings, 1 reply; 2+ messages in thread
From: John Levon @ 2004-06-21 16:32 UTC (permalink / raw)
  To: linux-kernel, torvalds, akpm


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. Against 2.6.7

Please apply

thanks
john


--- linux-2.6.0-0.test11.1.100/drivers/oprofile/oprofile_files.c.userdump	2003-12-09 10:46:54.947629369 -0500
+++ linux-2.6.0-0.test11.1.100/drivers/oprofile/oprofile_files.c	2003-12-09 11:27:44.903151844 -0500
@@ -90,7 +90,7 @@
 void oprofile_create_files(struct super_block * sb, struct dentry * root)
 {
 	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_ulong(sb, root, "buffer_size", &fs_buffer_size);
 	oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
--- linux-2.6.0-0.test11.1.100/drivers/oprofile/oprofilefs.c.userdump	2003-12-09 10:58:57.858593945 -0500
+++ linux-2.6.0-0.test11.1.100/drivers/oprofile/oprofilefs.c	2003-12-09 11:28:24.125874244 -0500
@@ -165,7 +165,8 @@
 
 
 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 inode * inode;
@@ -176,7 +177,7 @@
 	dentry = d_alloc(root, &qname);
 	if (!dentry)
 		return 0;
-	inode = oprofilefs_get_inode(sb, S_IFREG | 0644);
+	inode = oprofilefs_get_inode(sb, S_IFREG | perm);
 	if (!inode) {
 		dput(dentry);
 		return 0;
@@ -190,7 +191,8 @@
 int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
 	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)
 		return -EFAULT;
 
@@ -202,7 +204,8 @@
 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
 	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)
 		return -EFAULT;
 
@@ -227,7 +230,8 @@
 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
 	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)
 		return -EFAULT;
 
@@ -239,7 +243,16 @@
 int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
 	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 0;
 }
--- linux-2.6.0-0.test11.1.100/include/linux/oprofile.h.userdump	2003-12-09 11:12:44.250469922 -0500
+++ linux-2.6.0-0.test11.1.100/include/linux/oprofile.h	2003-12-09 11:23:00.006494400 -0500
@@ -65,6 +65,9 @@
  */
 int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
 	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. */
 int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] OProfile: allow normal user to trigger sample dumps
  2004-06-21 16:32 [PATCH] OProfile: allow normal user to trigger sample dumps John Levon
@ 2004-06-22 11:28 ` Philippe Elie
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Elie @ 2004-06-22 11:28 UTC (permalink / raw)
  To: John Levon; +Cc: linux-kernel, torvalds, akpm

On Mon, 21 Jun 2004 at 17:32 +0000, John Levon wrote:

> 
> 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. Against 2.6.7
> 

The patch didn't apply cleanly (minor problem but I redo the diff), it works fine on my box and it's usefull imho. Please apply

regards,
Phil



--- linux-2.6.0-0.test11.1.100/drivers/oprofile/oprofile_files.c.userdump	2003-12-09 10:46:54.947629369 -0500
+++ linux-2.6.0-0.test11.1.100/drivers/oprofile/oprofile_files.c	2003-12-09 11:27:44.903151844 -0500
@@ -90,7 +90,7 @@
 void oprofile_create_files(struct super_block * sb, struct dentry * root)
 {
 	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_ulong(sb, root, "buffer_size", &fs_buffer_size);
 	oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);

--- linux-2.6.0-0.test11.1.100/drivers/oprofile/oprofilefs.c.userdump	2003-12-09 10:58:57.858593945 -0500
+++ linux-2.6.0-0.test11.1.100/drivers/oprofile/oprofilefs.c	2003-12-09 11:28:24.125874244 -0500
@@ -165,7 +165,8 @@
 
 
 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 inode * inode;
@@ -176,7 +177,7 @@
 	dentry = d_alloc(root, &qname);
 	if (!dentry)
 		return 0;
-	inode = oprofilefs_get_inode(sb, S_IFREG | 0644);
+	inode = oprofilefs_get_inode(sb, S_IFREG | perm);
 	if (!inode) {
 		dput(dentry);
 		return 0;
@@ -190,7 +191,8 @@
 int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
 	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)
 		return -EFAULT;
 
@@ -202,7 +204,8 @@
 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
 	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)
 		return -EFAULT;
 
@@ -227,7 +230,8 @@
 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
 	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)
 		return -EFAULT;
 
@@ -239,7 +243,16 @@
 int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
 	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 0;
 }

--- linux-2.6.0-0.test11.1.100/include/linux/oprofile.h.userdump	2003-12-09 11:12:44.250469922 -0500
+++ linux-2.6.0-0.test11.1.100/include/linux/oprofile.h	2003-12-09 11:23:00.006494400 -0500
@@ -65,6 +65,9 @@
  */
 int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
 	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. */
 int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-06-22  9:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-21 16:32 [PATCH] OProfile: allow normal user to trigger sample dumps John Levon
2004-06-22 11:28 ` Philippe Elie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome