Combine event notifier and recorder enable/disable functions
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 22 Apr 2021 20:17:54 +0000 (16:17 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 23 Apr 2021 14:58:56 +0000 (10:58 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I945b24211b48b9d40b1d25f0c9fb78f6eb8439da

include/lttng/events.h
src/lttng-abi.c
src/lttng-events.c

index 811f78ce336f5e5c9452a151fb9b9fe2cb2b5d94..2ceec317d604edc11c0a12d7b5cd3fd7b110ab86 100644 (file)
@@ -936,11 +936,8 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create(
 
 int lttng_channel_enable(struct lttng_channel *channel);
 int lttng_channel_disable(struct lttng_channel *channel);
-int lttng_event_enable(struct lttng_kernel_event_recorder *event);
-int lttng_event_disable(struct lttng_kernel_event_recorder *event);
-
-int lttng_event_notifier_enable(struct lttng_kernel_event_notifier *event_notifier);
-int lttng_event_notifier_disable(struct lttng_kernel_event_notifier *event_notifier);
+int lttng_event_enable(struct lttng_kernel_event_common *event);
+int lttng_event_disable(struct lttng_kernel_event_common *event);
 
 void lttng_transport_register(struct lttng_transport *transport);
 void lttng_transport_unregister(struct lttng_transport *transport);
index d660ad470c7653801159a61b35059f2a2af183be..cc3a410cd9a5f62116b55015f2b038bbee0124e5 100644 (file)
@@ -1904,9 +1904,9 @@ long lttng_event_notifier_event_ioctl(struct file *file, unsigned int cmd, unsig
 
        switch (cmd) {
        case LTTNG_KERNEL_ABI_ENABLE:
-               return lttng_event_notifier_enable(event_notifier);
+               return lttng_event_enable(&event_notifier->parent);
        case LTTNG_KERNEL_ABI_DISABLE:
-               return lttng_event_notifier_disable(event_notifier);
+               return lttng_event_disable(&event_notifier->parent);
        case LTTNG_KERNEL_ABI_FILTER:
                return -EINVAL;
        case LTTNG_KERNEL_ABI_CAPTURE:
@@ -2597,10 +2597,10 @@ long lttng_event_recorder_event_ioctl(struct file *file, unsigned int cmd, unsig
        }
        case LTTNG_KERNEL_ABI_OLD_ENABLE:
        case LTTNG_KERNEL_ABI_ENABLE:
-               return lttng_event_enable(event_recorder);
+               return lttng_event_enable(&event_recorder->parent);
        case LTTNG_KERNEL_ABI_OLD_DISABLE:
        case LTTNG_KERNEL_ABI_DISABLE:
-               return lttng_event_disable(event_recorder);
+               return lttng_event_disable(&event_recorder->parent);
        case LTTNG_KERNEL_ABI_FILTER:
                return -EINVAL;
        case LTTNG_KERNEL_ABI_ADD_CALLSITE:
index c956db54a194c3bf0493b43edd3055bfb61379a7..d85b516c9dde7d1fec95165f204a4314a5f39a8e 100644 (file)
@@ -603,57 +603,37 @@ end:
        return ret;
 }
 
-int lttng_event_enable(struct lttng_kernel_event_recorder *event_recorder)
+int lttng_event_enable(struct lttng_kernel_event_common *event)
 {
-       struct lttng_kernel_event_common *event = &event_recorder->parent;
        int ret = 0;
 
        mutex_lock(&sessions_mutex);
-       if (event_recorder->chan->channel_type == METADATA_CHANNEL) {
-               ret = -EPERM;
-               goto end;
-       }
-       if (event->enabled) {
-               ret = -EEXIST;
-               goto end;
-       }
-       switch (event->priv->instrumentation) {
-       case LTTNG_KERNEL_ABI_TRACEPOINT:       /* Fall-through */
-       case LTTNG_KERNEL_ABI_SYSCALL:
-               ret = -EINVAL;
-               break;
+       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);
 
-       case LTTNG_KERNEL_ABI_KPROBE:           /* Fall-through */
-       case LTTNG_KERNEL_ABI_UPROBE:
-               WRITE_ONCE(event->enabled, 1);
+               if (event_recorder->chan->channel_type == METADATA_CHANNEL) {
+                       ret = -EPERM;
+                       goto end;
+               }
                break;
-
-       case LTTNG_KERNEL_ABI_KRETPROBE:
-               ret = lttng_kretprobes_event_enable_state(&event_recorder->parent, 1);
+       }
+       case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER:
+               switch (event->priv->instrumentation) {
+               case LTTNG_KERNEL_ABI_KRETPROBE:
+                       ret = -EINVAL;
+                       goto end;
+               default:
+                       break;
+               }
                break;
-
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
        default:
-               WARN_ON_ONCE(1);
-               ret = -EINVAL;
+               break;
        }
-end:
-       mutex_unlock(&sessions_mutex);
-       return ret;
-}
-
-int lttng_event_disable(struct lttng_kernel_event_recorder *event_recorder)
-{
-       struct lttng_kernel_event_common *event = &event_recorder->parent;
-       int ret = 0;
 
-       mutex_lock(&sessions_mutex);
-       if (event_recorder->chan->channel_type == METADATA_CHANNEL) {
-               ret = -EPERM;
-               goto end;
-       }
-       if (!event->enabled) {
+       if (event->enabled) {
                ret = -EEXIST;
                goto end;
        }
@@ -665,12 +645,11 @@ int lttng_event_disable(struct lttng_kernel_event_recorder *event_recorder)
 
        case LTTNG_KERNEL_ABI_KPROBE:           /* Fall-through */
        case LTTNG_KERNEL_ABI_UPROBE:
-               WRITE_ONCE(event->enabled, 0);
+               WRITE_ONCE(event->enabled, 1);
                break;
 
        case LTTNG_KERNEL_ABI_KRETPROBE:
-
-               ret = lttng_kretprobes_event_enable_state(&event_recorder->parent, 0);
+               ret = lttng_kretprobes_event_enable_state(event, 1);
                break;
 
        case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
@@ -684,45 +663,36 @@ end:
        return ret;
 }
 
-int lttng_event_notifier_enable(struct lttng_kernel_event_notifier *event_notifier)
+int lttng_event_disable(struct lttng_kernel_event_common *event)
 {
-       struct lttng_kernel_event_common *event = &event_notifier->parent;
        int ret = 0;
 
        mutex_lock(&sessions_mutex);
-       if (event->enabled) {
-               ret = -EEXIST;
-               goto end;
-       }
-       switch (event->priv->instrumentation) {
-       case LTTNG_KERNEL_ABI_TRACEPOINT:       /* Fall-through */
-       case LTTNG_KERNEL_ABI_SYSCALL:
-               ret = -EINVAL;
-               break;
+       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);
 
-       case LTTNG_KERNEL_ABI_KPROBE:           /* Fall-through */
-       case LTTNG_KERNEL_ABI_UPROBE:
-               WRITE_ONCE(event->enabled, 1);
+               if (event_recorder->chan->channel_type == METADATA_CHANNEL) {
+                       ret = -EPERM;
+                       goto end;
+               }
+               break;
+       }
+       case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER:
+               switch (event->priv->instrumentation) {
+               case LTTNG_KERNEL_ABI_KRETPROBE:
+                       ret = -EINVAL;
+                       goto end;
+               default:
+                       break;
+               }
                break;
-
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_KRETPROBE:        /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
        default:
-               WARN_ON_ONCE(1);
-               ret = -EINVAL;
+               break;
        }
-end:
-       mutex_unlock(&sessions_mutex);
-       return ret;
-}
-
-int lttng_event_notifier_disable(struct lttng_kernel_event_notifier *event_notifier)
-{
-       struct lttng_kernel_event_common *event = &event_notifier->parent;
-       int ret = 0;
 
-       mutex_lock(&sessions_mutex);
        if (!event->enabled) {
                ret = -EEXIST;
                goto end;
@@ -738,8 +708,11 @@ int lttng_event_notifier_disable(struct lttng_kernel_event_notifier *event_notif
                WRITE_ONCE(event->enabled, 0);
                break;
 
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               ret = lttng_kretprobes_event_enable_state(event, 0);
+               break;
+
        case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_KRETPROBE:        /* Fall-through */
        case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
        default:
                WARN_ON_ONCE(1);
This page took 0.033849 seconds and 4 git commands to generate.