From: Mathieu Desnoyers Date: Thu, 22 Apr 2021 20:17:54 +0000 (-0400) Subject: Combine event notifier and recorder enable/disable functions X-Git-Tag: v2.13.0-rc1~5 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9d993668c1e98fa676ea33432bf0d89fd33a0599;p=lttng-modules.git Combine event notifier and recorder enable/disable functions Signed-off-by: Mathieu Desnoyers Change-Id: I945b24211b48b9d40b1d25f0c9fb78f6eb8439da --- diff --git a/include/lttng/events.h b/include/lttng/events.h index 811f78ce..2ceec317 100644 --- a/include/lttng/events.h +++ b/include/lttng/events.h @@ -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); diff --git a/src/lttng-abi.c b/src/lttng-abi.c index d660ad47..cc3a410c 100644 --- a/src/lttng-abi.c +++ b/src/lttng-abi.c @@ -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: diff --git a/src/lttng-events.c b/src/lttng-events.c index c956db54..d85b516c 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -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);