trace_events_trigger.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  1. /*
  2. * trace_events_trigger - trace event triggers
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright (C) 2013 Tom Zanussi <tom.zanussi@linux.intel.com>
  19. */
  20. #include <linux/module.h>
  21. #include <linux/ctype.h>
  22. #include <linux/mutex.h>
  23. #include <linux/slab.h>
  24. #include "trace.h"
  25. static LIST_HEAD(trigger_commands);
  26. static DEFINE_MUTEX(trigger_cmd_mutex);
  27. static void
  28. trigger_data_free(struct event_trigger_data *data)
  29. {
  30. if (data->cmd_ops->set_filter)
  31. data->cmd_ops->set_filter(NULL, data, NULL);
  32. synchronize_sched(); /* make sure current triggers exit before free */
  33. kfree(data);
  34. }
  35. /**
  36. * event_triggers_call - Call triggers associated with a trace event
  37. * @file: The trace_event_file associated with the event
  38. * @rec: The trace entry for the event, NULL for unconditional invocation
  39. *
  40. * For each trigger associated with an event, invoke the trigger
  41. * function registered with the associated trigger command. If rec is
  42. * non-NULL, it means that the trigger requires further processing and
  43. * shouldn't be unconditionally invoked. If rec is non-NULL and the
  44. * trigger has a filter associated with it, rec will checked against
  45. * the filter and if the record matches the trigger will be invoked.
  46. * If the trigger is a 'post_trigger', meaning it shouldn't be invoked
  47. * in any case until the current event is written, the trigger
  48. * function isn't invoked but the bit associated with the deferred
  49. * trigger is set in the return value.
  50. *
  51. * Returns an enum event_trigger_type value containing a set bit for
  52. * any trigger that should be deferred, ETT_NONE if nothing to defer.
  53. *
  54. * Called from tracepoint handlers (with rcu_read_lock_sched() held).
  55. *
  56. * Return: an enum event_trigger_type value containing a set bit for
  57. * any trigger that should be deferred, ETT_NONE if nothing to defer.
  58. */
  59. enum event_trigger_type
  60. event_triggers_call(struct trace_event_file *file, void *rec)
  61. {
  62. struct event_trigger_data *data;
  63. enum event_trigger_type tt = ETT_NONE;
  64. struct event_filter *filter;
  65. if (list_empty(&file->triggers))
  66. return tt;
  67. list_for_each_entry_rcu(data, &file->triggers, list) {
  68. if (!rec) {
  69. data->ops->func(data);
  70. continue;
  71. }
  72. filter = rcu_dereference_sched(data->filter);
  73. if (filter && !filter_match_preds(filter, rec))
  74. continue;
  75. if (data->cmd_ops->post_trigger) {
  76. tt |= data->cmd_ops->trigger_type;
  77. continue;
  78. }
  79. data->ops->func(data);
  80. }
  81. return tt;
  82. }
  83. EXPORT_SYMBOL_GPL(event_triggers_call);
  84. /**
  85. * event_triggers_post_call - Call 'post_triggers' for a trace event
  86. * @file: The trace_event_file associated with the event
  87. * @tt: enum event_trigger_type containing a set bit for each trigger to invoke
  88. *
  89. * For each trigger associated with an event, invoke the trigger
  90. * function registered with the associated trigger command, if the
  91. * corresponding bit is set in the tt enum passed into this function.
  92. * See @event_triggers_call for details on how those bits are set.
  93. *
  94. * Called from tracepoint handlers (with rcu_read_lock_sched() held).
  95. */
  96. void
  97. event_triggers_post_call(struct trace_event_file *file,
  98. enum event_trigger_type tt)
  99. {
  100. struct event_trigger_data *data;
  101. list_for_each_entry_rcu(data, &file->triggers, list) {
  102. if (data->cmd_ops->trigger_type & tt)
  103. data->ops->func(data);
  104. }
  105. }
  106. EXPORT_SYMBOL_GPL(event_triggers_post_call);
  107. #define SHOW_AVAILABLE_TRIGGERS (void *)(1UL)
  108. static void *trigger_next(struct seq_file *m, void *t, loff_t *pos)
  109. {
  110. struct trace_event_file *event_file = event_file_data(m->private);
  111. if (t == SHOW_AVAILABLE_TRIGGERS)
  112. return NULL;
  113. return seq_list_next(t, &event_file->triggers, pos);
  114. }
  115. static void *trigger_start(struct seq_file *m, loff_t *pos)
  116. {
  117. struct trace_event_file *event_file;
  118. /* ->stop() is called even if ->start() fails */
  119. mutex_lock(&event_mutex);
  120. event_file = event_file_data(m->private);
  121. if (unlikely(!event_file))
  122. return ERR_PTR(-ENODEV);
  123. if (list_empty(&event_file->triggers))
  124. return *pos == 0 ? SHOW_AVAILABLE_TRIGGERS : NULL;
  125. return seq_list_start(&event_file->triggers, *pos);
  126. }
  127. static void trigger_stop(struct seq_file *m, void *t)
  128. {
  129. mutex_unlock(&event_mutex);
  130. }
  131. static int trigger_show(struct seq_file *m, void *v)
  132. {
  133. struct event_trigger_data *data;
  134. struct event_command *p;
  135. if (v == SHOW_AVAILABLE_TRIGGERS) {
  136. seq_puts(m, "# Available triggers:\n");
  137. seq_putc(m, '#');
  138. mutex_lock(&trigger_cmd_mutex);
  139. list_for_each_entry_reverse(p, &trigger_commands, list)
  140. seq_printf(m, " %s", p->name);
  141. seq_putc(m, '\n');
  142. mutex_unlock(&trigger_cmd_mutex);
  143. return 0;
  144. }
  145. data = list_entry(v, struct event_trigger_data, list);
  146. data->ops->print(m, data->ops, data);
  147. return 0;
  148. }
  149. static const struct seq_operations event_triggers_seq_ops = {
  150. .start = trigger_start,
  151. .next = trigger_next,
  152. .stop = trigger_stop,
  153. .show = trigger_show,
  154. };
  155. static int event_trigger_regex_open(struct inode *inode, struct file *file)
  156. {
  157. int ret = 0;
  158. mutex_lock(&event_mutex);
  159. if (unlikely(!event_file_data(file))) {
  160. mutex_unlock(&event_mutex);
  161. return -ENODEV;
  162. }
  163. if (file->f_mode & FMODE_READ) {
  164. ret = seq_open(file, &event_triggers_seq_ops);
  165. if (!ret) {
  166. struct seq_file *m = file->private_data;
  167. m->private = file;
  168. }
  169. }
  170. mutex_unlock(&event_mutex);
  171. return ret;
  172. }
  173. static int trigger_process_regex(struct trace_event_file *file, char *buff)
  174. {
  175. char *command, *next = buff;
  176. struct event_command *p;
  177. int ret = -EINVAL;
  178. command = strsep(&next, ": \t");
  179. command = (command[0] != '!') ? command : command + 1;
  180. mutex_lock(&trigger_cmd_mutex);
  181. list_for_each_entry(p, &trigger_commands, list) {
  182. if (strcmp(p->name, command) == 0) {
  183. ret = p->func(p, file, buff, command, next);
  184. goto out_unlock;
  185. }
  186. }
  187. out_unlock:
  188. mutex_unlock(&trigger_cmd_mutex);
  189. return ret;
  190. }
  191. static ssize_t event_trigger_regex_write(struct file *file,
  192. const char __user *ubuf,
  193. size_t cnt, loff_t *ppos)
  194. {
  195. struct trace_event_file *event_file;
  196. ssize_t ret;
  197. char *buf;
  198. if (!cnt)
  199. return 0;
  200. if (cnt >= PAGE_SIZE)
  201. return -EINVAL;
  202. buf = (char *)__get_free_page(GFP_TEMPORARY);
  203. if (!buf)
  204. return -ENOMEM;
  205. if (copy_from_user(buf, ubuf, cnt)) {
  206. free_page((unsigned long)buf);
  207. return -EFAULT;
  208. }
  209. buf[cnt] = '\0';
  210. strim(buf);
  211. mutex_lock(&event_mutex);
  212. event_file = event_file_data(file);
  213. if (unlikely(!event_file)) {
  214. mutex_unlock(&event_mutex);
  215. free_page((unsigned long)buf);
  216. return -ENODEV;
  217. }
  218. ret = trigger_process_regex(event_file, buf);
  219. mutex_unlock(&event_mutex);
  220. free_page((unsigned long)buf);
  221. if (ret < 0)
  222. goto out;
  223. *ppos += cnt;
  224. ret = cnt;
  225. out:
  226. return ret;
  227. }
  228. static int event_trigger_regex_release(struct inode *inode, struct file *file)
  229. {
  230. mutex_lock(&event_mutex);
  231. if (file->f_mode & FMODE_READ)
  232. seq_release(inode, file);
  233. mutex_unlock(&event_mutex);
  234. return 0;
  235. }
  236. static ssize_t
  237. event_trigger_write(struct file *filp, const char __user *ubuf,
  238. size_t cnt, loff_t *ppos)
  239. {
  240. return event_trigger_regex_write(filp, ubuf, cnt, ppos);
  241. }
  242. static int
  243. event_trigger_open(struct inode *inode, struct file *filp)
  244. {
  245. return event_trigger_regex_open(inode, filp);
  246. }
  247. static int
  248. event_trigger_release(struct inode *inode, struct file *file)
  249. {
  250. return event_trigger_regex_release(inode, file);
  251. }
  252. const struct file_operations event_trigger_fops = {
  253. .open = event_trigger_open,
  254. .read = seq_read,
  255. .write = event_trigger_write,
  256. .llseek = tracing_lseek,
  257. .release = event_trigger_release,
  258. };
  259. /*
  260. * Currently we only register event commands from __init, so mark this
  261. * __init too.
  262. */
  263. static __init int register_event_command(struct event_command *cmd)
  264. {
  265. struct event_command *p;
  266. int ret = 0;
  267. mutex_lock(&trigger_cmd_mutex);
  268. list_for_each_entry(p, &trigger_commands, list) {
  269. if (strcmp(cmd->name, p->name) == 0) {
  270. ret = -EBUSY;
  271. goto out_unlock;
  272. }
  273. }
  274. list_add(&cmd->list, &trigger_commands);
  275. out_unlock:
  276. mutex_unlock(&trigger_cmd_mutex);
  277. return ret;
  278. }
  279. /*
  280. * Currently we only unregister event commands from __init, so mark
  281. * this __init too.
  282. */
  283. static __init int unregister_event_command(struct event_command *cmd)
  284. {
  285. struct event_command *p, *n;
  286. int ret = -ENODEV;
  287. mutex_lock(&trigger_cmd_mutex);
  288. list_for_each_entry_safe(p, n, &trigger_commands, list) {
  289. if (strcmp(cmd->name, p->name) == 0) {
  290. ret = 0;
  291. list_del_init(&p->list);
  292. goto out_unlock;
  293. }
  294. }
  295. out_unlock:
  296. mutex_unlock(&trigger_cmd_mutex);
  297. return ret;
  298. }
  299. /**
  300. * event_trigger_print - Generic event_trigger_ops @print implementation
  301. * @name: The name of the event trigger
  302. * @m: The seq_file being printed to
  303. * @data: Trigger-specific data
  304. * @filter_str: filter_str to print, if present
  305. *
  306. * Common implementation for event triggers to print themselves.
  307. *
  308. * Usually wrapped by a function that simply sets the @name of the
  309. * trigger command and then invokes this.
  310. *
  311. * Return: 0 on success, errno otherwise
  312. */
  313. static int
  314. event_trigger_print(const char *name, struct seq_file *m,
  315. void *data, char *filter_str)
  316. {
  317. long count = (long)data;
  318. seq_puts(m, name);
  319. if (count == -1)
  320. seq_puts(m, ":unlimited");
  321. else
  322. seq_printf(m, ":count=%ld", count);
  323. if (filter_str)
  324. seq_printf(m, " if %s\n", filter_str);
  325. else
  326. seq_putc(m, '\n');
  327. return 0;
  328. }
  329. /**
  330. * event_trigger_init - Generic event_trigger_ops @init implementation
  331. * @ops: The trigger ops associated with the trigger
  332. * @data: Trigger-specific data
  333. *
  334. * Common implementation of event trigger initialization.
  335. *
  336. * Usually used directly as the @init method in event trigger
  337. * implementations.
  338. *
  339. * Return: 0 on success, errno otherwise
  340. */
  341. static int
  342. event_trigger_init(struct event_trigger_ops *ops,
  343. struct event_trigger_data *data)
  344. {
  345. data->ref++;
  346. return 0;
  347. }
  348. /**
  349. * event_trigger_free - Generic event_trigger_ops @free implementation
  350. * @ops: The trigger ops associated with the trigger
  351. * @data: Trigger-specific data
  352. *
  353. * Common implementation of event trigger de-initialization.
  354. *
  355. * Usually used directly as the @free method in event trigger
  356. * implementations.
  357. */
  358. static void
  359. event_trigger_free(struct event_trigger_ops *ops,
  360. struct event_trigger_data *data)
  361. {
  362. if (WARN_ON_ONCE(data->ref <= 0))
  363. return;
  364. data->ref--;
  365. if (!data->ref)
  366. trigger_data_free(data);
  367. }
  368. static int trace_event_trigger_enable_disable(struct trace_event_file *file,
  369. int trigger_enable)
  370. {
  371. int ret = 0;
  372. if (trigger_enable) {
  373. if (atomic_inc_return(&file->tm_ref) > 1)
  374. return ret;
  375. set_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
  376. ret = trace_event_enable_disable(file, 1, 1);
  377. } else {
  378. if (atomic_dec_return(&file->tm_ref) > 0)
  379. return ret;
  380. clear_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
  381. ret = trace_event_enable_disable(file, 0, 1);
  382. }
  383. return ret;
  384. }
  385. /**
  386. * clear_event_triggers - Clear all triggers associated with a trace array
  387. * @tr: The trace array to clear
  388. *
  389. * For each trigger, the triggering event has its tm_ref decremented
  390. * via trace_event_trigger_enable_disable(), and any associated event
  391. * (in the case of enable/disable_event triggers) will have its sm_ref
  392. * decremented via free()->trace_event_enable_disable(). That
  393. * combination effectively reverses the soft-mode/trigger state added
  394. * by trigger registration.
  395. *
  396. * Must be called with event_mutex held.
  397. */
  398. void
  399. clear_event_triggers(struct trace_array *tr)
  400. {
  401. struct trace_event_file *file;
  402. list_for_each_entry(file, &tr->events, list) {
  403. struct event_trigger_data *data;
  404. list_for_each_entry_rcu(data, &file->triggers, list) {
  405. trace_event_trigger_enable_disable(file, 0);
  406. if (data->ops->free)
  407. data->ops->free(data->ops, data);
  408. }
  409. }
  410. }
  411. /**
  412. * update_cond_flag - Set or reset the TRIGGER_COND bit
  413. * @file: The trace_event_file associated with the event
  414. *
  415. * If an event has triggers and any of those triggers has a filter or
  416. * a post_trigger, trigger invocation needs to be deferred until after
  417. * the current event has logged its data, and the event should have
  418. * its TRIGGER_COND bit set, otherwise the TRIGGER_COND bit should be
  419. * cleared.
  420. */
  421. static void update_cond_flag(struct trace_event_file *file)
  422. {
  423. struct event_trigger_data *data;
  424. bool set_cond = false;
  425. list_for_each_entry_rcu(data, &file->triggers, list) {
  426. if (data->filter || data->cmd_ops->post_trigger) {
  427. set_cond = true;
  428. break;
  429. }
  430. }
  431. if (set_cond)
  432. set_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags);
  433. else
  434. clear_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags);
  435. }
  436. /**
  437. * register_trigger - Generic event_command @reg implementation
  438. * @glob: The raw string used to register the trigger
  439. * @ops: The trigger ops associated with the trigger
  440. * @data: Trigger-specific data to associate with the trigger
  441. * @file: The trace_event_file associated with the event
  442. *
  443. * Common implementation for event trigger registration.
  444. *
  445. * Usually used directly as the @reg method in event command
  446. * implementations.
  447. *
  448. * Return: 0 on success, errno otherwise
  449. */
  450. static int register_trigger(char *glob, struct event_trigger_ops *ops,
  451. struct event_trigger_data *data,
  452. struct trace_event_file *file)
  453. {
  454. struct event_trigger_data *test;
  455. int ret = 0;
  456. list_for_each_entry_rcu(test, &file->triggers, list) {
  457. if (test->cmd_ops->trigger_type == data->cmd_ops->trigger_type) {
  458. ret = -EEXIST;
  459. goto out;
  460. }
  461. }
  462. if (data->ops->init) {
  463. ret = data->ops->init(data->ops, data);
  464. if (ret < 0)
  465. goto out;
  466. }
  467. list_add_rcu(&data->list, &file->triggers);
  468. ret++;
  469. if (trace_event_trigger_enable_disable(file, 1) < 0) {
  470. list_del_rcu(&data->list);
  471. ret--;
  472. }
  473. update_cond_flag(file);
  474. out:
  475. return ret;
  476. }
  477. /**
  478. * unregister_trigger - Generic event_command @unreg implementation
  479. * @glob: The raw string used to register the trigger
  480. * @ops: The trigger ops associated with the trigger
  481. * @test: Trigger-specific data used to find the trigger to remove
  482. * @file: The trace_event_file associated with the event
  483. *
  484. * Common implementation for event trigger unregistration.
  485. *
  486. * Usually used directly as the @unreg method in event command
  487. * implementations.
  488. */
  489. static void unregister_trigger(char *glob, struct event_trigger_ops *ops,
  490. struct event_trigger_data *test,
  491. struct trace_event_file *file)
  492. {
  493. struct event_trigger_data *data;
  494. bool unregistered = false;
  495. list_for_each_entry_rcu(data, &file->triggers, list) {
  496. if (data->cmd_ops->trigger_type == test->cmd_ops->trigger_type) {
  497. unregistered = true;
  498. list_del_rcu(&data->list);
  499. update_cond_flag(file);
  500. trace_event_trigger_enable_disable(file, 0);
  501. break;
  502. }
  503. }
  504. if (unregistered && data->ops->free)
  505. data->ops->free(data->ops, data);
  506. }
  507. /**
  508. * event_trigger_callback - Generic event_command @func implementation
  509. * @cmd_ops: The command ops, used for trigger registration
  510. * @file: The trace_event_file associated with the event
  511. * @glob: The raw string used to register the trigger
  512. * @cmd: The cmd portion of the string used to register the trigger
  513. * @param: The params portion of the string used to register the trigger
  514. *
  515. * Common implementation for event command parsing and trigger
  516. * instantiation.
  517. *
  518. * Usually used directly as the @func method in event command
  519. * implementations.
  520. *
  521. * Return: 0 on success, errno otherwise
  522. */
  523. static int
  524. event_trigger_callback(struct event_command *cmd_ops,
  525. struct trace_event_file *file,
  526. char *glob, char *cmd, char *param)
  527. {
  528. struct event_trigger_data *trigger_data;
  529. struct event_trigger_ops *trigger_ops;
  530. char *trigger = NULL;
  531. char *number;
  532. int ret;
  533. /* separate the trigger from the filter (t:n [if filter]) */
  534. if (param && isdigit(param[0]))
  535. trigger = strsep(&param, " \t");
  536. trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
  537. ret = -ENOMEM;
  538. trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
  539. if (!trigger_data)
  540. goto out;
  541. trigger_data->count = -1;
  542. trigger_data->ops = trigger_ops;
  543. trigger_data->cmd_ops = cmd_ops;
  544. INIT_LIST_HEAD(&trigger_data->list);
  545. if (glob[0] == '!') {
  546. cmd_ops->unreg(glob+1, trigger_ops, trigger_data, file);
  547. kfree(trigger_data);
  548. ret = 0;
  549. goto out;
  550. }
  551. if (trigger) {
  552. number = strsep(&trigger, ":");
  553. ret = -EINVAL;
  554. if (!strlen(number))
  555. goto out_free;
  556. /*
  557. * We use the callback data field (which is a pointer)
  558. * as our counter.
  559. */
  560. ret = kstrtoul(number, 0, &trigger_data->count);
  561. if (ret)
  562. goto out_free;
  563. }
  564. if (!param) /* if param is non-empty, it's supposed to be a filter */
  565. goto out_reg;
  566. if (!cmd_ops->set_filter)
  567. goto out_reg;
  568. ret = cmd_ops->set_filter(param, trigger_data, file);
  569. if (ret < 0)
  570. goto out_free;
  571. out_reg:
  572. ret = cmd_ops->reg(glob, trigger_ops, trigger_data, file);
  573. /*
  574. * The above returns on success the # of functions enabled,
  575. * but if it didn't find any functions it returns zero.
  576. * Consider no functions a failure too.
  577. */
  578. if (!ret) {
  579. ret = -ENOENT;
  580. goto out_free;
  581. } else if (ret < 0)
  582. goto out_free;
  583. ret = 0;
  584. out:
  585. return ret;
  586. out_free:
  587. if (cmd_ops->set_filter)
  588. cmd_ops->set_filter(NULL, trigger_data, NULL);
  589. kfree(trigger_data);
  590. goto out;
  591. }
  592. /**
  593. * set_trigger_filter - Generic event_command @set_filter implementation
  594. * @filter_str: The filter string for the trigger, NULL to remove filter
  595. * @trigger_data: Trigger-specific data
  596. * @file: The trace_event_file associated with the event
  597. *
  598. * Common implementation for event command filter parsing and filter
  599. * instantiation.
  600. *
  601. * Usually used directly as the @set_filter method in event command
  602. * implementations.
  603. *
  604. * Also used to remove a filter (if filter_str = NULL).
  605. *
  606. * Return: 0 on success, errno otherwise
  607. */
  608. static int set_trigger_filter(char *filter_str,
  609. struct event_trigger_data *trigger_data,
  610. struct trace_event_file *file)
  611. {
  612. struct event_trigger_data *data = trigger_data;
  613. struct event_filter *filter = NULL, *tmp;
  614. int ret = -EINVAL;
  615. char *s;
  616. if (!filter_str) /* clear the current filter */
  617. goto assign;
  618. s = strsep(&filter_str, " \t");
  619. if (!strlen(s) || strcmp(s, "if") != 0)
  620. goto out;
  621. if (!filter_str)
  622. goto out;
  623. /* The filter is for the 'trigger' event, not the triggered event */
  624. ret = create_event_filter(file->event_call, filter_str, false, &filter);
  625. if (ret)
  626. goto out;
  627. assign:
  628. tmp = rcu_access_pointer(data->filter);
  629. rcu_assign_pointer(data->filter, filter);
  630. if (tmp) {
  631. /* Make sure the call is done with the filter */
  632. synchronize_sched();
  633. free_event_filter(tmp);
  634. }
  635. kfree(data->filter_str);
  636. data->filter_str = NULL;
  637. if (filter_str) {
  638. data->filter_str = kstrdup(filter_str, GFP_KERNEL);
  639. if (!data->filter_str) {
  640. free_event_filter(rcu_access_pointer(data->filter));
  641. data->filter = NULL;
  642. ret = -ENOMEM;
  643. }
  644. }
  645. out:
  646. return ret;
  647. }
  648. static void
  649. traceon_trigger(struct event_trigger_data *data)
  650. {
  651. if (tracing_is_on())
  652. return;
  653. tracing_on();
  654. }
  655. static void
  656. traceon_count_trigger(struct event_trigger_data *data)
  657. {
  658. if (tracing_is_on())
  659. return;
  660. if (!data->count)
  661. return;
  662. if (data->count != -1)
  663. (data->count)--;
  664. tracing_on();
  665. }
  666. static void
  667. traceoff_trigger(struct event_trigger_data *data)
  668. {
  669. if (!tracing_is_on())
  670. return;
  671. tracing_off();
  672. }
  673. static void
  674. traceoff_count_trigger(struct event_trigger_data *data)
  675. {
  676. if (!tracing_is_on())
  677. return;
  678. if (!data->count)
  679. return;
  680. if (data->count != -1)
  681. (data->count)--;
  682. tracing_off();
  683. }
  684. static int
  685. traceon_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
  686. struct event_trigger_data *data)
  687. {
  688. return event_trigger_print("traceon", m, (void *)data->count,
  689. data->filter_str);
  690. }
  691. static int
  692. traceoff_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
  693. struct event_trigger_data *data)
  694. {
  695. return event_trigger_print("traceoff", m, (void *)data->count,
  696. data->filter_str);
  697. }
  698. static struct event_trigger_ops traceon_trigger_ops = {
  699. .func = traceon_trigger,
  700. .print = traceon_trigger_print,
  701. .init = event_trigger_init,
  702. .free = event_trigger_free,
  703. };
  704. static struct event_trigger_ops traceon_count_trigger_ops = {
  705. .func = traceon_count_trigger,
  706. .print = traceon_trigger_print,
  707. .init = event_trigger_init,
  708. .free = event_trigger_free,
  709. };
  710. static struct event_trigger_ops traceoff_trigger_ops = {
  711. .func = traceoff_trigger,
  712. .print = traceoff_trigger_print,
  713. .init = event_trigger_init,
  714. .free = event_trigger_free,
  715. };
  716. static struct event_trigger_ops traceoff_count_trigger_ops = {
  717. .func = traceoff_count_trigger,
  718. .print = traceoff_trigger_print,
  719. .init = event_trigger_init,
  720. .free = event_trigger_free,
  721. };
  722. static struct event_trigger_ops *
  723. onoff_get_trigger_ops(char *cmd, char *param)
  724. {
  725. struct event_trigger_ops *ops;
  726. /* we register both traceon and traceoff to this callback */
  727. if (strcmp(cmd, "traceon") == 0)
  728. ops = param ? &traceon_count_trigger_ops :
  729. &traceon_trigger_ops;
  730. else
  731. ops = param ? &traceoff_count_trigger_ops :
  732. &traceoff_trigger_ops;
  733. return ops;
  734. }
  735. static struct event_command trigger_traceon_cmd = {
  736. .name = "traceon",
  737. .trigger_type = ETT_TRACE_ONOFF,
  738. .func = event_trigger_callback,
  739. .reg = register_trigger,
  740. .unreg = unregister_trigger,
  741. .get_trigger_ops = onoff_get_trigger_ops,
  742. .set_filter = set_trigger_filter,
  743. };
  744. static struct event_command trigger_traceoff_cmd = {
  745. .name = "traceoff",
  746. .trigger_type = ETT_TRACE_ONOFF,
  747. .func = event_trigger_callback,
  748. .reg = register_trigger,
  749. .unreg = unregister_trigger,
  750. .get_trigger_ops = onoff_get_trigger_ops,
  751. .set_filter = set_trigger_filter,
  752. };
  753. #ifdef CONFIG_TRACER_SNAPSHOT
  754. static void
  755. snapshot_trigger(struct event_trigger_data *data)
  756. {
  757. tracing_snapshot();
  758. }
  759. static void
  760. snapshot_count_trigger(struct event_trigger_data *data)
  761. {
  762. if (!data->count)
  763. return;
  764. if (data->count != -1)
  765. (data->count)--;
  766. snapshot_trigger(data);
  767. }
  768. static int
  769. register_snapshot_trigger(char *glob, struct event_trigger_ops *ops,
  770. struct event_trigger_data *data,
  771. struct trace_event_file *file)
  772. {
  773. int ret = register_trigger(glob, ops, data, file);
  774. if (ret > 0 && tracing_alloc_snapshot() != 0) {
  775. unregister_trigger(glob, ops, data, file);
  776. ret = 0;
  777. }
  778. return ret;
  779. }
  780. static int
  781. snapshot_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
  782. struct event_trigger_data *data)
  783. {
  784. return event_trigger_print("snapshot", m, (void *)data->count,
  785. data->filter_str);
  786. }
  787. static struct event_trigger_ops snapshot_trigger_ops = {
  788. .func = snapshot_trigger,
  789. .print = snapshot_trigger_print,
  790. .init = event_trigger_init,
  791. .free = event_trigger_free,
  792. };
  793. static struct event_trigger_ops snapshot_count_trigger_ops = {
  794. .func = snapshot_count_trigger,
  795. .print = snapshot_trigger_print,
  796. .init = event_trigger_init,
  797. .free = event_trigger_free,
  798. };
  799. static struct event_trigger_ops *
  800. snapshot_get_trigger_ops(char *cmd, char *param)
  801. {
  802. return param ? &snapshot_count_trigger_ops : &snapshot_trigger_ops;
  803. }
  804. static struct event_command trigger_snapshot_cmd = {
  805. .name = "snapshot",
  806. .trigger_type = ETT_SNAPSHOT,
  807. .func = event_trigger_callback,
  808. .reg = register_snapshot_trigger,
  809. .unreg = unregister_trigger,
  810. .get_trigger_ops = snapshot_get_trigger_ops,
  811. .set_filter = set_trigger_filter,
  812. };
  813. static __init int register_trigger_snapshot_cmd(void)
  814. {
  815. int ret;
  816. ret = register_event_command(&trigger_snapshot_cmd);
  817. WARN_ON(ret < 0);
  818. return ret;
  819. }
  820. #else
  821. static __init int register_trigger_snapshot_cmd(void) { return 0; }
  822. #endif /* CONFIG_TRACER_SNAPSHOT */
  823. #ifdef CONFIG_STACKTRACE
  824. /*
  825. * Skip 3:
  826. * stacktrace_trigger()
  827. * event_triggers_post_call()
  828. * trace_event_raw_event_xxx()
  829. */
  830. #define STACK_SKIP 3
  831. static void
  832. stacktrace_trigger(struct event_trigger_data *data)
  833. {
  834. trace_dump_stack(STACK_SKIP);
  835. }
  836. static void
  837. stacktrace_count_trigger(struct event_trigger_data *data)
  838. {
  839. if (!data->count)
  840. return;
  841. if (data->count != -1)
  842. (data->count)--;
  843. stacktrace_trigger(data);
  844. }
  845. static int
  846. stacktrace_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
  847. struct event_trigger_data *data)
  848. {
  849. return event_trigger_print("stacktrace", m, (void *)data->count,
  850. data->filter_str);
  851. }
  852. static struct event_trigger_ops stacktrace_trigger_ops = {
  853. .func = stacktrace_trigger,
  854. .print = stacktrace_trigger_print,
  855. .init = event_trigger_init,
  856. .free = event_trigger_free,
  857. };
  858. static struct event_trigger_ops stacktrace_count_trigger_ops = {
  859. .func = stacktrace_count_trigger,
  860. .print = stacktrace_trigger_print,
  861. .init = event_trigger_init,
  862. .free = event_trigger_free,
  863. };
  864. static struct event_trigger_ops *
  865. stacktrace_get_trigger_ops(char *cmd, char *param)
  866. {
  867. return param ? &stacktrace_count_trigger_ops : &stacktrace_trigger_ops;
  868. }
  869. static struct event_command trigger_stacktrace_cmd = {
  870. .name = "stacktrace",
  871. .trigger_type = ETT_STACKTRACE,
  872. .post_trigger = true,
  873. .func = event_trigger_callback,
  874. .reg = register_trigger,
  875. .unreg = unregister_trigger,
  876. .get_trigger_ops = stacktrace_get_trigger_ops,
  877. .set_filter = set_trigger_filter,
  878. };
  879. static __init int register_trigger_stacktrace_cmd(void)
  880. {
  881. int ret;
  882. ret = register_event_command(&trigger_stacktrace_cmd);
  883. WARN_ON(ret < 0);
  884. return ret;
  885. }
  886. #else
  887. static __init int register_trigger_stacktrace_cmd(void) { return 0; }
  888. #endif /* CONFIG_STACKTRACE */
  889. static __init void unregister_trigger_traceon_traceoff_cmds(void)
  890. {
  891. unregister_event_command(&trigger_traceon_cmd);
  892. unregister_event_command(&trigger_traceoff_cmd);
  893. }
  894. /* Avoid typos */
  895. #define ENABLE_EVENT_STR "enable_event"
  896. #define DISABLE_EVENT_STR "disable_event"
  897. struct enable_trigger_data {
  898. struct trace_event_file *file;
  899. bool enable;
  900. };
  901. static void
  902. event_enable_trigger(struct event_trigger_data *data)
  903. {
  904. struct enable_trigger_data *enable_data = data->private_data;
  905. if (enable_data->enable)
  906. clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags);
  907. else
  908. set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags);
  909. }
  910. static void
  911. event_enable_count_trigger(struct event_trigger_data *data)
  912. {
  913. struct enable_trigger_data *enable_data = data->private_data;
  914. if (!data->count)
  915. return;
  916. /* Skip if the event is in a state we want to switch to */
  917. if (enable_data->enable == !(enable_data->file->flags & EVENT_FILE_FL_SOFT_DISABLED))
  918. return;
  919. if (data->count != -1)
  920. (data->count)--;
  921. event_enable_trigger(data);
  922. }
  923. static int
  924. event_enable_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
  925. struct event_trigger_data *data)
  926. {
  927. struct enable_trigger_data *enable_data = data->private_data;
  928. seq_printf(m, "%s:%s:%s",
  929. enable_data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR,
  930. enable_data->file->event_call->class->system,
  931. trace_event_name(enable_data->file->event_call));
  932. if (data->count == -1)
  933. seq_puts(m, ":unlimited");
  934. else
  935. seq_printf(m, ":count=%ld", data->count);
  936. if (data->filter_str)
  937. seq_printf(m, " if %s\n", data->filter_str);
  938. else
  939. seq_putc(m, '\n');
  940. return 0;
  941. }
  942. static void
  943. event_enable_trigger_free(struct event_trigger_ops *ops,
  944. struct event_trigger_data *data)
  945. {
  946. struct enable_trigger_data *enable_data = data->private_data;
  947. if (WARN_ON_ONCE(data->ref <= 0))
  948. return;
  949. data->ref--;
  950. if (!data->ref) {
  951. /* Remove the SOFT_MODE flag */
  952. trace_event_enable_disable(enable_data->file, 0, 1);
  953. module_put(enable_data->file->event_call->mod);
  954. trigger_data_free(data);
  955. kfree(enable_data);
  956. }
  957. }
  958. static struct event_trigger_ops event_enable_trigger_ops = {
  959. .func = event_enable_trigger,
  960. .print = event_enable_trigger_print,
  961. .init = event_trigger_init,
  962. .free = event_enable_trigger_free,
  963. };
  964. static struct event_trigger_ops event_enable_count_trigger_ops = {
  965. .func = event_enable_count_trigger,
  966. .print = event_enable_trigger_print,
  967. .init = event_trigger_init,
  968. .free = event_enable_trigger_free,
  969. };
  970. static struct event_trigger_ops event_disable_trigger_ops = {
  971. .func = event_enable_trigger,
  972. .print = event_enable_trigger_print,
  973. .init = event_trigger_init,
  974. .free = event_enable_trigger_free,
  975. };
  976. static struct event_trigger_ops event_disable_count_trigger_ops = {
  977. .func = event_enable_count_trigger,
  978. .print = event_enable_trigger_print,
  979. .init = event_trigger_init,
  980. .free = event_enable_trigger_free,
  981. };
  982. static int
  983. event_enable_trigger_func(struct event_command *cmd_ops,
  984. struct trace_event_file *file,
  985. char *glob, char *cmd, char *param)
  986. {
  987. struct trace_event_file *event_enable_file;
  988. struct enable_trigger_data *enable_data;
  989. struct event_trigger_data *trigger_data;
  990. struct event_trigger_ops *trigger_ops;
  991. struct trace_array *tr = file->tr;
  992. const char *system;
  993. const char *event;
  994. char *trigger;
  995. char *number;
  996. bool enable;
  997. int ret;
  998. if (!param)
  999. return -EINVAL;
  1000. /* separate the trigger from the filter (s:e:n [if filter]) */
  1001. trigger = strsep(&param, " \t");
  1002. if (!trigger)
  1003. return -EINVAL;
  1004. system = strsep(&trigger, ":");
  1005. if (!trigger)
  1006. return -EINVAL;
  1007. event = strsep(&trigger, ":");
  1008. ret = -EINVAL;
  1009. event_enable_file = find_event_file(tr, system, event);
  1010. if (!event_enable_file)
  1011. goto out;
  1012. enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
  1013. trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
  1014. ret = -ENOMEM;
  1015. trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
  1016. if (!trigger_data)
  1017. goto out;
  1018. enable_data = kzalloc(sizeof(*enable_data), GFP_KERNEL);
  1019. if (!enable_data) {
  1020. kfree(trigger_data);
  1021. goto out;
  1022. }
  1023. trigger_data->count = -1;
  1024. trigger_data->ops = trigger_ops;
  1025. trigger_data->cmd_ops = cmd_ops;
  1026. INIT_LIST_HEAD(&trigger_data->list);
  1027. RCU_INIT_POINTER(trigger_data->filter, NULL);
  1028. enable_data->enable = enable;
  1029. enable_data->file = event_enable_file;
  1030. trigger_data->private_data = enable_data;
  1031. if (glob[0] == '!') {
  1032. cmd_ops->unreg(glob+1, trigger_ops, trigger_data, file);
  1033. kfree(trigger_data);
  1034. kfree(enable_data);
  1035. ret = 0;
  1036. goto out;
  1037. }
  1038. if (trigger) {
  1039. number = strsep(&trigger, ":");
  1040. ret = -EINVAL;
  1041. if (!strlen(number))
  1042. goto out_free;
  1043. /*
  1044. * We use the callback data field (which is a pointer)
  1045. * as our counter.
  1046. */
  1047. ret = kstrtoul(number, 0, &trigger_data->count);
  1048. if (ret)
  1049. goto out_free;
  1050. }
  1051. if (!param) /* if param is non-empty, it's supposed to be a filter */
  1052. goto out_reg;
  1053. if (!cmd_ops->set_filter)
  1054. goto out_reg;
  1055. ret = cmd_ops->set_filter(param, trigger_data, file);
  1056. if (ret < 0)
  1057. goto out_free;
  1058. out_reg:
  1059. /* Don't let event modules unload while probe registered */
  1060. ret = try_module_get(event_enable_file->event_call->mod);
  1061. if (!ret) {
  1062. ret = -EBUSY;
  1063. goto out_free;
  1064. }
  1065. ret = trace_event_enable_disable(event_enable_file, 1, 1);
  1066. if (ret < 0)
  1067. goto out_put;
  1068. ret = cmd_ops->reg(glob, trigger_ops, trigger_data, file);
  1069. /*
  1070. * The above returns on success the # of functions enabled,
  1071. * but if it didn't find any functions it returns zero.
  1072. * Consider no functions a failure too.
  1073. */
  1074. if (!ret) {
  1075. ret = -ENOENT;
  1076. goto out_disable;
  1077. } else if (ret < 0)
  1078. goto out_disable;
  1079. /* Just return zero, not the number of enabled functions */
  1080. ret = 0;
  1081. out:
  1082. return ret;
  1083. out_disable:
  1084. trace_event_enable_disable(event_enable_file, 0, 1);
  1085. out_put:
  1086. module_put(event_enable_file->event_call->mod);
  1087. out_free:
  1088. if (cmd_ops->set_filter)
  1089. cmd_ops->set_filter(NULL, trigger_data, NULL);
  1090. kfree(trigger_data);
  1091. kfree(enable_data);
  1092. goto out;
  1093. }
  1094. static int event_enable_register_trigger(char *glob,
  1095. struct event_trigger_ops *ops,
  1096. struct event_trigger_data *data,
  1097. struct trace_event_file *file)
  1098. {
  1099. struct enable_trigger_data *enable_data = data->private_data;
  1100. struct enable_trigger_data *test_enable_data;
  1101. struct event_trigger_data *test;
  1102. int ret = 0;
  1103. list_for_each_entry_rcu(test, &file->triggers, list) {
  1104. test_enable_data = test->private_data;
  1105. if (test_enable_data &&
  1106. (test_enable_data->file == enable_data->file)) {
  1107. ret = -EEXIST;
  1108. goto out;
  1109. }
  1110. }
  1111. if (data->ops->init) {
  1112. ret = data->ops->init(data->ops, data);
  1113. if (ret < 0)
  1114. goto out;
  1115. }
  1116. list_add_rcu(&data->list, &file->triggers);
  1117. ret++;
  1118. if (trace_event_trigger_enable_disable(file, 1) < 0) {
  1119. list_del_rcu(&data->list);
  1120. ret--;
  1121. }
  1122. update_cond_flag(file);
  1123. out:
  1124. return ret;
  1125. }
  1126. static void event_enable_unregister_trigger(char *glob,
  1127. struct event_trigger_ops *ops,
  1128. struct event_trigger_data *test,
  1129. struct trace_event_file *file)
  1130. {
  1131. struct enable_trigger_data *test_enable_data = test->private_data;
  1132. struct enable_trigger_data *enable_data;
  1133. struct event_trigger_data *data;
  1134. bool unregistered = false;
  1135. list_for_each_entry_rcu(data, &file->triggers, list) {
  1136. enable_data = data->private_data;
  1137. if (enable_data &&
  1138. (enable_data->file == test_enable_data->file)) {
  1139. unregistered = true;
  1140. list_del_rcu(&data->list);
  1141. update_cond_flag(file);
  1142. trace_event_trigger_enable_disable(file, 0);
  1143. break;
  1144. }
  1145. }
  1146. if (unregistered && data->ops->free)
  1147. data->ops->free(data->ops, data);
  1148. }
  1149. static struct event_trigger_ops *
  1150. event_enable_get_trigger_ops(char *cmd, char *param)
  1151. {
  1152. struct event_trigger_ops *ops;
  1153. bool enable;
  1154. enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
  1155. if (enable)
  1156. ops = param ? &event_enable_count_trigger_ops :
  1157. &event_enable_trigger_ops;
  1158. else
  1159. ops = param ? &event_disable_count_trigger_ops :
  1160. &event_disable_trigger_ops;
  1161. return ops;
  1162. }
  1163. static struct event_command trigger_enable_cmd = {
  1164. .name = ENABLE_EVENT_STR,
  1165. .trigger_type = ETT_EVENT_ENABLE,
  1166. .func = event_enable_trigger_func,
  1167. .reg = event_enable_register_trigger,
  1168. .unreg = event_enable_unregister_trigger,
  1169. .get_trigger_ops = event_enable_get_trigger_ops,
  1170. .set_filter = set_trigger_filter,
  1171. };
  1172. static struct event_command trigger_disable_cmd = {
  1173. .name = DISABLE_EVENT_STR,
  1174. .trigger_type = ETT_EVENT_ENABLE,
  1175. .func = event_enable_trigger_func,
  1176. .reg = event_enable_register_trigger,
  1177. .unreg = event_enable_unregister_trigger,
  1178. .get_trigger_ops = event_enable_get_trigger_ops,
  1179. .set_filter = set_trigger_filter,
  1180. };
  1181. static __init void unregister_trigger_enable_disable_cmds(void)
  1182. {
  1183. unregister_event_command(&trigger_enable_cmd);
  1184. unregister_event_command(&trigger_disable_cmd);
  1185. }
  1186. static __init int register_trigger_enable_disable_cmds(void)
  1187. {
  1188. int ret;
  1189. ret = register_event_command(&trigger_enable_cmd);
  1190. if (WARN_ON(ret < 0))
  1191. return ret;
  1192. ret = register_event_command(&trigger_disable_cmd);
  1193. if (WARN_ON(ret < 0))
  1194. unregister_trigger_enable_disable_cmds();
  1195. return ret;
  1196. }
  1197. static __init int register_trigger_traceon_traceoff_cmds(void)
  1198. {
  1199. int ret;
  1200. ret = register_event_command(&trigger_traceon_cmd);
  1201. if (WARN_ON(ret < 0))
  1202. return ret;
  1203. ret = register_event_command(&trigger_traceoff_cmd);
  1204. if (WARN_ON(ret < 0))
  1205. unregister_trigger_traceon_traceoff_cmds();
  1206. return ret;
  1207. }
  1208. __init int register_trigger_cmds(void)
  1209. {
  1210. register_trigger_traceon_traceoff_cmds();
  1211. register_trigger_snapshot_cmd();
  1212. register_trigger_stacktrace_cmd();
  1213. register_trigger_enable_disable_cmds();
  1214. return 0;
  1215. }