From eb6b47dbeeb508c56dd965209c1179be15b6d27c Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 2 Nov 2021 13:30:32 -0400 Subject: [PATCH] Refactoring: kretprobes: use event common argument types Signed-off-by: Mathieu Desnoyers Change-Id: I9c272f240b01cf070e45d7663c331e1cbce921b8 --- include/lttng/events-internal.h | 16 +++++------ src/lttng-events.c | 6 ++-- src/probes/lttng-kretprobes.c | 49 ++++++++++++++++----------------- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/include/lttng/events-internal.h b/include/lttng/events-internal.h index c46f2b6c..86abd878 100644 --- a/include/lttng/events-internal.h +++ b/include/lttng/events-internal.h @@ -931,10 +931,10 @@ int lttng_kretprobes_register(const char *name, const char *symbol_name, uint64_t offset, uint64_t addr, - struct lttng_kernel_event_recorder *event_entry, - struct lttng_kernel_event_recorder *event_exit); -void lttng_kretprobes_unregister(struct lttng_kernel_event_recorder *event); -void lttng_kretprobes_destroy_private(struct lttng_kernel_event_recorder *event); + struct lttng_kernel_event_common *event_entry, + struct lttng_kernel_event_common *event_exit); +void lttng_kretprobes_unregister(struct lttng_kernel_event_common *event); +void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common *event); int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common *event, int enable); #else @@ -943,19 +943,19 @@ int lttng_kretprobes_register(const char *name, const char *symbol_name, uint64_t offset, uint64_t addr, - struct lttng_kernel_event_recorder *event_entry, - struct lttng_kernel_event_recorder *event_exit) + struct lttng_kernel_event_common *event_entry, + struct lttng_kernel_event_common *event_exit) { return -ENOSYS; } static inline -void lttng_kretprobes_unregister(struct lttng_kernel_event_recorder *event) +void lttng_kretprobes_unregister(struct lttng_kernel_event_common *event) { } static inline -void lttng_kretprobes_destroy_private(struct lttng_kernel_event_recorder *event) +void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common *event) { } diff --git a/src/lttng-events.c b/src/lttng-events.c index 92af4c90..bc5a56cc 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -1036,7 +1036,7 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l event_param->u.kretprobe.symbol_name, event_param->u.kretprobe.offset, event_param->u.kretprobe.addr, - event_recorder, event_recorder_return); + &event_recorder->parent, &event_recorder_return->parent); if (ret) { kmem_cache_free(event_recorder_private_cache, event_recorder_return_priv); kmem_cache_free(event_recorder_cache, event_recorder_return); @@ -1503,7 +1503,7 @@ int _lttng_event_recorder_unregister(struct lttng_kernel_event_recorder *event_r break; case LTTNG_KERNEL_ABI_KRETPROBE: - lttng_kretprobes_unregister(event_recorder); + lttng_kretprobes_unregister(&event_recorder->parent); ret = 0; break; @@ -1650,7 +1650,7 @@ void _lttng_event_destroy(struct lttng_kernel_event_common *event) case LTTNG_KERNEL_ABI_KRETPROBE: module_put(event_priv->desc->owner); - lttng_kretprobes_destroy_private(event_recorder); + lttng_kretprobes_destroy_private(&event_recorder->parent); break; case LTTNG_KERNEL_ABI_SYSCALL: diff --git a/src/probes/lttng-kretprobes.c b/src/probes/lttng-kretprobes.c index 1d0a5ecb..5cb2e953 100644 --- a/src/probes/lttng-kretprobes.c +++ b/src/probes/lttng-kretprobes.c @@ -132,7 +132,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, enum lttng_kretprobe_type type) { struct lttng_kernel_event_desc *desc; @@ -164,7 +164,7 @@ int lttng_create_kprobe_event(const char *name, struct lttng_kernel_event_record desc->event_name = alloc_name; desc->tp_class = &tp_class; desc->owner = THIS_MODULE; - event_recorder->priv->parent.desc = desc; + event->priv->desc = desc; return 0; @@ -177,8 +177,8 @@ int lttng_kretprobes_register(const char *name, const char *symbol_name, uint64_t offset, uint64_t addr, - struct lttng_kernel_event_recorder *event_recorder_entry, - struct lttng_kernel_event_recorder *event_recorder_exit) + struct lttng_kernel_event_common *event_entry, + struct lttng_kernel_event_common *event_exit) { int ret; struct lttng_krp *lttng_krp; @@ -187,10 +187,10 @@ int lttng_kretprobes_register(const char *name, if (symbol_name[0] == '\0') symbol_name = NULL; - ret = lttng_create_kprobe_event(name, event_recorder_entry, EVENT_ENTRY); + ret = lttng_create_kprobe_event(name, event_entry, EVENT_ENTRY); if (ret) goto error; - ret = lttng_create_kprobe_event(name, event_recorder_exit, EVENT_EXIT); + ret = lttng_create_kprobe_event(name, event_exit, EVENT_EXIT); if (ret) goto event_exit_error; lttng_krp = kzalloc(sizeof(*lttng_krp), GFP_KERNEL); @@ -206,21 +206,18 @@ int lttng_kretprobes_register(const char *name, ret = -ENOMEM; goto name_error; } - lttng_krp->krp.kp.symbol_name = - alloc_symbol; - event_recorder_entry->priv->parent.u.kretprobe.symbol_name = - alloc_symbol; - event_recorder_exit->priv->parent.u.kretprobe.symbol_name = - alloc_symbol; + lttng_krp->krp.kp.symbol_name = alloc_symbol; + event_entry->priv->u.kretprobe.symbol_name = alloc_symbol; + event_exit->priv->u.kretprobe.symbol_name = alloc_symbol; } lttng_krp->krp.kp.offset = offset; lttng_krp->krp.kp.addr = (void *) (unsigned long) addr; /* Allow probe handler to find event structures */ - lttng_krp->event[EVENT_ENTRY] = &event_recorder_entry->parent; - lttng_krp->event[EVENT_EXIT] = &event_recorder_exit->parent; - event_recorder_entry->priv->parent.u.kretprobe.lttng_krp = lttng_krp; - event_recorder_exit->priv->parent.u.kretprobe.lttng_krp = lttng_krp; + lttng_krp->event[EVENT_ENTRY] = event_entry; + lttng_krp->event[EVENT_EXIT] = event_exit; + event_entry->priv->u.kretprobe.lttng_krp = lttng_krp; + event_exit->priv->u.kretprobe.lttng_krp = lttng_krp; /* * Both events must be unregistered before the kretprobe is @@ -248,11 +245,11 @@ register_error: name_error: kfree(lttng_krp); krp_error: - kfree(event_recorder_exit->priv->parent.desc->event_name); - kfree(event_recorder_exit->priv->parent.desc); + kfree(event_exit->priv->desc->event_name); + kfree(event_exit->priv->desc); event_exit_error: - kfree(event_recorder_entry->priv->parent.desc->event_name); - kfree(event_recorder_entry->priv->parent.desc); + kfree(event_entry->priv->desc->event_name); + kfree(event_entry->priv->desc); error: return ret; } @@ -266,9 +263,9 @@ void _lttng_kretprobes_unregister_release(struct kref *kref) unregister_kretprobe(<tng_krp->krp); } -void lttng_kretprobes_unregister(struct lttng_kernel_event_recorder *event_recorder) +void lttng_kretprobes_unregister(struct lttng_kernel_event_common *event) { - kref_put(&event_recorder->priv->parent.u.kretprobe.lttng_krp->kref_register, + kref_put(&event->priv->u.kretprobe.lttng_krp->kref_register, _lttng_kretprobes_unregister_release); } EXPORT_SYMBOL_GPL(lttng_kretprobes_unregister); @@ -281,11 +278,11 @@ void _lttng_kretprobes_release(struct kref *kref) kfree(lttng_krp->krp.kp.symbol_name); } -void lttng_kretprobes_destroy_private(struct lttng_kernel_event_recorder *event_recorder) +void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common *event) { - kfree(event_recorder->priv->parent.desc->event_name); - kfree(event_recorder->priv->parent.desc); - kref_put(&event_recorder->priv->parent.u.kretprobe.lttng_krp->kref_alloc, + kfree(event->priv->desc->event_name); + kfree(event->priv->desc); + kref_put(&event->priv->u.kretprobe.lttng_krp->kref_alloc, _lttng_kretprobes_release); } EXPORT_SYMBOL_GPL(lttng_kretprobes_destroy_private); -- 2.34.1