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

Zhaolei zhaolei at cn.fujitsu.com
Fri Dec 5 03:15:58 EST 2008


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>
---
 ltt/ltt-trace-control.c |  124 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 105 insertions(+), 19 deletions(-)

diff --git a/ltt/ltt-trace-control.c b/ltt/ltt-trace-control.c
index d3124ec..3144669 100644
--- a/ltt/ltt-trace-control.c
+++ b/ltt/ltt-trace-control.c
@@ -207,8 +207,8 @@ static struct file_operations ltt_trans_operations = {
 };
 
 
-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 file *file, const char __user *user_buf,
 
 	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 file *file, const char __user *user_buf,
 
 	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,7 +331,7 @@ static ssize_t overwrite_write(struct file *file, const char __user *user_buf,
 		err = ltt_trace_set_channel_overwrite(trace_name, channel_name,
 			1);
 		if (IS_ERR_VALUE(err)) {
-			printk(KERN_ERR "overwrite_write: "
+			printk(KERN_ERR "channel_overwrite_write: "
 			"ltt_trace_set_channel_overwrite failed: %d\n", err);
 			goto err_set_subbufsize;
 		}
@@ -342,7 +342,7 @@ static ssize_t overwrite_write(struct file *file, const char __user *user_buf,
 		err = ltt_trace_set_channel_overwrite(trace_name, channel_name,
 			0);
 		if (IS_ERR_VALUE(err)) {
-			printk(KERN_ERR "overwrite_write: "
+			printk(KERN_ERR "channel_overwrite_write: "
 			"ltt_trace_set_channel_overwrite failed: %d\n", err);
 			goto err_set_subbufsize;
 		}
@@ -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(const char *trace_name)
 	 *     `-- <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(const char *trace_name)
 		}
 
 		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(const char *trace_name)
 		}
 
 		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(const char *trace_name)
 			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]);
-- 
1.5.5.3






More information about the lttng-dev mailing list