From: Mathieu Desnoyers Date: Tue, 2 Nov 2021 16:46:48 +0000 (-0400) Subject: Refactoring: kprobes: combine common code between recorder and notifier X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6a35e5bd38fb1a47f57281d349218c7e4aae1da1;p=lttng-modules.git Refactoring: kprobes: combine common code between recorder and notifier Signed-off-by: Mathieu Desnoyers Change-Id: Iea2cf795c5409b0f5dadbadccb9cb2b4cd37acfc --- diff --git a/include/lttng/events-internal.h b/include/lttng/events-internal.h index d72502c9..c46f2b6c 100644 --- a/include/lttng/events-internal.h +++ b/include/lttng/events-internal.h @@ -865,52 +865,27 @@ int lttng_kprobes_register_event(const char *name, const char *symbol_name, uint64_t offset, uint64_t addr, - struct lttng_kernel_event_recorder *event); -void lttng_kprobes_unregister_event(struct lttng_kernel_event_recorder *event); -void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_recorder *event); -int lttng_kprobes_register_event_notifier(const char *symbol_name, - uint64_t offset, - uint64_t addr, - struct lttng_kernel_event_notifier *event_notifier); -void lttng_kprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier); -void lttng_kprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier); + struct lttng_kernel_event_common *event); +void lttng_kprobes_unregister_event(struct lttng_kernel_event_common *event); +void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common *event); #else static inline int lttng_kprobes_register_event(const char *name, const char *symbol_name, uint64_t offset, uint64_t addr, - struct lttng_kernel_event_recorder *event) -{ - return -ENOSYS; -} - -static inline -void lttng_kprobes_unregister_event(struct lttng_kernel_event_recorder *event) -{ -} - -static inline -void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_recorder *event) -{ -} - -static inline -int lttng_kprobes_register_event_notifier(const char *symbol_name, - uint64_t offset, - uint64_t addr, - struct lttng_kernel_event_notifier *event_notifier) + struct lttng_kernel_event_common *event) { return -ENOSYS; } static inline -void lttng_kprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier) +void lttng_kprobes_unregister_event(struct lttng_kernel_event_common *event) { } static inline -void lttng_kprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier) +void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common *event) { } #endif diff --git a/src/lttng-events.c b/src/lttng-events.c index d5f8314c..92af4c90 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -981,7 +981,7 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l event_param->u.kprobe.symbol_name, event_param->u.kprobe.offset, event_param->u.kprobe.addr, - event_recorder); + &event_recorder->parent); if (ret) { ret = -EINVAL; goto register_error; @@ -1257,11 +1257,11 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create( * registration. */ smp_wmb(); - ret = lttng_kprobes_register_event_notifier( + 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, - event_notifier); + &event_notifier->parent); if (ret) { ret = -EINVAL; goto register_error; @@ -1498,7 +1498,7 @@ int _lttng_event_recorder_unregister(struct lttng_kernel_event_recorder *event_r break; case LTTNG_KERNEL_ABI_KPROBE: - lttng_kprobes_unregister_event(event_recorder); + lttng_kprobes_unregister_event(&event_recorder->parent); ret = 0; break; @@ -1590,7 +1590,7 @@ int _lttng_event_notifier_unregister( break; case LTTNG_KERNEL_ABI_KPROBE: - lttng_kprobes_unregister_event_notifier(event_notifier); + lttng_kprobes_unregister_event(&event_notifier->parent); ret = 0; break; @@ -1645,7 +1645,7 @@ void _lttng_event_destroy(struct lttng_kernel_event_common *event) case LTTNG_KERNEL_ABI_KPROBE: module_put(event_priv->desc->owner); - lttng_kprobes_destroy_event_private(event_recorder); + lttng_kprobes_destroy_event_private(&event_recorder->parent); break; case LTTNG_KERNEL_ABI_KRETPROBE: @@ -1685,7 +1685,7 @@ void _lttng_event_destroy(struct lttng_kernel_event_common *event) case LTTNG_KERNEL_ABI_KPROBE: module_put(event_notifier->priv->parent.desc->owner); - lttng_kprobes_destroy_event_notifier_private(event_notifier); + lttng_kprobes_destroy_event_private(&event_notifier->parent); break; case LTTNG_KERNEL_ABI_SYSCALL: diff --git a/src/probes/lttng-kprobes.c b/src/probes/lttng-kprobes.c index 12de611a..1f49c072 100644 --- a/src/probes/lttng-kprobes.c +++ b/src/probes/lttng-kprobes.c @@ -103,7 +103,7 @@ static const struct lttng_kernel_tracepoint_class tp_class = { * Create event description */ static -int lttng_create_kprobe_event(const char *name, struct lttng_kernel_event_recorder *event_recorder) +int lttng_create_kprobe_event(const char *name, struct lttng_kernel_event_common *event) { struct lttng_kernel_event_desc *desc; int ret; @@ -118,35 +118,7 @@ int lttng_create_kprobe_event(const char *name, struct lttng_kernel_event_record goto error_str; } desc->owner = THIS_MODULE; - event_recorder->priv->parent.desc = desc; - - return 0; - -error_str: - kfree(desc); - return ret; -} - -/* - * Create event_notifier description - */ -static -int lttng_create_kprobe_event_notifier(const char *name, struct lttng_kernel_event_notifier *event_notifier) -{ - struct lttng_kernel_event_desc *desc; - int ret; - - desc = kzalloc(sizeof(*desc), GFP_KERNEL); - if (!desc) - return -ENOMEM; - desc->tp_class = &tp_class; - desc->event_name = kstrdup(name, GFP_KERNEL); - if (!desc->event_name) { - ret = -ENOMEM; - goto error_str; - } - desc->owner = THIS_MODULE; - event_notifier->priv->parent.desc = desc; + event->priv->desc = desc; return 0; @@ -210,82 +182,43 @@ int lttng_kprobes_register_event(const char *name, const char *symbol_name, uint64_t offset, uint64_t addr, - struct lttng_kernel_event_recorder *event_recorder) + struct lttng_kernel_event_common *event) { int ret; - ret = lttng_create_kprobe_event(name, event_recorder); + ret = lttng_create_kprobe_event(name, event); if (ret) goto error; ret = _lttng_kprobes_register(symbol_name, offset, addr, - &event_recorder->priv->parent.u.kprobe, lttng_kprobes_event_handler_pre); + &event->priv->u.kprobe, lttng_kprobes_event_handler_pre); if (ret) goto register_error; return 0; register_error: - kfree(event_recorder->priv->parent.desc->event_name); - kfree(event_recorder->priv->parent.desc); + kfree(event->priv->desc->event_name); + kfree(event->priv->desc); error: return ret; } EXPORT_SYMBOL_GPL(lttng_kprobes_register_event); -int lttng_kprobes_register_event_notifier(const char *symbol_name, - uint64_t offset, - uint64_t addr, - struct lttng_kernel_event_notifier *event_notifier) -{ - int ret; - ret = lttng_create_kprobe_event_notifier(symbol_name, event_notifier); - if (ret) - goto error; - - ret = _lttng_kprobes_register(symbol_name, offset, addr, - &event_notifier->priv->parent.u.kprobe, lttng_kprobes_event_handler_pre); - if (ret) - goto register_error; - - return 0; - -register_error: - kfree(event_notifier->priv->parent.desc->event_name); - kfree(event_notifier->priv->parent.desc); -error: - return ret; -} -EXPORT_SYMBOL_GPL(lttng_kprobes_register_event_notifier); - -void lttng_kprobes_unregister_event(struct lttng_kernel_event_recorder *event_recorder) +void lttng_kprobes_unregister_event(struct lttng_kernel_event_common *event) { - unregister_kprobe(&event_recorder->priv->parent.u.kprobe.kp); + unregister_kprobe(&event->priv->u.kprobe.kp); } EXPORT_SYMBOL_GPL(lttng_kprobes_unregister_event); -void lttng_kprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier) +void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common *event) { - unregister_kprobe(&event_notifier->priv->parent.u.kprobe.kp); -} -EXPORT_SYMBOL_GPL(lttng_kprobes_unregister_event_notifier); - -void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_recorder *event_recorder) -{ - kfree(event_recorder->priv->parent.u.kprobe.symbol_name); - kfree(event_recorder->priv->parent.desc->event_name); - kfree(event_recorder->priv->parent.desc); + kfree(event->priv->u.kprobe.symbol_name); + kfree(event->priv->desc->event_name); + kfree(event->priv->desc); } EXPORT_SYMBOL_GPL(lttng_kprobes_destroy_event_private); -void lttng_kprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier) -{ - kfree(event_notifier->priv->parent.u.kprobe.symbol_name); - kfree(event_notifier->priv->parent.desc->event_name); - kfree(event_notifier->priv->parent.desc); -} -EXPORT_SYMBOL_GPL(lttng_kprobes_destroy_event_notifier_private); - MODULE_LICENSE("GPL and additional rights"); MODULE_AUTHOR("Mathieu Desnoyers "); MODULE_DESCRIPTION("LTTng kprobes probes");