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

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

index 4b5883ed12bc2264a0321dc7efaeae42b44c7fbf..d72502c9b0a8ee8a6b912a5cc846a46fe1058ca3 100644 (file)
@@ -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
index 7181f0fbaf6cb5d3461eb48af469cc1098402041..d5f8314c5fbbe59ea9834b37809de658971032c0 100644 (file)
@@ -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:
index fed3a1d5a2b4c9beefe4f787370398a38d44474f..b6531a71e16df3938e364023c9d767319f71f2c6 100644 (file)
@@ -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);
 
This page took 0.032921 seconds and 4 git commands to generate.