From 17806c46f59eba37b32bde6543bd5017d154b42d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 2 Nov 2021 12:38:41 -0400 Subject: [PATCH] Refactoring: uprobes: combine common code between recorder and notifier Signed-off-by: Mathieu Desnoyers Change-Id: Ibbd7ddb064ca114e0c9dcf1b88c695167ee087aa --- include/lttng/events-internal.h | 33 +++---------- src/lttng-events.c | 15 +++--- src/probes/lttng-uprobes.c | 83 ++++++--------------------------- 3 files changed, 26 insertions(+), 105 deletions(-) diff --git a/include/lttng/events-internal.h b/include/lttng/events-internal.h index 4b5883ed..d72502c9 100644 --- a/include/lttng/events-internal.h +++ b/include/lttng/events-internal.h @@ -920,19 +920,15 @@ int lttng_event_add_callsite(struct lttng_kernel_event_common *event, #ifdef CONFIG_UPROBES int lttng_uprobes_register_event(const char *name, - int fd, struct lttng_kernel_event_recorder *event); + int fd, struct lttng_kernel_event_common *event); int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event, struct lttng_kernel_abi_event_callsite __user *callsite); -void lttng_uprobes_unregister_event(struct lttng_kernel_event_recorder *event); -void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_recorder *event); -int lttng_uprobes_register_event_notifier(const char *name, - int fd, struct lttng_kernel_event_notifier *event_notifier); -void lttng_uprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier); -void lttng_uprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier); +void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event); +void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event); #else static inline int lttng_uprobes_register_event(const char *name, - int fd, struct lttng_kernel_event_recorder *event) + int fd, struct lttng_kernel_event_common *event) { return -ENOSYS; } @@ -945,29 +941,12 @@ int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event, } static inline -void lttng_uprobes_unregister_event(struct lttng_kernel_event_recorder *event) +void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event) { } static inline -void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_recorder *event) -{ -} - -static inline -int lttng_uprobes_register_event_notifier(const char *name, - int fd, struct lttng_kernel_event_notifier *event_notifier) -{ - return -ENOSYS; -} - -static inline -void lttng_uprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier) -{ -} - -static inline -void lttng_uprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier) +void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event) { } #endif diff --git a/src/lttng-events.c b/src/lttng-events.c index 7181f0fb..d5f8314c 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -1114,7 +1114,7 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l ret = lttng_uprobes_register_event(event_param->name, event_param->u.uprobe.fd, - event_recorder); + &event_recorder->parent); if (ret) goto register_error; ret = try_module_get(event_recorder->priv->parent.desc->owner); @@ -1321,10 +1321,9 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create( */ smp_wmb(); - ret = lttng_uprobes_register_event_notifier( - event_notifier_param->event.name, + ret = lttng_uprobes_register_event(event_notifier_param->event.name, event_notifier_param->event.u.uprobe.fd, - event_notifier); + &event_notifier->parent); if (ret) goto register_error; ret = try_module_get(event_notifier->priv->parent.desc->owner); @@ -1517,7 +1516,7 @@ int _lttng_event_recorder_unregister(struct lttng_kernel_event_recorder *event_r break; case LTTNG_KERNEL_ABI_UPROBE: - lttng_uprobes_unregister_event(event_recorder); + lttng_uprobes_unregister_event(&event_recorder->parent); ret = 0; break; @@ -1596,7 +1595,7 @@ int _lttng_event_notifier_unregister( break; case LTTNG_KERNEL_ABI_UPROBE: - lttng_uprobes_unregister_event_notifier(event_notifier); + lttng_uprobes_unregister_event(&event_notifier->parent); ret = 0; break; @@ -1659,7 +1658,7 @@ void _lttng_event_destroy(struct lttng_kernel_event_common *event) case LTTNG_KERNEL_ABI_UPROBE: module_put(event_priv->desc->owner); - lttng_uprobes_destroy_event_private(event_recorder); + lttng_uprobes_destroy_event_private(&event_recorder->parent); break; case LTTNG_KERNEL_ABI_FUNCTION: @@ -1694,7 +1693,7 @@ void _lttng_event_destroy(struct lttng_kernel_event_common *event) case LTTNG_KERNEL_ABI_UPROBE: module_put(event_notifier->priv->parent.desc->owner); - lttng_uprobes_destroy_event_notifier_private(event_notifier); + lttng_uprobes_destroy_event_private(&event_notifier->parent); break; case LTTNG_KERNEL_ABI_KRETPROBE: diff --git a/src/probes/lttng-uprobes.c b/src/probes/lttng-uprobes.c index fed3a1d5..b6531a71 100644 --- a/src/probes/lttng-uprobes.c +++ b/src/probes/lttng-uprobes.c @@ -113,7 +113,7 @@ static const struct lttng_kernel_tracepoint_class tp_class = { * Create event description. */ static -int lttng_create_uprobe_event(const char *name, struct lttng_kernel_event_recorder *event_recorder) +int lttng_create_uprobe_event(const char *name, struct lttng_kernel_event_common *event) { struct lttng_kernel_event_desc *desc; int ret; @@ -128,35 +128,7 @@ int lttng_create_uprobe_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_uprobe_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; @@ -276,51 +248,28 @@ inode_error: return ret; } -int lttng_uprobes_register_event(const char *name, int fd, struct lttng_kernel_event_recorder *event_recorder) +int lttng_uprobes_register_event(const char *name, int fd, struct lttng_kernel_event_common *event) { int ret = 0; - ret = lttng_create_uprobe_event(name, event_recorder); + ret = lttng_create_uprobe_event(name, event); if (ret) goto error; - ret = lttng_uprobes_register(&event_recorder->priv->parent.u.uprobe, fd); + ret = lttng_uprobes_register(&event->priv->u.uprobe, fd); 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_uprobes_register_event); -int lttng_uprobes_register_event_notifier(const char *name, int fd, - struct lttng_kernel_event_notifier *event_notifier) -{ - int ret = 0; - - ret = lttng_create_uprobe_event_notifier(name, event_notifier); - if (ret) - goto error; - - ret = lttng_uprobes_register(&event_notifier->priv->parent.u.uprobe, fd); - 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_uprobes_register_event_notifier); - static void lttng_uprobes_unregister(struct inode *inode, struct list_head *head) { @@ -337,23 +286,17 @@ void lttng_uprobes_unregister(struct inode *inode, struct list_head *head) } } -void lttng_uprobes_unregister_event(struct lttng_kernel_event_recorder *event_recorder) +void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event) { - lttng_uprobes_unregister(event_recorder->priv->parent.u.uprobe.inode, &event_recorder->priv->parent.u.uprobe.head); + lttng_uprobes_unregister(event->priv->u.uprobe.inode, &event->priv->u.uprobe.head); } EXPORT_SYMBOL_GPL(lttng_uprobes_unregister_event); -void lttng_uprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier) -{ - lttng_uprobes_unregister(event_notifier->priv->parent.u.uprobe.inode, &event_notifier->priv->parent.u.uprobe.head); -} -EXPORT_SYMBOL_GPL(lttng_uprobes_unregister_event_notifier); - -void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_recorder *event_recorder) +void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event) { - iput(event_recorder->priv->parent.u.uprobe.inode); - kfree(event_recorder->priv->parent.desc->event_name); - kfree(event_recorder->priv->parent.desc); + iput(event->priv->u.uprobe.inode); + kfree(event->priv->desc->event_name); + kfree(event->priv->desc); } EXPORT_SYMBOL_GPL(lttng_uprobes_destroy_event_private); -- 2.34.1