Fix: pass private data to context callbacks
[lttng-ust.git] / liblttng-ust / lttng-ust-abi.c
index 12cb91f736a59143bc1a73b79c8682a64d37be86..61105ace6dccd9d83e00865454e7580252b21199 100644 (file)
@@ -39,6 +39,7 @@
 #include <usterr-signal-safe.h>
 
 #include "../libringbuffer/frontend_types.h"
+#include "../libringbuffer/frontend.h"
 #include "../libringbuffer/shm.h"
 #include "../libcounter/counter.h"
 #include "tracepoint-internal.h"
@@ -287,13 +288,13 @@ int lttng_abi_create_root_handle(void)
 }
 
 static
-int lttng_is_channel_ready(struct lttng_channel *lttng_chan)
+int lttng_is_channel_ready(struct lttng_ust_channel_buffer *lttng_chan)
 {
        struct lttng_ust_lib_ring_buffer_channel *chan;
        unsigned int nr_streams, exp_streams;
 
-       chan = lttng_chan->chan;
-       nr_streams = channel_handle_get_nr_streams(lttng_chan->handle);
+       chan = lttng_chan->priv->rb_chan;
+       nr_streams = channel_handle_get_nr_streams(lttng_chan->priv->rb_chan->handle);
        exp_streams = chan->nr_streams;
        return nr_streams == exp_streams;
 }
@@ -322,7 +323,7 @@ objd_error:
 }
 
 static
-long lttng_abi_tracer_version(int objd,
+long lttng_abi_tracer_version(int objd __attribute__((unused)),
        struct lttng_ust_abi_tracer_version *v)
 {
        v->major = LTTNG_UST_MAJOR_VERSION;
@@ -376,7 +377,7 @@ fd_error:
 }
 
 static
-long lttng_abi_add_context(int objd,
+long lttng_abi_add_context(int objd __attribute__((unused)),
        struct lttng_ust_abi_context *context_param,
        union lttng_ust_abi_args *uargs,
        struct lttng_ust_ctx **ctx, struct lttng_ust_session *session)
@@ -448,7 +449,8 @@ int lttng_abi_map_channel(int session_objd,
        const char *chan_name;
        int chan_objd;
        struct lttng_ust_shm_handle *channel_handle;
-       struct lttng_channel *lttng_chan;
+       struct lttng_ust_abi_channel_config *lttng_chan_config;
+       struct lttng_ust_channel_buffer *lttng_chan_buf;
        struct lttng_ust_lib_ring_buffer_channel *chan;
        struct lttng_ust_lib_ring_buffer_config *config;
        void *chan_data;
@@ -475,6 +477,12 @@ int lttng_abi_map_channel(int session_objd,
                goto active;    /* Refuse to add channel to active session */
        }
 
+       lttng_chan_buf = lttng_ust_alloc_channel_buffer();
+       if (!lttng_chan_buf) {
+               ret = -ENOMEM;
+               goto lttng_chan_buf_error;
+       }
+
        channel_handle = channel_handle_create(chan_data, len, wakeup_fd);
        if (!channel_handle) {
                ret = -EINVAL;
@@ -489,12 +497,17 @@ int lttng_abi_map_channel(int session_objd,
        assert(chan);
        chan->handle = channel_handle;
        config = &chan->backend.config;
-       lttng_chan = channel_get_private(chan);
-       if (!lttng_chan) {
+       lttng_chan_config = channel_get_private_config(chan);
+       if (!lttng_chan_config) {
                ret = -EINVAL;
                goto alloc_error;
        }
 
+       if (lttng_ust_session_uuid_validate(session, lttng_chan_config->uuid)) {
+               ret = -EINVAL;
+               goto uuid_error;
+       }
+
        /* Lookup transport name */
        switch (type) {
        case LTTNG_UST_ABI_CHAN_PER_CPU:
@@ -537,26 +550,32 @@ int lttng_abi_map_channel(int session_objd,
        }
 
        /* Initialize our lttng chan */
-       lttng_chan->chan = chan;
-       lttng_chan->tstate = 1;
-       lttng_chan->enabled = 1;
-       lttng_chan->ctx = NULL;
-       lttng_chan->session = session;
-       lttng_chan->ops = &transport->ops;
-       memcpy(&lttng_chan->chan->backend.config,
+       lttng_chan_buf->parent->enabled = 1;
+       lttng_chan_buf->parent->session = session;
+
+       lttng_chan_buf->priv->parent.tstate = 1;
+       lttng_chan_buf->priv->ctx = NULL;
+       lttng_chan_buf->priv->rb_chan = chan;
+
+       lttng_chan_buf->ops = &transport->ops;
+
+       memcpy(&chan->backend.config,
                transport->client_config,
-               sizeof(lttng_chan->chan->backend.config));
-       cds_list_add(&lttng_chan->node, &session->priv->chan_head);
-       lttng_chan->header_type = 0;
-       lttng_chan->handle = channel_handle;
-       lttng_chan->type = type;
+               sizeof(chan->backend.config));
+       cds_list_add(&lttng_chan_buf->priv->node, &session->priv->chan_head);
+       lttng_chan_buf->priv->header_type = 0;
+       lttng_chan_buf->priv->type = type;
+       /* Copy fields from lttng ust chan config. */
+       lttng_chan_buf->priv->id = lttng_chan_config->id;
+       memcpy(lttng_chan_buf->priv->uuid, lttng_chan_config->uuid, LTTNG_UST_UUID_LEN);
+       channel_set_private(chan, lttng_chan_buf);
 
        /*
         * We tolerate no failure path after channel creation. It will stay
         * invariant for the rest of the session.
         */
-       objd_set_private(chan_objd, lttng_chan);
-       lttng_chan->objd = chan_objd;
+       objd_set_private(chan_objd, lttng_chan_buf);
+       lttng_chan_buf->priv->parent.objd = chan_objd;
        /* The channel created holds a reference on the session */
        objd_ref(session_objd);
        return chan_objd;
@@ -564,11 +583,15 @@ int lttng_abi_map_channel(int session_objd,
        /* error path after channel was created */
 objd_error:
 notransport:
+uuid_error:
 alloc_error:
        channel_destroy(chan, channel_handle, 0);
+       lttng_ust_free_channel_common(lttng_chan_buf->parent);
        return ret;
 
 handle_error:
+       lttng_ust_free_channel_common(lttng_chan_buf->parent);
+lttng_chan_buf_error:
 active:
 invalid:
        return ret;
@@ -691,7 +714,8 @@ objd_error:
 
 static
 long lttng_event_notifier_enabler_cmd(int objd, unsigned int cmd, unsigned long arg,
-               union lttng_ust_abi_args *uargs, void *owner)
+               union lttng_ust_abi_args *uargs __attribute__((unused)),
+               void *owner __attribute__((unused)))
 {
        struct lttng_event_notifier_enabler *event_notifier_enabler = objd_private(objd);
        switch (cmd) {
@@ -732,7 +756,7 @@ long lttng_event_notifier_enabler_cmd(int objd, unsigned int cmd, unsigned long
  */
 static
 long lttng_event_notifier_group_error_counter_cmd(int objd, unsigned int cmd, unsigned long arg,
-       union lttng_ust_abi_args *uargs, void *owner)
+       union lttng_ust_abi_args *uargs, void *owner __attribute__((unused)))
 {
        int ret;
        struct lttng_counter *counter = objd_private(objd);
@@ -762,7 +786,8 @@ long lttng_event_notifier_group_error_counter_cmd(int objd, unsigned int cmd, un
        return ret;
 }
 
-__attribute__((visibility("hidden")))
+int lttng_release_event_notifier_group_error_counter(int objd)
+       __attribute__((visibility("hidden")));
 int lttng_release_event_notifier_group_error_counter(int objd)
 {
        struct lttng_counter *counter = objd_private(objd);
@@ -932,7 +957,8 @@ static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_ops = {
 
 static
 long lttng_tracepoint_list_cmd(int objd, unsigned int cmd, unsigned long arg,
-       union lttng_ust_abi_args *uargs, void *owner)
+       union lttng_ust_abi_args *uargs __attribute__((unused)),
+       void *owner __attribute__((unused)))
 {
        struct lttng_ust_tracepoint_list *list = objd_private(objd);
        struct lttng_ust_abi_tracepoint_iter *tp =
@@ -1012,7 +1038,8 @@ static const struct lttng_ust_abi_objd_ops lttng_tracepoint_list_ops = {
 
 static
 long lttng_tracepoint_field_list_cmd(int objd, unsigned int cmd,
-       unsigned long arg, union lttng_ust_abi_args *uargs, void *owner)
+       unsigned long arg __attribute__((unused)), union lttng_ust_abi_args *uargs,
+       void *owner __attribute__((unused)))
 {
        struct lttng_ust_field_list *list = objd_private(objd);
        struct lttng_ust_abi_field_iter *tp = &uargs->field_list.entry;
@@ -1092,12 +1119,12 @@ static const struct lttng_ust_abi_objd_ops lttng_tracepoint_field_list_ops = {
 
 static
 int lttng_abi_map_stream(int channel_objd, struct lttng_ust_abi_stream *info,
-               union lttng_ust_abi_args *uargs, void *owner)
+               union lttng_ust_abi_args *uargs, void *owner __attribute__((unused)))
 {
-       struct lttng_channel *channel = objd_private(channel_objd);
+       struct lttng_ust_channel_buffer *lttng_chan_buf = objd_private(channel_objd);
        int ret;
 
-       ret = channel_handle_add_stream(channel->handle,
+       ret = channel_handle_add_stream(lttng_chan_buf->priv->rb_chan->handle,
                uargs->stream.shm_fd, uargs->stream.wakeup_fd,
                info->stream_nr, info->len);
        if (ret)
@@ -1118,7 +1145,7 @@ int lttng_abi_create_event_enabler(int channel_objd,
                           void *owner,
                           enum lttng_enabler_format_type format_type)
 {
-       struct lttng_channel *channel = objd_private(channel_objd);
+       struct lttng_ust_channel_buffer *channel = objd_private(channel_objd);
        struct lttng_event_enabler *enabler;
        int event_objd, ret;
 
@@ -1182,13 +1209,13 @@ static
 long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg,
        union lttng_ust_abi_args *uargs, void *owner)
 {
-       struct lttng_channel *channel = objd_private(objd);
+       struct lttng_ust_channel_buffer *lttng_chan_buf = objd_private(objd);
 
        if (cmd != LTTNG_UST_ABI_STREAM) {
                /*
                 * Check if channel received all streams.
                 */
-               if (!lttng_is_channel_ready(channel))
+               if (!lttng_is_channel_ready(lttng_chan_buf))
                        return -EPERM;
        }
 
@@ -1221,13 +1248,14 @@ long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg,
        case LTTNG_UST_ABI_CONTEXT:
                return lttng_abi_add_context(objd,
                                (struct lttng_ust_abi_context *) arg, uargs,
-                               &channel->ctx, channel->session);
+                               &lttng_chan_buf->priv->ctx,
+                               lttng_chan_buf->parent->session);
        case LTTNG_UST_ABI_ENABLE:
-               return lttng_channel_enable(channel);
+               return lttng_channel_enable(lttng_chan_buf->parent);
        case LTTNG_UST_ABI_DISABLE:
-               return lttng_channel_disable(channel);
+               return lttng_channel_disable(lttng_chan_buf->parent);
        case LTTNG_UST_ABI_FLUSH_BUFFER:
-               return channel->ops->priv->flush_buffer(channel->chan, channel->handle);
+               return lttng_chan_buf->ops->priv->flush_buffer(lttng_chan_buf);
        default:
                return -EINVAL;
        }
@@ -1236,10 +1264,10 @@ long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg,
 static
 int lttng_channel_release(int objd)
 {
-       struct lttng_channel *channel = objd_private(objd);
+       struct lttng_ust_channel_buffer *lttng_chan_buf = objd_private(objd);
 
-       if (channel)
-               return lttng_ust_abi_objd_unref(channel->session->priv->objd, 0);
+       if (lttng_chan_buf)
+               return lttng_ust_abi_objd_unref(lttng_chan_buf->parent->session->priv->objd, 0);
        return 0;
 }
 
@@ -1272,7 +1300,8 @@ static const struct lttng_ust_abi_objd_ops lttng_channel_ops = {
  */
 static
 long lttng_event_enabler_cmd(int objd, unsigned int cmd, unsigned long arg,
-       union lttng_ust_abi_args *uargs, void *owner)
+       union lttng_ust_abi_args *uargs __attribute__((unused)),
+       void *owner __attribute__((unused)))
 {
        struct lttng_event_enabler *enabler = objd_private(objd);
 
@@ -1310,7 +1339,7 @@ int lttng_event_enabler_release(int objd)
        struct lttng_event_enabler *event_enabler = objd_private(objd);
 
        if (event_enabler)
-               return lttng_ust_abi_objd_unref(event_enabler->chan->objd, 0);
+               return lttng_ust_abi_objd_unref(event_enabler->chan->priv->parent.objd, 0);
 
        return 0;
 }
This page took 0.028938 seconds and 4 git commands to generate.