Fix: tls-compat with hidden ring buffer context
[lttng-ust.git] / liblttng-ust / lttng-ust-abi.c
index 7953176335a6e0c4f9c30b2ec28d798fb790f5fd..df404de77e76d5a1c876a27e9a6c34819bc637b4 100644 (file)
@@ -287,13 +287,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;
 }
@@ -301,7 +301,7 @@ int lttng_is_channel_ready(struct lttng_channel *lttng_chan)
 static
 int lttng_abi_create_session(void *owner)
 {
-       struct lttng_session *session;
+       struct lttng_ust_session *session;
        int session_objd, ret;
 
        session = lttng_session_create();
@@ -379,7 +379,7 @@ static
 long lttng_abi_add_context(int objd,
        struct lttng_ust_abi_context *context_param,
        union lttng_ust_abi_args *uargs,
-       struct lttng_ctx **ctx, struct lttng_session *session)
+       struct lttng_ust_ctx **ctx, struct lttng_ust_session *session)
 {
        return lttng_attach_context(context_param, uargs, ctx, session);
 }
@@ -442,13 +442,14 @@ int lttng_abi_map_channel(int session_objd,
                union lttng_ust_abi_args *uargs,
                void *owner)
 {
-       struct lttng_session *session = objd_private(session_objd);
+       struct lttng_ust_session *session = objd_private(session_objd);
        const char *transport_name;
-       const struct lttng_transport *transport;
+       struct lttng_transport *transport;
        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 +476,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 +496,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 +549,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 +582,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;
@@ -597,7 +619,7 @@ static
 long lttng_session_cmd(int objd, unsigned int cmd, unsigned long arg,
        union lttng_ust_abi_args *uargs, void *owner)
 {
-       struct lttng_session *session = objd_private(objd);
+       struct lttng_ust_session *session = objd_private(objd);
 
        switch (cmd) {
        case LTTNG_UST_ABI_CHANNEL:
@@ -633,7 +655,7 @@ long lttng_session_cmd(int objd, unsigned int cmd, unsigned long arg,
 static
 int lttng_release_session(int objd)
 {
-       struct lttng_session *session = objd_private(objd);
+       struct lttng_ust_session *session = objd_private(objd);
 
        if (session) {
                lttng_session_destroy(session);
@@ -1094,10 +1116,10 @@ static
 int lttng_abi_map_stream(int channel_objd, struct lttng_ust_abi_stream *info,
                union lttng_ust_abi_args *uargs, void *owner)
 {
-       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 +1140,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 +1204,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 +1243,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->flush_buffer(channel->chan, channel->handle);
+               return lttng_chan_buf->ops->priv->flush_buffer(lttng_chan_buf);
        default:
                return -EINVAL;
        }
@@ -1236,10 +1259,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;
 }
 
@@ -1310,7 +1333,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.026626 seconds and 4 git commands to generate.