Refactoring: combine probe callbacks
[lttng-modules.git] / src / probes / lttng-kprobes.c
index ecb08fc8fd65f9f9dcb474d4e959baadca50b7d2..d3a5cf8a6bf13c62fbe2e80bea9b01bdc5be147f 100644 (file)
@@ -23,54 +23,69 @@ int lttng_kprobes_event_handler_pre(struct kprobe *p, struct pt_regs *regs)
 {
        struct lttng_kernel_event_common_private *event_priv =
                container_of(p, struct lttng_kernel_event_common_private, u.kprobe.kp);
-       struct lttng_kernel_event_recorder_private *event_recorder_priv =
-               container_of(event_priv, struct lttng_kernel_event_recorder_private, parent);
-       struct lttng_kernel_event_recorder *event_recorder =
-               event_recorder_priv->pub;
+       struct lttng_kernel_event_common *event = event_priv->pub;
        struct lttng_probe_ctx lttng_probe_ctx = {
-               .event = event_recorder,
+               .event = event,
                .interruptible = !lttng_regs_irqs_disabled(regs),
        };
-       struct lttng_channel *chan = event_recorder->chan;
-       struct lib_ring_buffer_ctx ctx;
-       int ret;
        unsigned long data = (unsigned long) p->addr;
 
-       if (unlikely(!LTTNG_READ_ONCE(chan->session->active)))
-               return 0;
-       if (unlikely(!LTTNG_READ_ONCE(chan->enabled)))
-               return 0;
-       if (unlikely(!LTTNG_READ_ONCE(event_recorder->parent.enabled)))
-               return 0;
-
-       lib_ring_buffer_ctx_init(&ctx, chan->chan, &lttng_probe_ctx, sizeof(data),
-                                lttng_alignof(data), -1);
-       ret = chan->ops->event_reserve(&ctx, event_recorder->priv->id);
-       if (ret < 0)
-               return 0;
-       lib_ring_buffer_align_ctx(&ctx, lttng_alignof(data));
-       chan->ops->event_write(&ctx, &data, sizeof(data));
-       chan->ops->event_commit(&ctx);
-       return 0;
-}
-
-static
-int lttng_kprobes_event_notifier_handler_pre(struct kprobe *p, struct pt_regs *regs)
-{
-       struct lttng_kernel_event_common_private *event_priv =
-               container_of(p, struct lttng_kernel_event_common_private, u.kprobe.kp);
-       struct lttng_kernel_event_notifier_private *event_notifier_priv =
-               container_of(event_priv, struct lttng_kernel_event_notifier_private, parent);
-       struct lttng_kernel_event_notifier *event_notifier =
-               event_notifier_priv->pub;
-       struct lttng_kernel_notification_ctx notif_ctx;
+       switch (event->type) {
+       case LTTNG_KERNEL_EVENT_TYPE_RECORDER:
+       {
+               struct lttng_kernel_event_recorder_private *event_recorder_priv =
+                       container_of(event_priv, struct lttng_kernel_event_recorder_private, parent);
+               struct lttng_kernel_event_recorder *event_recorder =
+                       event_recorder_priv->pub;
+               struct lttng_channel *chan = event_recorder->chan;
+
+               if (unlikely(!LTTNG_READ_ONCE(chan->session->active)))
+                       return 0;
+               if (unlikely(!LTTNG_READ_ONCE(chan->enabled)))
+                       return 0;
+               break;
+       }
+       case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER:
+               break;
+       default:
+               WARN_ON_ONCE(1);
+       }
 
-       if (unlikely(!READ_ONCE(event_notifier->parent.enabled)))
+       if (unlikely(!LTTNG_READ_ONCE(event->enabled)))
                return 0;
 
-       notif_ctx.eval_capture = LTTNG_READ_ONCE(event_notifier->eval_capture);
-       event_notifier->notification_send(event_notifier, NULL, NULL, &notif_ctx);
-
+       switch (event->type) {
+       case LTTNG_KERNEL_EVENT_TYPE_RECORDER:
+       {
+               struct lttng_kernel_event_recorder *event_recorder =
+                       container_of(event, struct lttng_kernel_event_recorder, parent);
+               struct lttng_channel *chan = event_recorder->chan;
+               struct lib_ring_buffer_ctx ctx;
+               int ret;
+
+               lib_ring_buffer_ctx_init(&ctx, chan->chan, &lttng_probe_ctx, sizeof(data),
+                                        lttng_alignof(data), -1);
+               ret = chan->ops->event_reserve(&ctx, event_recorder->priv->id);
+               if (ret < 0)
+                       return 0;
+               lib_ring_buffer_align_ctx(&ctx, lttng_alignof(data));
+               chan->ops->event_write(&ctx, &data, sizeof(data));
+               chan->ops->event_commit(&ctx);
+               break;
+       }
+       case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER:
+       {
+               struct lttng_kernel_event_notifier *event_notifier =
+                       container_of(event, struct lttng_kernel_event_notifier, parent);
+               struct lttng_kernel_notification_ctx notif_ctx;
+
+               notif_ctx.eval_capture = LTTNG_READ_ONCE(event_notifier->eval_capture);
+               event_notifier->notification_send(event_notifier, NULL, NULL, &notif_ctx);
+               break;
+       }
+       default:
+               WARN_ON_ONCE(1);
+       }
        return 0;
 }
 
@@ -244,7 +259,7 @@ int lttng_kprobes_register_event_notifier(const char *symbol_name,
                goto error;
 
        ret = _lttng_kprobes_register(symbol_name, offset, addr,
-               &event_notifier->priv->parent.u.kprobe, lttng_kprobes_event_notifier_handler_pre);
+               &event_notifier->priv->parent.u.kprobe, lttng_kprobes_event_handler_pre);
        if (ret)
                goto register_error;
 
This page took 0.023999 seconds and 4 git commands to generate.