Refactoring: channel enable/disable using common type
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 1 Nov 2021 19:31:04 +0000 (15:31 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 1 Nov 2021 19:31:04 +0000 (15:31 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ie86e23937d00a5d53aa3dbadb7666c176f3c0d52

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

index 84c0d009a4f2eefbc5d415eaf3fe9a236492a23e..a016bdf48559534f38ccee3471c91c1f6f931a3d 100644 (file)
@@ -1108,8 +1108,8 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create(
                                struct lttng_kernel_abi_event_notifier *event_notifier_param,
                                enum lttng_kernel_abi_instrumentation itype);
 
-int lttng_channel_enable(struct lttng_kernel_channel_buffer *channel);
-int lttng_channel_disable(struct lttng_kernel_channel_buffer *channel);
+int lttng_channel_enable(struct lttng_kernel_channel_common *channel);
+int lttng_channel_disable(struct lttng_kernel_channel_common *channel);
 int lttng_event_enable(struct lttng_kernel_event_common *event);
 int lttng_event_disable(struct lttng_kernel_event_common *event);
 
index 7eafe2d09ff1403738ce00442ac18f458dd73606..d4760561d73469741f093d96003e2e3cf8020419 100644 (file)
@@ -2527,10 +2527,10 @@ old_ctx_end:
        }
        case LTTNG_KERNEL_ABI_OLD_ENABLE:
        case LTTNG_KERNEL_ABI_ENABLE:
-               return lttng_channel_enable(channel);
+               return lttng_channel_enable(&channel->parent);
        case LTTNG_KERNEL_ABI_OLD_DISABLE:
        case LTTNG_KERNEL_ABI_DISABLE:
-               return lttng_channel_disable(channel);
+               return lttng_channel_disable(&channel->parent);
        case LTTNG_KERNEL_ABI_SYSCALL_MASK:
                return lttng_channel_syscall_mask(channel,
                        (struct lttng_kernel_abi_syscall_mask __user *) arg);
index fe29870d09b65c2b2cba7289a4364a98567330f0..bed65028a912fff796d2cf5a00c411780b926ecc 100644 (file)
@@ -578,47 +578,60 @@ end:
        return ret;
 }
 
-int lttng_channel_enable(struct lttng_kernel_channel_buffer *channel)
+static
+bool is_channel_buffer_metadata(struct lttng_kernel_channel_common *channel)
+{
+       struct lttng_kernel_channel_buffer *chan_buf;
+
+       if (channel->type != LTTNG_KERNEL_CHANNEL_TYPE_BUFFER)
+               return false;
+       chan_buf = container_of(channel, struct lttng_kernel_channel_buffer, parent);
+       if (chan_buf->priv->channel_type == METADATA_CHANNEL)
+               return true;
+       return false;
+}
+
+int lttng_channel_enable(struct lttng_kernel_channel_common *channel)
 {
        int ret = 0;
 
        mutex_lock(&sessions_mutex);
-       if (channel->priv->channel_type == METADATA_CHANNEL) {
+       if (is_channel_buffer_metadata(channel)) {
                ret = -EPERM;
                goto end;
        }
-       if (channel->parent.enabled) {
+       if (channel->enabled) {
                ret = -EEXIST;
                goto end;
        }
        /* Set transient enabler state to "enabled" */
-       channel->priv->parent.tstate = 1;
-       lttng_session_sync_event_enablers(channel->parent.session);
+       channel->priv->tstate = 1;
+       lttng_session_sync_event_enablers(channel->session);
        /* Set atomically the state to "enabled" */
-       WRITE_ONCE(channel->parent.enabled, 1);
+       WRITE_ONCE(channel->enabled, 1);
 end:
        mutex_unlock(&sessions_mutex);
        return ret;
 }
 
-int lttng_channel_disable(struct lttng_kernel_channel_buffer *channel)
+int lttng_channel_disable(struct lttng_kernel_channel_common *channel)
 {
        int ret = 0;
 
        mutex_lock(&sessions_mutex);
-       if (channel->priv->channel_type == METADATA_CHANNEL) {
+       if (is_channel_buffer_metadata(channel)) {
                ret = -EPERM;
                goto end;
        }
-       if (!channel->parent.enabled) {
+       if (!channel->enabled) {
                ret = -EEXIST;
                goto end;
        }
        /* Set atomically the state to "disabled" */
-       WRITE_ONCE(channel->parent.enabled, 0);
+       WRITE_ONCE(channel->enabled, 0);
        /* Set transient enabler state to "enabled" */
-       channel->priv->parent.tstate = 0;
-       lttng_session_sync_event_enablers(channel->parent.session);
+       channel->priv->tstate = 0;
+       lttng_session_sync_event_enablers(channel->session);
 end:
        mutex_unlock(&sessions_mutex);
        return ret;
This page took 0.037191 seconds and 4 git commands to generate.