From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Tom Zanussi <tom.zanussi@linux.intel.com>
Cc: rostedt@goodmis.org, linux-kernel@vger.kernel.org,
Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH v4 02/11] tracing: add basic event trigger framework
Date: Thu, 08 Aug 2013 17:30:06 +0900 [thread overview]
Message-ID: <5203570E.3020201@hitachi.com> (raw)
In-Reply-To: <9660276cae921dfe8450cc259c99cd8b41ebb862.1375111640.git.tom.zanussi@linux.intel.com>
(2013/07/30 1:40), Tom Zanussi wrote:
> +struct event_command {
> + struct list_head list;
> + char *name;
> + enum trigger_mode trigger_mode;
> + bool post_trigger;
> + int (*func)(struct event_command *cmd_ops,
> + void *cmd_data, char *glob, char *cmd,
> + char *params, int enable);
> + int (*reg)(char *glob,
> + struct event_trigger_ops *trigger_ops,
> + void *trigger_data, void *cmd_data);
> + void (*unreg)(char *glob,
> + struct event_trigger_ops *trigger_ops,
> + void *trigger_data, void *cmd_data);
> + int (*set_filter)(char *filter_str,
> + void *trigger_data,
> + void *cmd_data);
I think you should pass trace_event_file *file (see below) instead of ambiguous
void *cmd_data, because all handler implementations expect that.
[...]
> +#include <linux/module.h>
> +#include <linux/ctype.h>
> +#include <linux/mutex.h>
> +#include <linux/slab.h>
> +
> +#include "trace.h"
> +
> +static LIST_HEAD(trigger_commands);
> +static DEFINE_MUTEX(trigger_cmd_mutex);
> +
> +struct event_trigger_data {
> + struct ftrace_event_file *file;
> + unsigned long count;
> + int ref;
> + bool enable;
> + struct event_trigger_ops *ops;
> + enum trigger_mode mode;
> + struct event_filter *filter;
> + char *filter_str;
> + struct list_head list;
> +};
> +
> +struct trigger_iterator {
> + struct ftrace_event_file *file;
> +};
Why would you define this trigger_iterator even if it has
only one member? This means all iterators can be replaced
by the file. I'd like to keep it simple.
> +
> +void event_triggers_call(struct ftrace_event_file *file)
> +{
> + struct event_trigger_data *data;
> +
> + if (list_empty(&file->triggers))
> + return;
> +
> + preempt_disable_notrace();
> + list_for_each_entry_rcu(data, &file->triggers, list)
> + data->ops->func((void **)&data);
> + preempt_enable_notrace();
> +}
> +EXPORT_SYMBOL_GPL(event_triggers_call);
> +
> +static void *trigger_next(struct seq_file *m, void *t, loff_t *pos)
> +{
> + struct trigger_iterator *iter = m->private;
> +
> + return seq_list_next(t, &iter->file->triggers, pos);
> +}
> +
> +static void *trigger_start(struct seq_file *m, loff_t *pos)
> +{
> + struct trigger_iterator *iter = m->private;
> +
> + mutex_lock(&event_mutex);
> +
> + return seq_list_start(&iter->file->triggers, *pos);
> +}
By Oleg's bugfixes, we are now using event_file_data(filp)
please refer the f_start/trace_format_open implementation
which is the closest usage of the trigger file.
> +static int event_trigger_regex_open(struct inode *inode, struct file *file)
> +{
> + struct trigger_iterator *iter;
> + int ret = 0;
> +
> + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
> + if (!iter)
> + return -ENOMEM;
> +
> + mutex_lock(&event_mutex);
> +
> + iter->file = inode->i_private;
> +
> + if (file->f_mode & FMODE_READ) {
> + ret = seq_open(file, &event_triggers_seq_ops);
> + if (!ret) {
> + struct seq_file *m = file->private_data;
> + m->private = iter;
> + } else {
> + /* Failed */
> + kfree(iter);
> + }
> + } else
> + file->private_data = iter;
> +
> + mutex_unlock(&event_mutex);
> +
> + return ret;
> +}
As you can see in trace_format_open(), now file->private_data and
m->private will point struct file *, don't need to allocate something.
> +static ssize_t event_trigger_regex_write(struct file *file,
> + const char __user *ubuf,
> + size_t cnt, loff_t *ppos, int enable)
> +{
> + struct trigger_iterator *iter = file->private_data;
> + ssize_t ret;
> + char *buf;
> +
> + if (!cnt)
> + return 0;
> +
> + if (cnt >= PAGE_SIZE)
> + return -EINVAL;
> +
> + if (file->f_mode & FMODE_READ) {
> + struct seq_file *m = file->private_data;
> + iter = m->private;
> + } else
> + iter = file->private_data;
> +
> + buf = (char *)__get_free_page(GFP_TEMPORARY);
> + if (!buf)
> + return -ENOMEM;
> +
> + if (copy_from_user(buf, ubuf, cnt)) {
> + free_page((unsigned long) buf);
> + return -EFAULT;
> + }
> + buf[cnt] = '\0';
> + strim(buf);
> +
> + ret = trigger_process_regex(iter, buf, enable);
You also need to get event_mutex while processing event_file to
prevent unexpected releasing.
> +
> + free_page((unsigned long) buf);
> + if (ret < 0)
> + goto out;
> +
> + *ppos += cnt;
> + ret = cnt;
> + out:
> + return ret;
> +}
Thank you,
--
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
next prev parent reply other threads:[~2013-08-08 8:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-29 16:40 [PATCH v4 00/11] tracing: trace event triggers Tom Zanussi
2013-07-29 16:40 ` [PATCH v4 01/11] tracing: Add support for SOFT_DISABLE to syscall events Tom Zanussi
2013-08-05 11:42 ` Masami Hiramatsu
2013-07-29 16:40 ` [PATCH v4 02/11] tracing: add basic event trigger framework Tom Zanussi
2013-08-08 8:30 ` Masami Hiramatsu [this message]
2013-08-22 19:54 ` Tom Zanussi
2013-07-29 16:40 ` [PATCH v4 03/11] tracing: add 'traceon' and 'traceoff' event trigger commands Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 04/11] tracing: add 'snapshot' event trigger command Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 05/11] tracing: add 'stacktrace' " Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 06/11] tracing: add 'enable_event' and 'disable_event' event trigger commands Tom Zanussi
2013-08-08 5:54 ` Masami Hiramatsu
2013-07-29 16:41 ` [PATCH v4 07/11] tracing: add and use generic set_trigger_filter() implementation Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 08/11] tracing: update event filters for multibuffer Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 09/11] tracing: add documentation for trace event triggers Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 10/11] tracing: make register/unregister_ftrace_command __init Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 11/11] tracing: change event_trigger_open to verify i_private != NULL Tom Zanussi
2013-08-08 2:02 ` [PATCH v4 00/11] tracing: trace event triggers Masami Hiramatsu
2013-08-08 2:15 ` Steven Rostedt
2013-08-22 19:48 ` Tom Zanussi
2013-08-22 23:26 ` Tom Zanussi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5203570E.3020201@hitachi.com \
--to=masami.hiramatsu.pt@hitachi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=rostedt@goodmis.org \
--cc=tom.zanussi@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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