[ltt-dev] [PATCH 2/2] Make ltt-trace-control support each channel's enable/disable

Mathieu Desnoyers compudj at krystal.dyndns.org
Fri Dec 5 05:04:42 EST 2008


* Zhaolei (zhaolei at cn.fujitsu.com) wrote:
> We can set each channel's enable/disable state by
> echo 1/0 > [debugfs]/ltt/control/[trace]/channel/[channel]/enable
> 
> Signed-off-by: Zhao Lei <zhaolei at cn.fujitsu.com>

I had to edit two hunks of this patch to make it apply. I'm telling you
so you know the patch in the next lttng might conflict with some of your
work.

Mathieu


LTTng control : support channel enable

We can set each channel's enable/disable state by
echo 1/0 > [debugfs]/ltt/control/[trace]/channel/[channel]/enable

[Mathieu : edited two printk rejects]

From: Zhao Lei <zhaolei at cn.fujitsu.com>
Signed-off-by: Zhao Lei <zhaolei at cn.fujitsu.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at polymtl.ca>
---
 ltt/ltt-trace-control.c |  128 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 107 insertions(+), 21 deletions(-)

Index: linux-2.6-lttng/ltt/ltt-trace-control.c
===================================================================
--- linux-2.6-lttng.orig/ltt/ltt-trace-control.c	2008-12-05 04:46:31.000000000 -0500
+++ linux-2.6-lttng/ltt/ltt-trace-control.c	2008-12-05 04:48:17.000000000 -0500
@@ -207,8 +207,8 @@ static struct file_operations ltt_trans_
 };
 
 
-static ssize_t subbuf_num_write(struct file *file, const char __user *user_buf,
-		size_t count, loff_t *ppos)
+static ssize_t channel_subbuf_num_write(struct file *file,
+		const char __user *user_buf, size_t count, loff_t *ppos)
 {
 	int err = 0;
 	char buf[NAME_MAX];
@@ -233,7 +233,7 @@ static ssize_t subbuf_num_write(struct f
 
 	err = ltt_trace_set_channel_subbufcount(trace_name, channel_name, num);
 	if (IS_ERR_VALUE(err)) {
-		printk(KERN_ERR "subbuf_num_write: "
+		printk(KERN_ERR "channel_subbuf_num_write: "
 			"ltt_trace_set_channel_subbufcount failed: %d\n", err);
 		goto err_set_subbufcount;
 	}
@@ -246,13 +246,13 @@ err_copy_from_user:
 	return err;
 }
 
-static struct file_operations ltt_subbuf_num_operations = {
-	.write = subbuf_num_write,
+static struct file_operations ltt_channel_subbuf_num_operations = {
+	.write = channel_subbuf_num_write,
 };
 
 
-static ssize_t subbuf_size_write(struct file *file, const char __user *user_buf,
-		size_t count, loff_t *ppos)
+static ssize_t channel_subbuf_size_write(struct file *file,
+	const char __user *user_buf, size_t count, loff_t *ppos)
 {
 	int err = 0;
 	char buf[NAME_MAX];
@@ -277,7 +277,7 @@ static ssize_t subbuf_size_write(struct 
 
 	err = ltt_trace_set_channel_subbufsize(trace_name, channel_name, num);
 	if (IS_ERR_VALUE(err)) {
-		printk(KERN_ERR "subbuf_size_write: "
+		printk(KERN_ERR "channel_subbuf_size_write: "
 		"ltt_trace_set_channel_subbufsize failed: %d\n", err);
 		goto err_set_subbufsize;
 	}
@@ -290,13 +290,13 @@ err_copy_from_user:
 	return err;
 }
 
-static struct file_operations ltt_subbuf_size_operations = {
-	.write = subbuf_size_write,
+static struct file_operations ltt_channel_subbuf_size_operations = {
+	.write = channel_subbuf_size_write,
 };
 
 
-static ssize_t overwrite_write(struct file *file, const char __user *user_buf,
-		size_t count, loff_t *ppos)
+static ssize_t channel_overwrite_write(struct file *file,
+	const char __user *user_buf, size_t count, loff_t *ppos)
 {
 	int err = 0;
 	char buf[NAME_MAX];
@@ -331,8 +331,8 @@ static ssize_t overwrite_write(struct fi
 		err = ltt_trace_set_channel_overwrite(trace_name, channel_name,
 			1);
 		if (IS_ERR_VALUE(err)) {
-			printk(KERN_ERR "subbuf_size_write: "
-			"ltt_trace_set_channel_subbufsize failed: %d\n", err);
+			printk(KERN_ERR "channel_overwrite_write: "
+			"ltt_trace_set_channel_overwrite failed: %d\n", err);
 			goto err_set_subbufsize;
 		}
 		break;
@@ -342,8 +342,8 @@ static ssize_t overwrite_write(struct fi
 		err = ltt_trace_set_channel_overwrite(trace_name, channel_name,
 			0);
 		if (IS_ERR_VALUE(err)) {
-			printk(KERN_ERR "subbuf_size_write: "
-			"ltt_trace_set_channel_subbufsize failed: %d\n", err);
+			printk(KERN_ERR "channel_overwrite_write: "
+			"ltt_trace_set_channel_overwrite failed: %d\n", err);
 			goto err_set_subbufsize;
 		}
 		break;
@@ -361,8 +361,79 @@ err_copy_from_user:
 	return err;
 }
 
-static struct file_operations ltt_overwrite_operations = {
-	.write = overwrite_write,
+static struct file_operations ltt_channel_overwrite_operations = {
+	.write = channel_overwrite_write,
+};
+
+
+static ssize_t channel_enable_write(struct file *file,
+	const char __user *user_buf, size_t count, loff_t *ppos)
+{
+	int err = 0;
+	char buf[NAME_MAX];
+	int buf_size;
+	char cmd[NAME_MAX];
+	const char *channel_name;
+	const char *trace_name;
+
+	buf_size = min(count, sizeof(buf) - 1);
+	err = copy_from_user(buf, user_buf, buf_size);
+	if (err)
+		goto err_copy_from_user;
+	buf[buf_size] = 0;
+
+	if (sscanf(buf, "%s", cmd) != 1) {
+		err = -EPERM;
+		goto err_get_cmd;
+	}
+
+	if (cmd[1]) {
+		err = -EPERM;
+		goto err_bad_cmd;
+	}
+
+	channel_name = file->f_dentry->d_parent->d_name.name;
+	trace_name = file->f_dentry->d_parent->d_parent->d_parent->d_name.name;
+
+	switch (cmd[0]) {
+	case 'Y':
+	case 'y':
+	case '1':
+		err = ltt_trace_set_channel_enable(trace_name, channel_name,
+			1);
+		if (IS_ERR_VALUE(err)) {
+			printk(KERN_ERR "channel_enable_write: "
+			"ltt_trace_set_channel_enable failed: %d\n", err);
+			goto err_set_subbufsize;
+		}
+		break;
+	case 'N':
+	case 'n':
+	case '0':
+		err = ltt_trace_set_channel_enable(trace_name, channel_name,
+			0);
+		if (IS_ERR_VALUE(err)) {
+			printk(KERN_ERR "channel_enable_write: "
+			"ltt_trace_set_channel_enable failed: %d\n", err);
+			goto err_set_subbufsize;
+		}
+		break;
+	default:
+		err = -EPERM;
+		goto err_bad_cmd;
+	}
+
+	return count;
+
+err_set_subbufsize:
+err_bad_cmd:
+err_get_cmd:
+err_copy_from_user:
+	return err;
+}
+
+static struct file_operations ltt_channel_enable_operations = {
+	.write = channel_enable_write,
 };
 
 
@@ -443,26 +514,32 @@ static int _create_trace_control_dir(con
 	 *     `-- <trace_name>
 	 *         `-- <channel>
 	 *             |-- interrupts
+	 *             |   |-- enable
 	 *             |   |-- overwrite
 	 *             |   |-- subbuf_num
 	 *             |   `-- subbuf_size
 	 *             |-- metadata
+	 *             |   |-- enable
 	 *             |   |-- overwrite
 	 *             |   |-- subbuf_num
 	 *             |   `-- subbuf_size
 	 *             |-- modules
+	 *             |   |-- enable
 	 *             |   |-- overwrite
 	 *             |   |-- subbuf_num
 	 *             |   `-- subbuf_size
 	 *             |-- network
+	 *             |   |-- enable
 	 *             |   |-- overwrite
 	 *             |   |-- subbuf_num
 	 *             |   `-- subbuf_size
 	 *             |-- processes
+	 *             |   |-- enable
 	 *             |   |-- overwrite
 	 *             |   |-- subbuf_num
 	 *             |   `-- subbuf_size
 	 *             `-- cpu
+	 *                 |-- enable
 	 *                 |-- overwrite
 	 *                 |-- subbuf_num
 	 *                 `-- subbuf_size
@@ -481,7 +558,7 @@ static int _create_trace_control_dir(con
 		}
 
 		tmp_den = debugfs_create_file("subbuf_num", S_IWUSR,
-			channel_den, NULL, &ltt_subbuf_num_operations);
+			channel_den, NULL, &ltt_channel_subbuf_num_operations);
 		if (IS_ERR(tmp_den) || !tmp_den) {
 			printk(KERN_ERR "_create_trace_control_dir: "
 				"create subbuf_num in %s failed\n",
@@ -491,7 +568,7 @@ static int _create_trace_control_dir(con
 		}
 
 		tmp_den = debugfs_create_file("subbuf_size", S_IWUSR,
-			channel_den, NULL, &ltt_subbuf_size_operations);
+			channel_den, NULL, &ltt_channel_subbuf_size_operations);
 		if (IS_ERR(tmp_den) || !tmp_den) {
 			printk(KERN_ERR "_create_trace_control_dir: "
 				"create subbuf_size in %s failed\n",
@@ -500,8 +577,17 @@ static int _create_trace_control_dir(con
 			goto err_create_subdir;
 		}
 
+		tmp_den = debugfs_create_file("enable", S_IWUSR, channel_den,
+			NULL, &ltt_channel_enable_operations);
+		if (IS_ERR(tmp_den) || !tmp_den) {
+			printk(KERN_ERR "_create_trace_control_dir: "
+				"create enable in %s failed\n", channels[i]);
+			err = -ENOMEM;
+			goto err_create_subdir;
+		}
+
 		tmp_den = debugfs_create_file("overwrite", S_IWUSR, channel_den,
-			NULL, &ltt_overwrite_operations);
+			NULL, &ltt_channel_overwrite_operations);
 		if (IS_ERR(tmp_den) || !tmp_den) {
 			printk(KERN_ERR "_create_trace_control_dir: "
 				"create overwrite in %s failed\n", channels[i]);

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68




More information about the lttng-dev mailing list