1 // SPDX-License-Identifier: GPL-2.0
3 * trace_events_trigger - trace event triggers
5 * Copyright (C) 2013 Tom Zanussi <tom.zanussi@linux.intel.com>
8 #include <linux/security.h>
9 #include <linux/module.h>
10 #include <linux/ctype.h>
11 #include <linux/mutex.h>
12 #include <linux/slab.h>
13 #include <linux/rculist.h>
17 static LIST_HEAD(trigger_commands);
18 static DEFINE_MUTEX(trigger_cmd_mutex);
20 void trigger_data_free(struct event_trigger_data *data)
22 if (data->cmd_ops->set_filter)
23 data->cmd_ops->set_filter(NULL, data, NULL);
25 /* make sure current triggers exit before free */
26 tracepoint_synchronize_unregister();
32 * event_triggers_call - Call triggers associated with a trace event
33 * @file: The trace_event_file associated with the event
34 * @rec: The trace entry for the event, NULL for unconditional invocation
36 * For each trigger associated with an event, invoke the trigger
37 * function registered with the associated trigger command. If rec is
38 * non-NULL, it means that the trigger requires further processing and
39 * shouldn't be unconditionally invoked. If rec is non-NULL and the
40 * trigger has a filter associated with it, rec will checked against
41 * the filter and if the record matches the trigger will be invoked.
42 * If the trigger is a 'post_trigger', meaning it shouldn't be invoked
43 * in any case until the current event is written, the trigger
44 * function isn't invoked but the bit associated with the deferred
45 * trigger is set in the return value.
47 * Returns an enum event_trigger_type value containing a set bit for
48 * any trigger that should be deferred, ETT_NONE if nothing to defer.
50 * Called from tracepoint handlers (with rcu_read_lock_sched() held).
52 * Return: an enum event_trigger_type value containing a set bit for
53 * any trigger that should be deferred, ETT_NONE if nothing to defer.
55 enum event_trigger_type
56 event_triggers_call(struct trace_event_file *file,
57 struct trace_buffer *buffer, void *rec,
58 struct ring_buffer_event *event)
60 struct event_trigger_data *data;
61 enum event_trigger_type tt = ETT_NONE;
62 struct event_filter *filter;
64 if (list_empty(&file->triggers))
67 list_for_each_entry_rcu(data, &file->triggers, list) {
71 data->ops->trigger(data, buffer, rec, event);
74 filter = rcu_dereference_sched(data->filter);
75 if (filter && !filter_match_preds(filter, rec))
77 if (event_command_post_trigger(data->cmd_ops)) {
78 tt |= data->cmd_ops->trigger_type;
81 data->ops->trigger(data, buffer, rec, event);
85 EXPORT_SYMBOL_GPL(event_triggers_call);
87 bool __trace_trigger_soft_disabled(struct trace_event_file *file)
89 unsigned long eflags = file->flags;
91 if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
92 event_triggers_call(file, NULL, NULL, NULL);
93 if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
95 if (eflags & EVENT_FILE_FL_PID_FILTER)
96 return trace_event_ignore_this_pid(file);
99 EXPORT_SYMBOL_GPL(__trace_trigger_soft_disabled);
102 * event_triggers_post_call - Call 'post_triggers' for a trace event
103 * @file: The trace_event_file associated with the event
104 * @tt: enum event_trigger_type containing a set bit for each trigger to invoke
106 * For each trigger associated with an event, invoke the trigger
107 * function registered with the associated trigger command, if the
108 * corresponding bit is set in the tt enum passed into this function.
109 * See @event_triggers_call for details on how those bits are set.
111 * Called from tracepoint handlers (with rcu_read_lock_sched() held).
114 event_triggers_post_call(struct trace_event_file *file,
115 enum event_trigger_type tt)
117 struct event_trigger_data *data;
119 list_for_each_entry_rcu(data, &file->triggers, list) {
122 if (data->cmd_ops->trigger_type & tt)
123 data->ops->trigger(data, NULL, NULL, NULL);
126 EXPORT_SYMBOL_GPL(event_triggers_post_call);
128 #define SHOW_AVAILABLE_TRIGGERS (void *)(1UL)
130 static void *trigger_next(struct seq_file *m, void *t, loff_t *pos)
132 struct trace_event_file *event_file = event_file_data(m->private);
134 if (t == SHOW_AVAILABLE_TRIGGERS) {
138 return seq_list_next(t, &event_file->triggers, pos);
141 static bool check_user_trigger(struct trace_event_file *file)
143 struct event_trigger_data *data;
145 list_for_each_entry_rcu(data, &file->triggers, list) {
146 if (data->flags & EVENT_TRIGGER_FL_PROBE)
153 static void *trigger_start(struct seq_file *m, loff_t *pos)
155 struct trace_event_file *event_file;
157 /* ->stop() is called even if ->start() fails */
158 mutex_lock(&event_mutex);
159 event_file = event_file_data(m->private);
160 if (unlikely(!event_file))
161 return ERR_PTR(-ENODEV);
163 if (list_empty(&event_file->triggers) || !check_user_trigger(event_file))
164 return *pos == 0 ? SHOW_AVAILABLE_TRIGGERS : NULL;
166 return seq_list_start(&event_file->triggers, *pos);
169 static void trigger_stop(struct seq_file *m, void *t)
171 mutex_unlock(&event_mutex);
174 static int trigger_show(struct seq_file *m, void *v)
176 struct event_trigger_data *data;
177 struct event_command *p;
179 if (v == SHOW_AVAILABLE_TRIGGERS) {
180 seq_puts(m, "# Available triggers:\n");
182 mutex_lock(&trigger_cmd_mutex);
183 list_for_each_entry_reverse(p, &trigger_commands, list)
184 seq_printf(m, " %s", p->name);
186 mutex_unlock(&trigger_cmd_mutex);
190 data = list_entry(v, struct event_trigger_data, list);
191 data->ops->print(m, data->ops, data);
196 static const struct seq_operations event_triggers_seq_ops = {
197 .start = trigger_start,
198 .next = trigger_next,
199 .stop = trigger_stop,
200 .show = trigger_show,
203 static int event_trigger_regex_open(struct inode *inode, struct file *file)
207 ret = security_locked_down(LOCKDOWN_TRACEFS);
211 mutex_lock(&event_mutex);
213 if (unlikely(!event_file_data(file))) {
214 mutex_unlock(&event_mutex);
218 if ((file->f_mode & FMODE_WRITE) &&
219 (file->f_flags & O_TRUNC)) {
220 struct trace_event_file *event_file;
221 struct event_command *p;
223 event_file = event_file_data(file);
225 list_for_each_entry(p, &trigger_commands, list) {
227 p->unreg_all(event_file);
231 if (file->f_mode & FMODE_READ) {
232 ret = seq_open(file, &event_triggers_seq_ops);
234 struct seq_file *m = file->private_data;
239 mutex_unlock(&event_mutex);
244 int trigger_process_regex(struct trace_event_file *file, char *buff)
246 char *command, *next;
247 struct event_command *p;
250 next = buff = skip_spaces(buff);
251 command = strsep(&next, ": \t");
253 next = skip_spaces(next);
257 command = (command[0] != '!') ? command : command + 1;
259 mutex_lock(&trigger_cmd_mutex);
260 list_for_each_entry(p, &trigger_commands, list) {
261 if (strcmp(p->name, command) == 0) {
262 ret = p->parse(p, file, buff, command, next);
267 mutex_unlock(&trigger_cmd_mutex);
272 static ssize_t event_trigger_regex_write(struct file *file,
273 const char __user *ubuf,
274 size_t cnt, loff_t *ppos)
276 struct trace_event_file *event_file;
283 if (cnt >= PAGE_SIZE)
286 buf = memdup_user_nul(ubuf, cnt);
292 mutex_lock(&event_mutex);
293 event_file = event_file_data(file);
294 if (unlikely(!event_file)) {
295 mutex_unlock(&event_mutex);
299 ret = trigger_process_regex(event_file, buf);
300 mutex_unlock(&event_mutex);
312 static int event_trigger_regex_release(struct inode *inode, struct file *file)
314 mutex_lock(&event_mutex);
316 if (file->f_mode & FMODE_READ)
317 seq_release(inode, file);
319 mutex_unlock(&event_mutex);
325 event_trigger_write(struct file *filp, const char __user *ubuf,
326 size_t cnt, loff_t *ppos)
328 return event_trigger_regex_write(filp, ubuf, cnt, ppos);
332 event_trigger_open(struct inode *inode, struct file *filp)
334 /* Checks for tracefs lockdown */
335 return event_trigger_regex_open(inode, filp);
339 event_trigger_release(struct inode *inode, struct file *file)
341 return event_trigger_regex_release(inode, file);
344 const struct file_operations event_trigger_fops = {
345 .open = event_trigger_open,
347 .write = event_trigger_write,
348 .llseek = tracing_lseek,
349 .release = event_trigger_release,
353 * Currently we only register event commands from __init, so mark this
356 __init int register_event_command(struct event_command *cmd)
358 struct event_command *p;
361 mutex_lock(&trigger_cmd_mutex);
362 list_for_each_entry(p, &trigger_commands, list) {
363 if (strcmp(cmd->name, p->name) == 0) {
368 list_add(&cmd->list, &trigger_commands);
370 mutex_unlock(&trigger_cmd_mutex);
376 * Currently we only unregister event commands from __init, so mark
379 __init int unregister_event_command(struct event_command *cmd)
381 struct event_command *p, *n;
384 mutex_lock(&trigger_cmd_mutex);
385 list_for_each_entry_safe(p, n, &trigger_commands, list) {
386 if (strcmp(cmd->name, p->name) == 0) {
388 list_del_init(&p->list);
393 mutex_unlock(&trigger_cmd_mutex);
399 * event_trigger_print - Generic event_trigger_ops @print implementation
400 * @name: The name of the event trigger
401 * @m: The seq_file being printed to
402 * @data: Trigger-specific data
403 * @filter_str: filter_str to print, if present
405 * Common implementation for event triggers to print themselves.
407 * Usually wrapped by a function that simply sets the @name of the
408 * trigger command and then invokes this.
410 * Return: 0 on success, errno otherwise
413 event_trigger_print(const char *name, struct seq_file *m,
414 void *data, char *filter_str)
416 long count = (long)data;
421 seq_puts(m, ":unlimited");
423 seq_printf(m, ":count=%ld", count);
426 seq_printf(m, " if %s\n", filter_str);
434 * event_trigger_init - Generic event_trigger_ops @init implementation
435 * @ops: The trigger ops associated with the trigger
436 * @data: Trigger-specific data
438 * Common implementation of event trigger initialization.
440 * Usually used directly as the @init method in event trigger
443 * Return: 0 on success, errno otherwise
445 int event_trigger_init(struct event_trigger_ops *ops,
446 struct event_trigger_data *data)
453 * event_trigger_free - Generic event_trigger_ops @free implementation
454 * @ops: The trigger ops associated with the trigger
455 * @data: Trigger-specific data
457 * Common implementation of event trigger de-initialization.
459 * Usually used directly as the @free method in event trigger
463 event_trigger_free(struct event_trigger_ops *ops,
464 struct event_trigger_data *data)
466 if (WARN_ON_ONCE(data->ref <= 0))
471 trigger_data_free(data);
474 int trace_event_trigger_enable_disable(struct trace_event_file *file,
479 if (trigger_enable) {
480 if (atomic_inc_return(&file->tm_ref) > 1)
482 set_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
483 ret = trace_event_enable_disable(file, 1, 1);
485 if (atomic_dec_return(&file->tm_ref) > 0)
487 clear_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
488 ret = trace_event_enable_disable(file, 0, 1);
495 * clear_event_triggers - Clear all triggers associated with a trace array
496 * @tr: The trace array to clear
498 * For each trigger, the triggering event has its tm_ref decremented
499 * via trace_event_trigger_enable_disable(), and any associated event
500 * (in the case of enable/disable_event triggers) will have its sm_ref
501 * decremented via free()->trace_event_enable_disable(). That
502 * combination effectively reverses the soft-mode/trigger state added
503 * by trigger registration.
505 * Must be called with event_mutex held.
508 clear_event_triggers(struct trace_array *tr)
510 struct trace_event_file *file;
512 list_for_each_entry(file, &tr->events, list) {
513 struct event_trigger_data *data, *n;
514 list_for_each_entry_safe(data, n, &file->triggers, list) {
515 trace_event_trigger_enable_disable(file, 0);
516 list_del_rcu(&data->list);
518 data->ops->free(data->ops, data);
524 * update_cond_flag - Set or reset the TRIGGER_COND bit
525 * @file: The trace_event_file associated with the event
527 * If an event has triggers and any of those triggers has a filter or
528 * a post_trigger, trigger invocation needs to be deferred until after
529 * the current event has logged its data, and the event should have
530 * its TRIGGER_COND bit set, otherwise the TRIGGER_COND bit should be
533 void update_cond_flag(struct trace_event_file *file)
535 struct event_trigger_data *data;
536 bool set_cond = false;
538 lockdep_assert_held(&event_mutex);
540 list_for_each_entry(data, &file->triggers, list) {
541 if (data->filter || event_command_post_trigger(data->cmd_ops) ||
542 event_command_needs_rec(data->cmd_ops)) {
549 set_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags);
551 clear_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags);
555 * register_trigger - Generic event_command @reg implementation
556 * @glob: The raw string used to register the trigger
557 * @data: Trigger-specific data to associate with the trigger
558 * @file: The trace_event_file associated with the event
560 * Common implementation for event trigger registration.
562 * Usually used directly as the @reg method in event command
565 * Return: 0 on success, errno otherwise
567 static int register_trigger(char *glob,
568 struct event_trigger_data *data,
569 struct trace_event_file *file)
571 struct event_trigger_data *test;
574 lockdep_assert_held(&event_mutex);
576 list_for_each_entry(test, &file->triggers, list) {
577 if (test->cmd_ops->trigger_type == data->cmd_ops->trigger_type) {
583 if (data->ops->init) {
584 ret = data->ops->init(data->ops, data);
589 list_add_rcu(&data->list, &file->triggers);
592 update_cond_flag(file);
593 if (trace_event_trigger_enable_disable(file, 1) < 0) {
594 list_del_rcu(&data->list);
595 update_cond_flag(file);
603 * unregister_trigger - Generic event_command @unreg implementation
604 * @glob: The raw string used to register the trigger
605 * @test: Trigger-specific data used to find the trigger to remove
606 * @file: The trace_event_file associated with the event
608 * Common implementation for event trigger unregistration.
610 * Usually used directly as the @unreg method in event command
613 static void unregister_trigger(char *glob,
614 struct event_trigger_data *test,
615 struct trace_event_file *file)
617 struct event_trigger_data *data;
618 bool unregistered = false;
620 lockdep_assert_held(&event_mutex);
622 list_for_each_entry(data, &file->triggers, list) {
623 if (data->cmd_ops->trigger_type == test->cmd_ops->trigger_type) {
625 list_del_rcu(&data->list);
626 trace_event_trigger_enable_disable(file, 0);
627 update_cond_flag(file);
632 if (unregistered && data->ops->free)
633 data->ops->free(data->ops, data);
637 * Event trigger parsing helper functions.
639 * These functions help make it easier to write an event trigger
640 * parsing function i.e. the struct event_command.parse() callback
641 * function responsible for parsing and registering a trigger command
642 * written to the 'trigger' file.
644 * A trigger command (or just 'trigger' for short) takes the form:
645 * [trigger] [if filter]
647 * The struct event_command.parse() callback (and other struct
648 * event_command functions) refer to several components of a trigger
649 * command. Those same components are referenced by the event trigger
650 * parsing helper functions defined below. These components are:
652 * cmd - the trigger command name
653 * glob - the trigger command name optionally prefaced with '!'
654 * param_and_filter - text following cmd and ':'
655 * param - text following cmd and ':' and stripped of filter
656 * filter - the optional filter text following (and including) 'if'
658 * To illustrate the use of these componenents, here are some concrete
659 * examples. For the following triggers:
661 * echo 'traceon:5 if pid == 0' > trigger
662 * - 'traceon' is both cmd and glob
663 * - '5 if pid == 0' is the param_and_filter
665 * - 'if pid == 0' is the filter
667 * echo 'enable_event:sys:event:n' > trigger
668 * - 'enable_event' is both cmd and glob
669 * - 'sys:event:n' is the param_and_filter
670 * - 'sys:event:n' is the param
671 * - there is no filter
673 * echo 'hist:keys=pid if prio > 50' > trigger
674 * - 'hist' is both cmd and glob
675 * - 'keys=pid if prio > 50' is the param_and_filter
676 * - 'keys=pid' is the param
677 * - 'if prio > 50' is the filter
679 * echo '!enable_event:sys:event:n' > trigger
680 * - 'enable_event' the cmd
681 * - '!enable_event' is the glob
682 * - 'sys:event:n' is the param_and_filter
683 * - 'sys:event:n' is the param
684 * - there is no filter
686 * echo 'traceoff' > trigger
687 * - 'traceoff' is both cmd and glob
688 * - there is no param_and_filter
689 * - there is no param
690 * - there is no filter
692 * There are a few different categories of event trigger covered by
695 * - triggers that don't require a parameter e.g. traceon
696 * - triggers that do require a parameter e.g. enable_event and hist
697 * - triggers that though they may not require a param may support an
698 * optional 'n' param (n = number of times the trigger should fire)
699 * e.g.: traceon:5 or enable_event:sys:event:n
700 * - triggers that do not support an 'n' param e.g. hist
702 * These functions can be used or ignored as necessary - it all
703 * depends on the complexity of the trigger, and the granularity of
704 * the functions supported reflects the fact that some implementations
705 * may need to customize certain aspects of their implementations and
706 * won't need certain functions. For instance, the hist trigger
707 * implementation doesn't use event_trigger_separate_filter() because
708 * it has special requirements for handling the filter.
712 * event_trigger_check_remove - check whether an event trigger specifies remove
713 * @glob: The trigger command string, with optional remove(!) operator
715 * The event trigger callback implementations pass in 'glob' as a
716 * parameter. This is the command name either with or without a
717 * remove(!) operator. This function simply parses the glob and
718 * determines whether the command corresponds to a trigger removal or
719 * a trigger addition.
721 * Return: true if this is a remove command, false otherwise
723 bool event_trigger_check_remove(const char *glob)
725 return (glob && glob[0] == '!') ? true : false;
729 * event_trigger_empty_param - check whether the param is empty
730 * @param: The trigger param string
732 * The event trigger callback implementations pass in 'param' as a
733 * parameter. This corresponds to the string following the command
734 * name minus the command name. This function can be called by a
735 * callback implementation for any command that requires a param; a
736 * callback that doesn't require a param can ignore it.
738 * Return: true if this is an empty param, false otherwise
740 bool event_trigger_empty_param(const char *param)
746 * event_trigger_separate_filter - separate an event trigger from a filter
747 * @param: The param string containing trigger and possibly filter
748 * @trigger: outparam, will be filled with a pointer to the trigger
749 * @filter: outparam, will be filled with a pointer to the filter
750 * @param_required: Specifies whether or not the param string is required
752 * Given a param string of the form '[trigger] [if filter]', this
753 * function separates the filter from the trigger and returns the
754 * trigger in *trigger and the filter in *filter. Either the *trigger
755 * or the *filter may be set to NULL by this function - if not set to
756 * NULL, they will contain strings corresponding to the trigger and
759 * There are two cases that need to be handled with respect to the
760 * passed-in param: either the param is required, or it is not
761 * required. If @param_required is set, and there's no param, it will
762 * return -EINVAL. If @param_required is not set and there's a param
763 * that starts with a number, that corresponds to the case of a
764 * trigger with :n (n = number of times the trigger should fire) and
765 * the parsing continues normally; otherwise the function just returns
766 * and assumes param just contains a filter and there's nothing else
769 * Return: 0 on success, errno otherwise
771 int event_trigger_separate_filter(char *param_and_filter, char **param,
772 char **filter, bool param_required)
776 *param = *filter = NULL;
778 if (!param_and_filter) {
785 * Here we check for an optional param. The only legal
786 * optional param is :n, and if that's the case, continue
787 * below. Otherwise we assume what's left is a filter and
788 * return it as the filter string for the caller to deal with.
790 if (!param_required && param_and_filter && !isdigit(param_and_filter[0])) {
791 *filter = param_and_filter;
796 * Separate the param from the filter (param [if filter]).
797 * Here we have either an optional :n param or a required
798 * param and an optional filter.
800 *param = strsep(¶m_and_filter, " \t");
803 * Here we have a filter, though it may be empty.
805 if (param_and_filter) {
806 *filter = skip_spaces(param_and_filter);
815 * event_trigger_alloc - allocate and init event_trigger_data for a trigger
816 * @cmd_ops: The event_command operations for the trigger
817 * @cmd: The cmd string
818 * @param: The param string
819 * @private_data: User data to associate with the event trigger
821 * Allocate an event_trigger_data instance and initialize it. The
822 * @cmd_ops are used along with the @cmd and @param to get the
823 * trigger_ops to assign to the event_trigger_data. @private_data can
824 * also be passed in and associated with the event_trigger_data.
826 * Use event_trigger_free() to free an event_trigger_data object.
828 * Return: The trigger_data object success, NULL otherwise
830 struct event_trigger_data *event_trigger_alloc(struct event_command *cmd_ops,
835 struct event_trigger_data *trigger_data;
836 struct event_trigger_ops *trigger_ops;
838 trigger_ops = cmd_ops->get_trigger_ops(cmd, param);
840 trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
844 trigger_data->count = -1;
845 trigger_data->ops = trigger_ops;
846 trigger_data->cmd_ops = cmd_ops;
847 trigger_data->private_data = private_data;
849 INIT_LIST_HEAD(&trigger_data->list);
850 INIT_LIST_HEAD(&trigger_data->named_list);
851 RCU_INIT_POINTER(trigger_data->filter, NULL);
857 * event_trigger_parse_num - parse and return the number param for a trigger
858 * @param: The param string
859 * @trigger_data: The trigger_data for the trigger
861 * Parse the :n (n = number of times the trigger should fire) param
862 * and set the count variable in the trigger_data to the parsed count.
864 * Return: 0 on success, errno otherwise
866 int event_trigger_parse_num(char *param,
867 struct event_trigger_data *trigger_data)
873 number = strsep(¶m, ":");
879 * We use the callback data field (which is a pointer)
882 ret = kstrtoul(number, 0, &trigger_data->count);
889 * event_trigger_set_filter - set an event trigger's filter
890 * @cmd_ops: The event_command operations for the trigger
891 * @file: The event file for the trigger's event
892 * @param: The string containing the filter
893 * @trigger_data: The trigger_data for the trigger
895 * Set the filter for the trigger. If the filter is NULL, just return
898 * Return: 0 on success, errno otherwise
900 int event_trigger_set_filter(struct event_command *cmd_ops,
901 struct trace_event_file *file,
903 struct event_trigger_data *trigger_data)
905 if (param && cmd_ops->set_filter)
906 return cmd_ops->set_filter(param, trigger_data, file);
912 * event_trigger_reset_filter - reset an event trigger's filter
913 * @cmd_ops: The event_command operations for the trigger
914 * @trigger_data: The trigger_data for the trigger
916 * Reset the filter for the trigger to no filter.
918 void event_trigger_reset_filter(struct event_command *cmd_ops,
919 struct event_trigger_data *trigger_data)
921 if (cmd_ops->set_filter)
922 cmd_ops->set_filter(NULL, trigger_data, NULL);
926 * event_trigger_register - register an event trigger
927 * @cmd_ops: The event_command operations for the trigger
928 * @file: The event file for the trigger's event
929 * @glob: The trigger command string, with optional remove(!) operator
930 * @cmd: The cmd string
931 * @param: The param string
932 * @trigger_data: The trigger_data for the trigger
933 * @n_registered: optional outparam, the number of triggers registered
935 * Register an event trigger. The @cmd_ops are used to call the
936 * cmd_ops->reg() function which actually does the registration. The
937 * cmd_ops->reg() function returns the number of triggers registered,
938 * which is assigned to n_registered, if n_registered is non-NULL.
940 * Return: 0 on success, errno otherwise
942 int event_trigger_register(struct event_command *cmd_ops,
943 struct trace_event_file *file,
947 struct event_trigger_data *trigger_data,
955 ret = cmd_ops->reg(glob, trigger_data, file);
957 * The above returns on success the # of functions enabled,
958 * but if it didn't find any functions it returns zero.
959 * Consider no functions a failure too.
962 cmd_ops->unreg(glob, trigger_data, file);
964 } else if (ret > 0) {
967 /* Just return zero, not the number of enabled functions */
975 * End event trigger parsing helper functions.
979 * event_trigger_parse - Generic event_command @parse implementation
980 * @cmd_ops: The command ops, used for trigger registration
981 * @file: The trace_event_file associated with the event
982 * @glob: The raw string used to register the trigger
983 * @cmd: The cmd portion of the string used to register the trigger
984 * @param: The params portion of the string used to register the trigger
986 * Common implementation for event command parsing and trigger
989 * Usually used directly as the @parse method in event command
992 * Return: 0 on success, errno otherwise
995 event_trigger_parse(struct event_command *cmd_ops,
996 struct trace_event_file *file,
997 char *glob, char *cmd, char *param)
999 struct event_trigger_data *trigger_data;
1000 struct event_trigger_ops *trigger_ops;
1001 char *trigger = NULL;
1005 /* separate the trigger from the filter (t:n [if filter]) */
1006 if (param && isdigit(param[0])) {
1007 trigger = strsep(¶m, " \t");
1009 param = skip_spaces(param);
1015 trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
1018 trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
1022 trigger_data->count = -1;
1023 trigger_data->ops = trigger_ops;
1024 trigger_data->cmd_ops = cmd_ops;
1025 trigger_data->private_data = file;
1026 INIT_LIST_HEAD(&trigger_data->list);
1027 INIT_LIST_HEAD(&trigger_data->named_list);
1029 if (glob[0] == '!') {
1030 cmd_ops->unreg(glob+1, trigger_data, file);
1031 kfree(trigger_data);
1037 number = strsep(&trigger, ":");
1040 if (!strlen(number))
1044 * We use the callback data field (which is a pointer)
1047 ret = kstrtoul(number, 0, &trigger_data->count);
1052 if (!param) /* if param is non-empty, it's supposed to be a filter */
1055 if (!cmd_ops->set_filter)
1058 ret = cmd_ops->set_filter(param, trigger_data, file);
1063 /* Up the trigger_data count to make sure reg doesn't free it on failure */
1064 event_trigger_init(trigger_ops, trigger_data);
1065 ret = cmd_ops->reg(glob, trigger_data, file);
1067 * The above returns on success the # of functions enabled,
1068 * but if it didn't find any functions it returns zero.
1069 * Consider no functions a failure too.
1072 cmd_ops->unreg(glob, trigger_data, file);
1077 /* Down the counter of trigger_data or free it if not used anymore */
1078 event_trigger_free(trigger_ops, trigger_data);
1083 if (cmd_ops->set_filter)
1084 cmd_ops->set_filter(NULL, trigger_data, NULL);
1085 kfree(trigger_data);
1090 * set_trigger_filter - Generic event_command @set_filter implementation
1091 * @filter_str: The filter string for the trigger, NULL to remove filter
1092 * @trigger_data: Trigger-specific data
1093 * @file: The trace_event_file associated with the event
1095 * Common implementation for event command filter parsing and filter
1098 * Usually used directly as the @set_filter method in event command
1101 * Also used to remove a filter (if filter_str = NULL).
1103 * Return: 0 on success, errno otherwise
1105 int set_trigger_filter(char *filter_str,
1106 struct event_trigger_data *trigger_data,
1107 struct trace_event_file *file)
1109 struct event_trigger_data *data = trigger_data;
1110 struct event_filter *filter = NULL, *tmp;
1114 if (!filter_str) /* clear the current filter */
1117 s = strsep(&filter_str, " \t");
1119 if (!strlen(s) || strcmp(s, "if") != 0)
1125 /* The filter is for the 'trigger' event, not the triggered event */
1126 ret = create_event_filter(file->tr, file->event_call,
1127 filter_str, false, &filter);
1129 * If create_event_filter() fails, filter still needs to be freed.
1130 * Which the calling code will do with data->filter.
1133 tmp = rcu_access_pointer(data->filter);
1135 rcu_assign_pointer(data->filter, filter);
1138 /* Make sure the call is done with the filter */
1139 tracepoint_synchronize_unregister();
1140 free_event_filter(tmp);
1143 kfree(data->filter_str);
1144 data->filter_str = NULL;
1147 data->filter_str = kstrdup(filter_str, GFP_KERNEL);
1148 if (!data->filter_str) {
1149 free_event_filter(rcu_access_pointer(data->filter));
1150 data->filter = NULL;
1158 static LIST_HEAD(named_triggers);
1161 * find_named_trigger - Find the common named trigger associated with @name
1162 * @name: The name of the set of named triggers to find the common data for
1164 * Named triggers are sets of triggers that share a common set of
1165 * trigger data. The first named trigger registered with a given name
1166 * owns the common trigger data that the others subsequently
1167 * registered with the same name will reference. This function
1168 * returns the common trigger data associated with that first
1169 * registered instance.
1171 * Return: the common trigger data for the given named trigger on
1172 * success, NULL otherwise.
1174 struct event_trigger_data *find_named_trigger(const char *name)
1176 struct event_trigger_data *data;
1181 list_for_each_entry(data, &named_triggers, named_list) {
1182 if (data->named_data)
1184 if (strcmp(data->name, name) == 0)
1192 * is_named_trigger - determine if a given trigger is a named trigger
1193 * @test: The trigger data to test
1195 * Return: true if 'test' is a named trigger, false otherwise.
1197 bool is_named_trigger(struct event_trigger_data *test)
1199 struct event_trigger_data *data;
1201 list_for_each_entry(data, &named_triggers, named_list) {
1210 * save_named_trigger - save the trigger in the named trigger list
1211 * @name: The name of the named trigger set
1212 * @data: The trigger data to save
1214 * Return: 0 if successful, negative error otherwise.
1216 int save_named_trigger(const char *name, struct event_trigger_data *data)
1218 data->name = kstrdup(name, GFP_KERNEL);
1222 list_add(&data->named_list, &named_triggers);
1228 * del_named_trigger - delete a trigger from the named trigger list
1229 * @data: The trigger data to delete
1231 void del_named_trigger(struct event_trigger_data *data)
1236 list_del(&data->named_list);
1239 static void __pause_named_trigger(struct event_trigger_data *data, bool pause)
1241 struct event_trigger_data *test;
1243 list_for_each_entry(test, &named_triggers, named_list) {
1244 if (strcmp(test->name, data->name) == 0) {
1246 test->paused_tmp = test->paused;
1247 test->paused = true;
1249 test->paused = test->paused_tmp;
1256 * pause_named_trigger - Pause all named triggers with the same name
1257 * @data: The trigger data of a named trigger to pause
1259 * Pauses a named trigger along with all other triggers having the
1260 * same name. Because named triggers share a common set of data,
1261 * pausing only one is meaningless, so pausing one named trigger needs
1262 * to pause all triggers with the same name.
1264 void pause_named_trigger(struct event_trigger_data *data)
1266 __pause_named_trigger(data, true);
1270 * unpause_named_trigger - Un-pause all named triggers with the same name
1271 * @data: The trigger data of a named trigger to unpause
1273 * Un-pauses a named trigger along with all other triggers having the
1274 * same name. Because named triggers share a common set of data,
1275 * unpausing only one is meaningless, so unpausing one named trigger
1276 * needs to unpause all triggers with the same name.
1278 void unpause_named_trigger(struct event_trigger_data *data)
1280 __pause_named_trigger(data, false);
1284 * set_named_trigger_data - Associate common named trigger data
1285 * @data: The trigger data to associate
1286 * @named_data: The common named trigger to be associated
1288 * Named triggers are sets of triggers that share a common set of
1289 * trigger data. The first named trigger registered with a given name
1290 * owns the common trigger data that the others subsequently
1291 * registered with the same name will reference. This function
1292 * associates the common trigger data from the first trigger with the
1295 void set_named_trigger_data(struct event_trigger_data *data,
1296 struct event_trigger_data *named_data)
1298 data->named_data = named_data;
1301 struct event_trigger_data *
1302 get_named_trigger_data(struct event_trigger_data *data)
1304 return data->named_data;
1308 traceon_trigger(struct event_trigger_data *data,
1309 struct trace_buffer *buffer, void *rec,
1310 struct ring_buffer_event *event)
1312 struct trace_event_file *file = data->private_data;
1315 if (tracer_tracing_is_on(file->tr))
1318 tracer_tracing_on(file->tr);
1322 if (tracing_is_on())
1329 traceon_count_trigger(struct event_trigger_data *data,
1330 struct trace_buffer *buffer, void *rec,
1331 struct ring_buffer_event *event)
1333 struct trace_event_file *file = data->private_data;
1336 if (tracer_tracing_is_on(file->tr))
1339 if (tracing_is_on())
1346 if (data->count != -1)
1350 tracer_tracing_on(file->tr);
1356 traceoff_trigger(struct event_trigger_data *data,
1357 struct trace_buffer *buffer, void *rec,
1358 struct ring_buffer_event *event)
1360 struct trace_event_file *file = data->private_data;
1363 if (!tracer_tracing_is_on(file->tr))
1366 tracer_tracing_off(file->tr);
1370 if (!tracing_is_on())
1377 traceoff_count_trigger(struct event_trigger_data *data,
1378 struct trace_buffer *buffer, void *rec,
1379 struct ring_buffer_event *event)
1381 struct trace_event_file *file = data->private_data;
1384 if (!tracer_tracing_is_on(file->tr))
1387 if (!tracing_is_on())
1394 if (data->count != -1)
1398 tracer_tracing_off(file->tr);
1404 traceon_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
1405 struct event_trigger_data *data)
1407 return event_trigger_print("traceon", m, (void *)data->count,
1412 traceoff_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
1413 struct event_trigger_data *data)
1415 return event_trigger_print("traceoff", m, (void *)data->count,
1419 static struct event_trigger_ops traceon_trigger_ops = {
1420 .trigger = traceon_trigger,
1421 .print = traceon_trigger_print,
1422 .init = event_trigger_init,
1423 .free = event_trigger_free,
1426 static struct event_trigger_ops traceon_count_trigger_ops = {
1427 .trigger = traceon_count_trigger,
1428 .print = traceon_trigger_print,
1429 .init = event_trigger_init,
1430 .free = event_trigger_free,
1433 static struct event_trigger_ops traceoff_trigger_ops = {
1434 .trigger = traceoff_trigger,
1435 .print = traceoff_trigger_print,
1436 .init = event_trigger_init,
1437 .free = event_trigger_free,
1440 static struct event_trigger_ops traceoff_count_trigger_ops = {
1441 .trigger = traceoff_count_trigger,
1442 .print = traceoff_trigger_print,
1443 .init = event_trigger_init,
1444 .free = event_trigger_free,
1447 static struct event_trigger_ops *
1448 onoff_get_trigger_ops(char *cmd, char *param)
1450 struct event_trigger_ops *ops;
1452 /* we register both traceon and traceoff to this callback */
1453 if (strcmp(cmd, "traceon") == 0)
1454 ops = param ? &traceon_count_trigger_ops :
1455 &traceon_trigger_ops;
1457 ops = param ? &traceoff_count_trigger_ops :
1458 &traceoff_trigger_ops;
1463 static struct event_command trigger_traceon_cmd = {
1465 .trigger_type = ETT_TRACE_ONOFF,
1466 .parse = event_trigger_parse,
1467 .reg = register_trigger,
1468 .unreg = unregister_trigger,
1469 .get_trigger_ops = onoff_get_trigger_ops,
1470 .set_filter = set_trigger_filter,
1473 static struct event_command trigger_traceoff_cmd = {
1475 .trigger_type = ETT_TRACE_ONOFF,
1476 .flags = EVENT_CMD_FL_POST_TRIGGER,
1477 .parse = event_trigger_parse,
1478 .reg = register_trigger,
1479 .unreg = unregister_trigger,
1480 .get_trigger_ops = onoff_get_trigger_ops,
1481 .set_filter = set_trigger_filter,
1484 #ifdef CONFIG_TRACER_SNAPSHOT
1486 snapshot_trigger(struct event_trigger_data *data,
1487 struct trace_buffer *buffer, void *rec,
1488 struct ring_buffer_event *event)
1490 struct trace_event_file *file = data->private_data;
1493 tracing_snapshot_instance(file->tr);
1499 snapshot_count_trigger(struct event_trigger_data *data,
1500 struct trace_buffer *buffer, void *rec,
1501 struct ring_buffer_event *event)
1506 if (data->count != -1)
1509 snapshot_trigger(data, buffer, rec, event);
1513 register_snapshot_trigger(char *glob,
1514 struct event_trigger_data *data,
1515 struct trace_event_file *file)
1517 if (tracing_alloc_snapshot_instance(file->tr) != 0)
1520 return register_trigger(glob, data, file);
1524 snapshot_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
1525 struct event_trigger_data *data)
1527 return event_trigger_print("snapshot", m, (void *)data->count,
1531 static struct event_trigger_ops snapshot_trigger_ops = {
1532 .trigger = snapshot_trigger,
1533 .print = snapshot_trigger_print,
1534 .init = event_trigger_init,
1535 .free = event_trigger_free,
1538 static struct event_trigger_ops snapshot_count_trigger_ops = {
1539 .trigger = snapshot_count_trigger,
1540 .print = snapshot_trigger_print,
1541 .init = event_trigger_init,
1542 .free = event_trigger_free,
1545 static struct event_trigger_ops *
1546 snapshot_get_trigger_ops(char *cmd, char *param)
1548 return param ? &snapshot_count_trigger_ops : &snapshot_trigger_ops;
1551 static struct event_command trigger_snapshot_cmd = {
1553 .trigger_type = ETT_SNAPSHOT,
1554 .parse = event_trigger_parse,
1555 .reg = register_snapshot_trigger,
1556 .unreg = unregister_trigger,
1557 .get_trigger_ops = snapshot_get_trigger_ops,
1558 .set_filter = set_trigger_filter,
1561 static __init int register_trigger_snapshot_cmd(void)
1565 ret = register_event_command(&trigger_snapshot_cmd);
1571 static __init int register_trigger_snapshot_cmd(void) { return 0; }
1572 #endif /* CONFIG_TRACER_SNAPSHOT */
1574 #ifdef CONFIG_STACKTRACE
1575 #ifdef CONFIG_UNWINDER_ORC
1577 * event_triggers_post_call()
1578 * trace_event_raw_event_xxx()
1580 # define STACK_SKIP 2
1584 * stacktrace_trigger()
1585 * event_triggers_post_call()
1586 * trace_event_buffer_commit()
1587 * trace_event_raw_event_xxx()
1589 #define STACK_SKIP 4
1593 stacktrace_trigger(struct event_trigger_data *data,
1594 struct trace_buffer *buffer, void *rec,
1595 struct ring_buffer_event *event)
1597 struct trace_event_file *file = data->private_data;
1600 __trace_stack(file->tr, tracing_gen_ctx(), STACK_SKIP);
1602 trace_dump_stack(STACK_SKIP);
1606 stacktrace_count_trigger(struct event_trigger_data *data,
1607 struct trace_buffer *buffer, void *rec,
1608 struct ring_buffer_event *event)
1613 if (data->count != -1)
1616 stacktrace_trigger(data, buffer, rec, event);
1620 stacktrace_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
1621 struct event_trigger_data *data)
1623 return event_trigger_print("stacktrace", m, (void *)data->count,
1627 static struct event_trigger_ops stacktrace_trigger_ops = {
1628 .trigger = stacktrace_trigger,
1629 .print = stacktrace_trigger_print,
1630 .init = event_trigger_init,
1631 .free = event_trigger_free,
1634 static struct event_trigger_ops stacktrace_count_trigger_ops = {
1635 .trigger = stacktrace_count_trigger,
1636 .print = stacktrace_trigger_print,
1637 .init = event_trigger_init,
1638 .free = event_trigger_free,
1641 static struct event_trigger_ops *
1642 stacktrace_get_trigger_ops(char *cmd, char *param)
1644 return param ? &stacktrace_count_trigger_ops : &stacktrace_trigger_ops;
1647 static struct event_command trigger_stacktrace_cmd = {
1648 .name = "stacktrace",
1649 .trigger_type = ETT_STACKTRACE,
1650 .flags = EVENT_CMD_FL_POST_TRIGGER,
1651 .parse = event_trigger_parse,
1652 .reg = register_trigger,
1653 .unreg = unregister_trigger,
1654 .get_trigger_ops = stacktrace_get_trigger_ops,
1655 .set_filter = set_trigger_filter,
1658 static __init int register_trigger_stacktrace_cmd(void)
1662 ret = register_event_command(&trigger_stacktrace_cmd);
1668 static __init int register_trigger_stacktrace_cmd(void) { return 0; }
1669 #endif /* CONFIG_STACKTRACE */
1671 static __init void unregister_trigger_traceon_traceoff_cmds(void)
1673 unregister_event_command(&trigger_traceon_cmd);
1674 unregister_event_command(&trigger_traceoff_cmd);
1678 event_enable_trigger(struct event_trigger_data *data,
1679 struct trace_buffer *buffer, void *rec,
1680 struct ring_buffer_event *event)
1682 struct enable_trigger_data *enable_data = data->private_data;
1684 if (enable_data->enable)
1685 clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags);
1687 set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags);
1691 event_enable_count_trigger(struct event_trigger_data *data,
1692 struct trace_buffer *buffer, void *rec,
1693 struct ring_buffer_event *event)
1695 struct enable_trigger_data *enable_data = data->private_data;
1700 /* Skip if the event is in a state we want to switch to */
1701 if (enable_data->enable == !(enable_data->file->flags & EVENT_FILE_FL_SOFT_DISABLED))
1704 if (data->count != -1)
1707 event_enable_trigger(data, buffer, rec, event);
1710 int event_enable_trigger_print(struct seq_file *m,
1711 struct event_trigger_ops *ops,
1712 struct event_trigger_data *data)
1714 struct enable_trigger_data *enable_data = data->private_data;
1716 seq_printf(m, "%s:%s:%s",
1718 (enable_data->enable ? ENABLE_HIST_STR : DISABLE_HIST_STR) :
1719 (enable_data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR),
1720 enable_data->file->event_call->class->system,
1721 trace_event_name(enable_data->file->event_call));
1723 if (data->count == -1)
1724 seq_puts(m, ":unlimited");
1726 seq_printf(m, ":count=%ld", data->count);
1728 if (data->filter_str)
1729 seq_printf(m, " if %s\n", data->filter_str);
1736 void event_enable_trigger_free(struct event_trigger_ops *ops,
1737 struct event_trigger_data *data)
1739 struct enable_trigger_data *enable_data = data->private_data;
1741 if (WARN_ON_ONCE(data->ref <= 0))
1746 /* Remove the SOFT_MODE flag */
1747 trace_event_enable_disable(enable_data->file, 0, 1);
1748 trace_event_put_ref(enable_data->file->event_call);
1749 trigger_data_free(data);
1754 static struct event_trigger_ops event_enable_trigger_ops = {
1755 .trigger = event_enable_trigger,
1756 .print = event_enable_trigger_print,
1757 .init = event_trigger_init,
1758 .free = event_enable_trigger_free,
1761 static struct event_trigger_ops event_enable_count_trigger_ops = {
1762 .trigger = event_enable_count_trigger,
1763 .print = event_enable_trigger_print,
1764 .init = event_trigger_init,
1765 .free = event_enable_trigger_free,
1768 static struct event_trigger_ops event_disable_trigger_ops = {
1769 .trigger = event_enable_trigger,
1770 .print = event_enable_trigger_print,
1771 .init = event_trigger_init,
1772 .free = event_enable_trigger_free,
1775 static struct event_trigger_ops event_disable_count_trigger_ops = {
1776 .trigger = event_enable_count_trigger,
1777 .print = event_enable_trigger_print,
1778 .init = event_trigger_init,
1779 .free = event_enable_trigger_free,
1782 int event_enable_trigger_parse(struct event_command *cmd_ops,
1783 struct trace_event_file *file,
1784 char *glob, char *cmd, char *param)
1786 struct trace_event_file *event_enable_file;
1787 struct enable_trigger_data *enable_data;
1788 struct event_trigger_data *trigger_data;
1789 struct event_trigger_ops *trigger_ops;
1790 struct trace_array *tr = file->tr;
1802 /* separate the trigger from the filter (s:e:n [if filter]) */
1803 trigger = strsep(¶m, " \t");
1807 param = skip_spaces(param);
1812 system = strsep(&trigger, ":");
1816 event = strsep(&trigger, ":");
1819 event_enable_file = find_event_file(tr, system, event);
1820 if (!event_enable_file)
1823 #ifdef CONFIG_HIST_TRIGGERS
1824 hist = ((strcmp(cmd, ENABLE_HIST_STR) == 0) ||
1825 (strcmp(cmd, DISABLE_HIST_STR) == 0));
1827 enable = ((strcmp(cmd, ENABLE_EVENT_STR) == 0) ||
1828 (strcmp(cmd, ENABLE_HIST_STR) == 0));
1830 enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
1832 trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
1835 trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
1839 enable_data = kzalloc(sizeof(*enable_data), GFP_KERNEL);
1841 kfree(trigger_data);
1845 trigger_data->count = -1;
1846 trigger_data->ops = trigger_ops;
1847 trigger_data->cmd_ops = cmd_ops;
1848 INIT_LIST_HEAD(&trigger_data->list);
1849 RCU_INIT_POINTER(trigger_data->filter, NULL);
1851 enable_data->hist = hist;
1852 enable_data->enable = enable;
1853 enable_data->file = event_enable_file;
1854 trigger_data->private_data = enable_data;
1856 if (glob[0] == '!') {
1857 cmd_ops->unreg(glob+1, trigger_data, file);
1858 kfree(trigger_data);
1864 /* Up the trigger_data count to make sure nothing frees it on failure */
1865 event_trigger_init(trigger_ops, trigger_data);
1868 number = strsep(&trigger, ":");
1871 if (!strlen(number))
1875 * We use the callback data field (which is a pointer)
1878 ret = kstrtoul(number, 0, &trigger_data->count);
1883 if (!param) /* if param is non-empty, it's supposed to be a filter */
1886 if (!cmd_ops->set_filter)
1889 ret = cmd_ops->set_filter(param, trigger_data, file);
1894 /* Don't let event modules unload while probe registered */
1895 ret = trace_event_try_get_ref(event_enable_file->event_call);
1901 ret = trace_event_enable_disable(event_enable_file, 1, 1);
1904 ret = cmd_ops->reg(glob, trigger_data, file);
1906 * The above returns on success the # of functions enabled,
1907 * but if it didn't find any functions it returns zero.
1908 * Consider no functions a failure too.
1915 /* Just return zero, not the number of enabled functions */
1917 event_trigger_free(trigger_ops, trigger_data);
1922 trace_event_enable_disable(event_enable_file, 0, 1);
1924 trace_event_put_ref(event_enable_file->event_call);
1926 if (cmd_ops->set_filter)
1927 cmd_ops->set_filter(NULL, trigger_data, NULL);
1928 event_trigger_free(trigger_ops, trigger_data);
1933 int event_enable_register_trigger(char *glob,
1934 struct event_trigger_data *data,
1935 struct trace_event_file *file)
1937 struct enable_trigger_data *enable_data = data->private_data;
1938 struct enable_trigger_data *test_enable_data;
1939 struct event_trigger_data *test;
1942 lockdep_assert_held(&event_mutex);
1944 list_for_each_entry(test, &file->triggers, list) {
1945 test_enable_data = test->private_data;
1946 if (test_enable_data &&
1947 (test->cmd_ops->trigger_type ==
1948 data->cmd_ops->trigger_type) &&
1949 (test_enable_data->file == enable_data->file)) {
1955 if (data->ops->init) {
1956 ret = data->ops->init(data->ops, data);
1961 list_add_rcu(&data->list, &file->triggers);
1964 update_cond_flag(file);
1965 if (trace_event_trigger_enable_disable(file, 1) < 0) {
1966 list_del_rcu(&data->list);
1967 update_cond_flag(file);
1974 void event_enable_unregister_trigger(char *glob,
1975 struct event_trigger_data *test,
1976 struct trace_event_file *file)
1978 struct enable_trigger_data *test_enable_data = test->private_data;
1979 struct enable_trigger_data *enable_data;
1980 struct event_trigger_data *data;
1981 bool unregistered = false;
1983 lockdep_assert_held(&event_mutex);
1985 list_for_each_entry(data, &file->triggers, list) {
1986 enable_data = data->private_data;
1988 (data->cmd_ops->trigger_type ==
1989 test->cmd_ops->trigger_type) &&
1990 (enable_data->file == test_enable_data->file)) {
1991 unregistered = true;
1992 list_del_rcu(&data->list);
1993 trace_event_trigger_enable_disable(file, 0);
1994 update_cond_flag(file);
1999 if (unregistered && data->ops->free)
2000 data->ops->free(data->ops, data);
2003 static struct event_trigger_ops *
2004 event_enable_get_trigger_ops(char *cmd, char *param)
2006 struct event_trigger_ops *ops;
2009 #ifdef CONFIG_HIST_TRIGGERS
2010 enable = ((strcmp(cmd, ENABLE_EVENT_STR) == 0) ||
2011 (strcmp(cmd, ENABLE_HIST_STR) == 0));
2013 enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
2016 ops = param ? &event_enable_count_trigger_ops :
2017 &event_enable_trigger_ops;
2019 ops = param ? &event_disable_count_trigger_ops :
2020 &event_disable_trigger_ops;
2025 static struct event_command trigger_enable_cmd = {
2026 .name = ENABLE_EVENT_STR,
2027 .trigger_type = ETT_EVENT_ENABLE,
2028 .parse = event_enable_trigger_parse,
2029 .reg = event_enable_register_trigger,
2030 .unreg = event_enable_unregister_trigger,
2031 .get_trigger_ops = event_enable_get_trigger_ops,
2032 .set_filter = set_trigger_filter,
2035 static struct event_command trigger_disable_cmd = {
2036 .name = DISABLE_EVENT_STR,
2037 .trigger_type = ETT_EVENT_ENABLE,
2038 .parse = event_enable_trigger_parse,
2039 .reg = event_enable_register_trigger,
2040 .unreg = event_enable_unregister_trigger,
2041 .get_trigger_ops = event_enable_get_trigger_ops,
2042 .set_filter = set_trigger_filter,
2045 static __init void unregister_trigger_enable_disable_cmds(void)
2047 unregister_event_command(&trigger_enable_cmd);
2048 unregister_event_command(&trigger_disable_cmd);
2051 static __init int register_trigger_enable_disable_cmds(void)
2055 ret = register_event_command(&trigger_enable_cmd);
2056 if (WARN_ON(ret < 0))
2058 ret = register_event_command(&trigger_disable_cmd);
2059 if (WARN_ON(ret < 0))
2060 unregister_trigger_enable_disable_cmds();
2065 static __init int register_trigger_traceon_traceoff_cmds(void)
2069 ret = register_event_command(&trigger_traceon_cmd);
2070 if (WARN_ON(ret < 0))
2072 ret = register_event_command(&trigger_traceoff_cmd);
2073 if (WARN_ON(ret < 0))
2074 unregister_trigger_traceon_traceoff_cmds();
2079 __init int register_trigger_cmds(void)
2081 register_trigger_traceon_traceoff_cmds();
2082 register_trigger_snapshot_cmd();
2083 register_trigger_stacktrace_cmd();
2084 register_trigger_enable_disable_cmds();
2085 register_trigger_hist_enable_disable_cmds();
2086 register_trigger_hist_cmd();