Validate match of all session channel's UUID
[lttng-ust.git] / liblttng-ust / lttng-ust-abi.c
index 1b21b80e50ea7b1453b126a0becb90eb6a0db033..af2a47dcb5269ac8ec478a75fa18afdfd63fbd2a 100644 (file)
@@ -30,7 +30,6 @@
 #include <urcu/compiler.h>
 #include <urcu/list.h>
 
-#include <ust-helper.h>
 #include <lttng/tracepoint.h>
 #include <lttng/ust-abi.h>
 #include <lttng/ust-error.h>
@@ -47,6 +46,7 @@
 #include "string-utils.h"
 #include "ust-events-internal.h"
 #include "context-internal.h"
+#include "ust-helper.h"
 
 #define OBJ_NAME_LEN   16
 
@@ -287,9 +287,9 @@ 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 channel *chan;
+       struct lttng_ust_lib_ring_buffer_channel *chan;
        unsigned int nr_streams, exp_streams;
 
        chan = lttng_chan->chan;
@@ -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,14 +442,15 @@ 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 channel *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;
        int wakeup_fd;
@@ -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:
@@ -522,7 +534,7 @@ int lttng_abi_map_channel(int session_objd,
                ret = -EINVAL;
                goto notransport;
        }
-       transport = lttng_transport_find(transport_name);
+       transport = lttng_ust_transport_find(transport_name);
        if (!transport) {
                DBG("LTTng transport %s not found\n",
                       transport_name);
@@ -537,26 +549,33 @@ 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->ops = &transport->ops;
+       lttng_chan_buf->chan = chan;
+       lttng_chan_buf->handle = channel_handle;
+
+       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;
@@ -597,7 +620,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 +656,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);
@@ -762,7 +785,7 @@ long lttng_event_notifier_group_error_counter_cmd(int objd, unsigned int cmd, un
        return ret;
 }
 
-LTTNG_HIDDEN
+__attribute__((visibility("hidden")))
 int lttng_release_event_notifier_group_error_counter(int objd)
 {
        struct lttng_counter *counter = objd_private(objd);
@@ -1094,10 +1117,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->handle,
                uargs->stream.shm_fd, uargs->stream.wakeup_fd,
                info->stream_nr, info->len);
        if (ret)
@@ -1118,7 +1141,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 +1205,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 +1244,15 @@ 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->chan,
+                               lttng_chan_buf->handle);
        default:
                return -EINVAL;
        }
@@ -1236,10 +1261,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 +1335,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.02891 seconds and 4 git commands to generate.