Refactoring: kprobes: combine common code between recorder and notifier
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Nov 2021 16:46:48 +0000 (12:46 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Nov 2021 16:46:48 +0000 (12:46 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Iea2cf795c5409b0f5dadbadccb9cb2b4cd37acfc

include/lttng/events-internal.h
src/lttng-events.c
src/probes/lttng-kprobes.c

index d72502c9b0a8ee8a6b912a5cc846a46fe1058ca3..c46f2b6c2386b6a4f4231dde74e5b28ca43b2882 100644 (file)
@@ -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
index d5f8314c5fbbe59ea9834b37809de658971032c0..92af4c900b278ba794d586520afbdcae78a44eeb 100644 (file)
@@ -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:
index 12de611a8004e968c58724273992313ed9977f2c..1f49c072c7daae9a3f25a1ddccda4b9965816b5e 100644 (file)
@@ -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 <mathieu.desnoyers@efficios.com>");
 MODULE_DESCRIPTION("LTTng kprobes probes");
This page took 0.031756 seconds and 4 git commands to generate.