From 1bbb5b2dfb4634c1ed19d006a538101fd69a30de Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 2 Nov 2021 15:04:08 -0400 Subject: [PATCH] Refactoring: event notifier create: use enablers Signed-off-by: Mathieu Desnoyers Change-Id: Ib75cc8d0336f74af96455fd04c0a967db9013633 --- include/lttng/events-internal.h | 25 +++++------- src/lttng-abi.c | 29 +++++++------- src/lttng-events.c | 68 +++++++++++++++------------------ src/lttng-syscalls.c | 35 ++++++++++------- 4 files changed, 77 insertions(+), 80 deletions(-) diff --git a/include/lttng/events-internal.h b/include/lttng/events-internal.h index 873adc31..30f56e15 100644 --- a/include/lttng/events-internal.h +++ b/include/lttng/events-internal.h @@ -250,6 +250,7 @@ struct lttng_event_notifier_enabler { struct lttng_event_enabler_common parent; uint64_t error_counter_index; struct list_head node; /* List of event_notifier enablers */ + bool published; /* published in group list. */ struct lttng_event_notifier_group *group; /* head list of struct lttng_kernel_bytecode_node */ @@ -780,9 +781,11 @@ void lttng_event_enabler_session_add(struct lttng_kernel_session *session, struct lttng_event_recorder_enabler *event_enabler); struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( - struct lttng_event_notifier_group *event_notifier_group, enum lttng_enabler_format_type format_type, - struct lttng_kernel_abi_event_notifier *event_notifier_param); + struct lttng_kernel_abi_event_notifier *event_notifier_param, + struct lttng_event_notifier_group *event_notifier_group); +void lttng_event_notifier_enabler_group_add(struct lttng_event_notifier_group *event_notifier_group, + struct lttng_event_notifier_enabler *event_notifier_enabler); int lttng_event_notifier_enabler_attach_capture_bytecode( struct lttng_event_notifier_enabler *event_notifier_enabler, struct lttng_kernel_abi_capture_bytecode __user *bytecode); @@ -1015,20 +1018,10 @@ struct lttng_kernel_event_recorder *lttng_event_compat_old_create(struct lttng_k struct lttng_kernel_abi_old_event *old_event_param, const struct lttng_kernel_event_desc *internal_desc); -struct lttng_kernel_event_notifier *lttng_event_notifier_create( - const struct lttng_kernel_event_desc *event_notifier_desc, - uint64_t id, - uint64_t error_counter_idx, - struct lttng_event_notifier_group *event_notifier_group, - struct lttng_kernel_abi_event_notifier *event_notifier_param, - enum lttng_kernel_abi_instrumentation itype); -struct lttng_kernel_event_notifier *_lttng_event_notifier_create( - const struct lttng_kernel_event_desc *event_notifier_desc, - uint64_t id, - uint64_t error_counter_idx, - struct lttng_event_notifier_group *event_notifier_group, - struct lttng_kernel_abi_event_notifier *event_notifier_param, - enum lttng_kernel_abi_instrumentation itype); +struct lttng_kernel_event_notifier *lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler, + const struct lttng_kernel_event_desc *event_notifier_desc); +struct lttng_kernel_event_notifier *_lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler, + const struct lttng_kernel_event_desc *event_notifier_desc); int lttng_channel_enable(struct lttng_kernel_channel_common *channel); int lttng_channel_disable(struct lttng_kernel_channel_common *channel); diff --git a/src/lttng-abi.c b/src/lttng-abi.c index 63cce39c..1f093981 100644 --- a/src/lttng-abi.c +++ b/src/lttng-abi.c @@ -2132,15 +2132,17 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, * we create the special star globbing enabler. */ enabler = lttng_event_notifier_enabler_create( - event_notifier_group, LTTNG_ENABLER_FORMAT_STAR_GLOB, - event_notifier_param); + event_notifier_param, + event_notifier_group); } else { enabler = lttng_event_notifier_enabler_create( - event_notifier_group, LTTNG_ENABLER_FORMAT_NAME, - event_notifier_param); + event_notifier_param, + event_notifier_group); } + if (enabler) + lttng_event_notifier_enabler_group_add(event_notifier_group, enabler); priv = enabler; break; } @@ -2152,18 +2154,17 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, case LTTNG_KERNEL_ABI_UPROBE: { struct lttng_kernel_event_notifier *event_notifier; + struct lttng_event_notifier_enabler *event_notifier_enabler; - /* - * We tolerate no failure path after event notifier creation. - * It will stay invariant for the rest of the session. - */ - event_notifier = lttng_event_notifier_create(NULL, - event_notifier_param->event.token, - event_notifier_param->error_counter_index, - event_notifier_group, - event_notifier_param, - event_notifier_param->event.instrumentation); + event_notifier_enabler = lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME, + event_notifier_param, event_notifier_group); + if (!event_notifier_enabler) { + ret = -ENOMEM; + goto event_notifier_error; + } + event_notifier = lttng_event_notifier_create(event_notifier_enabler, NULL); WARN_ON_ONCE(!event_notifier); + lttng_event_enabler_destroy(&event_notifier_enabler->parent); if (IS_ERR(event_notifier)) { ret = PTR_ERR(event_notifier); goto event_notifier_error; diff --git a/src/lttng-events.c b/src/lttng-events.c index 9f9e8947..78ee916f 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -1151,13 +1151,13 @@ full: return ERR_PTR(ret); } -struct lttng_kernel_event_notifier *_lttng_event_notifier_create( - const struct lttng_kernel_event_desc *event_desc, - uint64_t token, uint64_t error_counter_index, - struct lttng_event_notifier_group *event_notifier_group, - struct lttng_kernel_abi_event_notifier *event_notifier_param, - enum lttng_kernel_abi_instrumentation itype) +struct lttng_kernel_event_notifier *_lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler, + const struct lttng_kernel_event_desc *event_desc) { + struct lttng_event_notifier_group *event_notifier_group = event_enabler->group; + struct lttng_kernel_abi_event *event_param = &event_enabler->parent.event_param; + uint64_t token = event_enabler->parent.user_token; + enum lttng_kernel_abi_instrumentation itype = event_param->instrumentation; struct lttng_kernel_event_notifier *event_notifier; struct lttng_kernel_event_notifier_private *event_notifier_priv; struct lttng_counter *error_counter; @@ -1175,7 +1175,7 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create( case LTTNG_KERNEL_ABI_UPROBE: lttng_fallthrough; case LTTNG_KERNEL_ABI_SYSCALL: - event_name = event_notifier_param->event.name; + event_name = event_param->name; break; case LTTNG_KERNEL_ABI_KRETPROBE: @@ -1220,8 +1220,8 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create( event_notifier->parent.type = LTTNG_KERNEL_EVENT_TYPE_NOTIFIER; event_notifier->priv->group = event_notifier_group; - event_notifier->priv->parent.user_token = token; - event_notifier->priv->error_counter_index = error_counter_index; + event_notifier->priv->parent.user_token = event_enabler->parent.user_token; + event_notifier->priv->error_counter_index = event_enabler->error_counter_index; event_notifier->priv->num_captures = 0; event_notifier->priv->parent.instrumentation = itype; event_notifier->notification_send = lttng_event_notifier_notification_send; @@ -1256,10 +1256,10 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create( * registration. */ smp_wmb(); - ret = lttng_kprobes_register_event(event_notifier_param->event.u.kprobe.symbol_name, - event_notifier_param->event.u.kprobe.symbol_name, - event_notifier_param->event.u.kprobe.offset, - event_notifier_param->event.u.kprobe.addr, + ret = lttng_kprobes_register_event(event_param->u.kprobe.symbol_name, + event_param->u.kprobe.symbol_name, + event_param->u.kprobe.offset, + event_param->u.kprobe.addr, &event_notifier->parent); if (ret) { ret = -EINVAL; @@ -1277,7 +1277,7 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create( event_notifier->parent.enabled = 0; event_notifier->priv->parent.registered = 0; event_notifier->priv->parent.desc = event_desc; - switch (event_notifier_param->event.u.syscall.entryexit) { + switch (event_param->u.syscall.entryexit) { case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT: ret = -EINVAL; goto register_error; @@ -1288,7 +1288,7 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create( event_notifier->priv->parent.u.syscall.entryexit = LTTNG_SYSCALL_EXIT; break; } - switch (event_notifier_param->event.u.syscall.abi) { + switch (event_param->u.syscall.abi) { case LTTNG_KERNEL_ABI_SYSCALL_ABI_ALL: ret = -EINVAL; goto register_error; @@ -1320,8 +1320,8 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create( */ smp_wmb(); - ret = lttng_uprobes_register_event(event_notifier_param->event.name, - event_notifier_param->event.u.uprobe.fd, + ret = lttng_uprobes_register_event(event_param->name, + event_param->u.uprobe.fd, &event_notifier->parent); if (ret) goto register_error; @@ -1418,19 +1418,13 @@ struct lttng_kernel_event_recorder *lttng_kernel_event_recorder_create(struct lt return event; } -struct lttng_kernel_event_notifier *lttng_event_notifier_create( - const struct lttng_kernel_event_desc *event_desc, - uint64_t id, uint64_t error_counter_index, - struct lttng_event_notifier_group *event_notifier_group, - struct lttng_kernel_abi_event_notifier *event_notifier_param, - enum lttng_kernel_abi_instrumentation itype) +struct lttng_kernel_event_notifier *lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler, + const struct lttng_kernel_event_desc *event_desc) { struct lttng_kernel_event_notifier *event_notifier; mutex_lock(&sessions_mutex); - event_notifier = _lttng_event_notifier_create(event_desc, id, - error_counter_index, event_notifier_group, - event_notifier_param, itype); + event_notifier = _lttng_event_notifier_create(event_enabler, event_desc); mutex_unlock(&sessions_mutex); return event_notifier; } @@ -2156,11 +2150,7 @@ void lttng_create_tracepoint_event_notifier_if_missing(struct lttng_event_notifi /* * We need to create a event_notifier for this event probe. */ - event_notifier = _lttng_event_notifier_create(desc, - event_notifier_enabler->parent.user_token, - event_notifier_enabler->error_counter_index, - event_notifier_group, NULL, - LTTNG_KERNEL_ABI_TRACEPOINT); + event_notifier = _lttng_event_notifier_create(event_notifier_enabler, desc); if (IS_ERR(event_notifier)) { printk(KERN_INFO "Unable to create event_notifier %s\n", probe_desc->event_desc[i]->event_name); @@ -2545,8 +2535,9 @@ void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enable struct lttng_event_notifier_enabler *event_notifier_enabler = container_of(event_enabler, struct lttng_event_notifier_enabler, parent); - list_del(&event_notifier_enabler->node); lttng_enabler_destroy(event_enabler); + if (event_notifier_enabler->published) + list_del(&event_notifier_enabler->node); kfree(event_notifier_enabler); break; } @@ -2556,9 +2547,9 @@ void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enable } struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( - struct lttng_event_notifier_group *event_notifier_group, enum lttng_enabler_format_type format_type, - struct lttng_kernel_abi_event_notifier *event_notifier_param) + struct lttng_kernel_abi_event_notifier *event_notifier_param, + struct lttng_event_notifier_group *event_notifier_group) { struct lttng_event_notifier_enabler *event_notifier_enabler; @@ -2580,14 +2571,17 @@ struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( event_notifier_enabler->parent.enabled = 0; event_notifier_enabler->parent.user_token = event_notifier_param->event.token; event_notifier_enabler->group = event_notifier_group; + return event_notifier_enabler; +} +void lttng_event_notifier_enabler_group_add(struct lttng_event_notifier_group *event_notifier_group, + struct lttng_event_notifier_enabler *event_notifier_enabler) +{ mutex_lock(&sessions_mutex); list_add(&event_notifier_enabler->node, &event_notifier_enabler->group->enablers_head); + event_notifier_enabler->published = true; lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group); - mutex_unlock(&sessions_mutex); - - return event_notifier_enabler; } int lttng_event_notifier_enabler_enable( diff --git a/src/lttng-syscalls.c b/src/lttng-syscalls.c index ff14dbbb..360f12b4 100644 --- a/src/lttng-syscalls.c +++ b/src/lttng-syscalls.c @@ -898,12 +898,16 @@ int create_unknown_event_notifier( event_notifier_param.event.name[LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1] = '\0'; event_notifier_param.event.instrumentation = LTTNG_KERNEL_ABI_SYSCALL; + event_notifier_param.event.token = user_token; event_notifier_param.event.u.syscall.abi = abi; event_notifier_param.event.u.syscall.entryexit = entryexit; + event_notifier_param.error_counter_index = error_counter_index; - event_notifier = _lttng_event_notifier_create(desc, user_token, - error_counter_index, group, &event_notifier_param, - event_notifier_param.event.instrumentation); + event_notifier_enabler = lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME, + &event_notifier_param, group); + WARN_ON_ONCE(!event_notifier_enabler); + event_notifier = _lttng_event_notifier_create(event_notifier_enabler, desc); + lttng_event_enabler_destroy(&event_notifier_enabler->parent); if (IS_ERR(event_notifier)) { printk(KERN_INFO "Unable to create unknown notifier %s\n", desc->event_name); @@ -918,19 +922,20 @@ end: } static int create_matching_event_notifiers( - struct lttng_event_notifier_enabler *event_notifier_enabler, + struct lttng_event_notifier_enabler *syscall_event_notifier_enabler, const struct trace_syscall_entry *table, size_t table_len, enum sc_type type) { - struct lttng_event_notifier_group *group = event_notifier_enabler->group; + struct lttng_event_notifier_group *group = syscall_event_notifier_enabler->group; const struct lttng_kernel_event_desc *desc; - uint64_t user_token = event_notifier_enabler->parent.user_token; - uint64_t error_counter_index = event_notifier_enabler->error_counter_index; + uint64_t user_token = syscall_event_notifier_enabler->parent.user_token; + uint64_t error_counter_index = syscall_event_notifier_enabler->error_counter_index; unsigned int i; int ret = 0; /* iterate over all syscall and create event_notifier that match */ for (i = 0; i < table_len; i++) { + struct lttng_event_notifier_enabler *event_notifier_enabler; struct lttng_kernel_event_notifier_private *event_notifier_priv; struct lttng_kernel_event_notifier *event_notifier; struct lttng_kernel_abi_event_notifier event_notifier_param; @@ -944,7 +949,7 @@ static int create_matching_event_notifiers( } if (!lttng_desc_match_enabler(desc, - lttng_event_notifier_enabler_as_enabler(event_notifier_enabler))) + lttng_event_notifier_enabler_as_enabler(syscall_event_notifier_enabler))) continue; /* @@ -954,7 +959,7 @@ static int create_matching_event_notifiers( LTTNG_EVENT_HT_SIZE, desc->event_name); lttng_hlist_for_each_entry(event_notifier_priv, head, hlist) { if (event_notifier_priv->parent.desc == desc - && event_notifier_priv->parent.user_token == event_notifier_enabler->parent.user_token) + && event_notifier_priv->parent.user_token == syscall_event_notifier_enabler->parent.user_token) found = 1; } if (found) @@ -983,10 +988,14 @@ static int create_matching_event_notifiers( LTTNG_KERNEL_ABI_SYM_NAME_LEN - strlen(event_notifier_param.event.name) - 1); event_notifier_param.event.name[LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1] = '\0'; event_notifier_param.event.instrumentation = LTTNG_KERNEL_ABI_SYSCALL; - - event_notifier = _lttng_event_notifier_create(desc, user_token, - error_counter_index, group, &event_notifier_param, - event_notifier_param.event.instrumentation); + event_notifier_param.event.token = user_token; + event_notifier_param.error_counter_index = error_counter_index; + + event_notifier_enabler = lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME, + &event_notifier_param, group); + WARN_ON_ONCE(!event_notifier_enabler); + event_notifier = _lttng_event_notifier_create(event_notifier_enabler, desc); + lttng_event_enabler_destroy(&event_notifier_enabler->parent); if (IS_ERR(event_notifier)) { printk(KERN_INFO "Unable to create event_notifier %s\n", desc->event_name); -- 2.34.1