* Returns 0 on success or else a negative code which is either -ENOMEM or
* -ENOTCONN which is the default code if the ustctl_create_session fails.
*/
-static int create_ust_app_session(struct ltt_ust_session *usess,
+static int find_or_create_ust_app_session(struct ltt_ust_session *usess,
struct ust_app *app, struct ust_app_session **ua_sess_ptr,
int *is_created)
{
* Create and send to the application the created buffers with per UID buffers.
*
* This MUST be called with a RCU read side lock acquired.
+ * The session list lock and the session's lock must be acquired.
*
* Return 0 on success else a negative value.
*/
int ret;
struct buffer_reg_uid *reg_uid;
struct buffer_reg_channel *reg_chan;
- bool created = false;
assert(app);
assert(usess);
reg_chan = buffer_reg_channel_find(ua_chan->tracing_channel_id,
reg_uid);
- if (!reg_chan) {
- /* Create the buffer registry channel object. */
- ret = create_buffer_reg_channel(reg_uid->registry, ua_chan, ®_chan);
- if (ret < 0) {
- ERR("Error creating the UST channel \"%s\" registry instance",
- ua_chan->name);
- goto error;
- }
- assert(reg_chan);
+ if (reg_chan) {
+ goto send_channel;
+ }
- /*
- * Create the buffers on the consumer side. This call populates the
- * ust app channel object with all streams and data object.
- */
- ret = do_consumer_create_channel(usess, ua_sess, ua_chan,
- app->bits_per_long, reg_uid->registry->reg.ust);
- if (ret < 0) {
- ERR("Error creating UST channel \"%s\" on the consumer daemon",
+ /* Create the buffer registry channel object. */
+ ret = create_buffer_reg_channel(reg_uid->registry, ua_chan, ®_chan);
+ if (ret < 0) {
+ ERR("Error creating the UST channel \"%s\" registry instance",
ua_chan->name);
+ goto error;
+ }
- /*
- * Let's remove the previously created buffer registry channel so
- * it's not visible anymore in the session registry.
- */
- ust_registry_channel_del_free(reg_uid->registry->reg.ust,
- ua_chan->tracing_channel_id, false);
- buffer_reg_channel_remove(reg_uid->registry, reg_chan);
- buffer_reg_channel_destroy(reg_chan, LTTNG_DOMAIN_UST);
- goto error;
- }
+ /*
+ * Create the buffers on the consumer side. This call populates the
+ * ust app channel object with all streams and data object.
+ */
+ ret = do_consumer_create_channel(usess, ua_sess, ua_chan,
+ app->bits_per_long, reg_uid->registry->reg.ust);
+ if (ret < 0) {
+ ERR("Error creating UST channel \"%s\" on the consumer daemon",
+ ua_chan->name);
/*
- * Setup the streams and add it to the session registry.
+ * Let's remove the previously created buffer registry channel so
+ * it's not visible anymore in the session registry.
*/
- ret = setup_buffer_reg_channel(reg_uid->registry,
- ua_chan, reg_chan, app);
- if (ret < 0) {
- ERR("Error setting up UST channel \"%s\"",
- ua_chan->name);
- goto error;
- }
- created = true;
+ ust_registry_channel_del_free(reg_uid->registry->reg.ust,
+ ua_chan->tracing_channel_id, false);
+ buffer_reg_channel_remove(reg_uid->registry, reg_chan);
+ buffer_reg_channel_destroy(reg_chan, LTTNG_DOMAIN_UST);
+ goto error;
}
- if (created) {
+ /*
+ * Setup the streams and add it to the session registry.
+ */
+ ret = setup_buffer_reg_channel(reg_uid->registry,
+ ua_chan, reg_chan, app);
+ if (ret < 0) {
+ ERR("Error setting up UST channel \"%s\"", ua_chan->name);
+ goto error;
+ }
+
+ {
enum lttng_error_code cmd_ret;
struct ltt_session *session;
uint64_t chan_reg_key;
session = session_find_by_id(ua_sess->tracing_id);
assert(session);
+ assert(pthread_mutex_trylock(&session->lock));
+ assert(session_trylock_list());
cmd_ret = notification_thread_command_add_channel(
notification_thread_handle, session->name,
ua_sess->euid, ua_sess->egid,
}
}
+send_channel:
/* Send buffers to the application. */
ret = send_channel_uid_to_ust(reg_chan, app, ua_sess, ua_chan);
if (ret < 0) {
* Create and send to the application the created buffers with per PID buffers.
*
* Called with UST app session lock held.
+ * The session list lock and the session's lock must be acquired.
*
* Return 0 on success else a negative value.
*/
chan_reg->consumer_key = ua_chan->key;
pthread_mutex_unlock(®istry->lock);
+ assert(pthread_mutex_trylock(&session->lock));
+ assert(session_trylock_list());
+
cmd_ret = notification_thread_command_add_channel(
notification_thread_handle, session->name,
ua_sess->euid, ua_sess->egid,
* that if session exist, it will simply return a pointer to the ust
* app session.
*/
- ret = create_ust_app_session(usess, app, &ua_sess, &created);
+ ret = find_or_create_ust_app_session(usess, app, &ua_sess, &created);
if (ret < 0) {
switch (ret) {
case -ENOTCONN:
struct ust_app_ctx *ua_ctx;
int is_created = 0;
- ret = create_ust_app_session(usess, app, &ua_sess, &is_created);
+ ret = find_or_create_ust_app_session(usess, app, &ua_sess, &is_created);
if (ret < 0) {
/* Tracer is probably gone or ENOMEM. */
goto error;
*lost = 0;
ret = buffer_reg_uid_consumer_channel_key(
- buffer_reg_uid_list, ust_session_id,
- uchan_id, &consumer_chan_key);
+ buffer_reg_uid_list, uchan_id, &consumer_chan_key);
if (ret < 0) {
/* Not found */
ret = 0;
reg->registry->reg.ust->metadata_key,
LTTNG_DOMAIN_UST, session);
if (ret < 0) {
- ret = LTTNG_ERR_KERN_CONSUMER_FAIL;
+ ret = reg->bits_per_long == 32 ?
+ -LTTNG_ERR_UST_CONSUMER32_FAIL :
+ -LTTNG_ERR_UST_CONSUMER64_FAIL;
goto error;
}
reg_chan->consumer_key,
LTTNG_DOMAIN_UST, session);
if (ret < 0) {
- ret = LTTNG_ERR_KERN_CONSUMER_FAIL;
+ ret = reg->bits_per_long == 32 ?
+ -LTTNG_ERR_UST_CONSUMER32_FAIL :
+ -LTTNG_ERR_UST_CONSUMER64_FAIL;
goto error;
}
ret = consumer_rotate_channel(socket,
usess->uid, usess->gid,
usess->consumer, pathname,
/* is_metadata_channel */ false,
- session->rotate_count,
+ session->current_archive_id,
&session->rotate_pending_relay);
if (ret < 0) {
goto error;
usess->uid, usess->gid,
usess->consumer, pathname,
/* is_metadata_channel */ true,
- session->rotate_count,
+ session->current_archive_id,
&session->rotate_pending_relay);
if (ret < 0) {
goto error;
ret = rotate_add_channel_pending(registry->metadata_key,
LTTNG_DOMAIN_UST, session);
if (ret < 0) {
- ret = LTTNG_ERR_KERN_CONSUMER_FAIL;
+ ret = app->bits_per_long == 32 ?
+ -LTTNG_ERR_UST_CONSUMER32_FAIL :
+ -LTTNG_ERR_UST_CONSUMER64_FAIL;
goto error;
}
ua_chan->key, LTTNG_DOMAIN_UST,
session);
if (ret < 0) {
- ret = LTTNG_ERR_KERN_CONSUMER_FAIL;
+ ret = app->bits_per_long == 32 ?
+ -LTTNG_ERR_UST_CONSUMER32_FAIL :
+ -LTTNG_ERR_UST_CONSUMER64_FAIL;
goto error;
}
ret = consumer_rotate_channel(socket, ua_chan->key,
ua_sess->euid, ua_sess->egid,
ua_sess->consumer, pathname,
/* is_metadata_channel */ false,
- session->rotate_count,
+ session->current_archive_id,
&session->rotate_pending_relay);
if (ret < 0) {
goto error;
ua_sess->euid, ua_sess->egid,
ua_sess->consumer, pathname,
/* is_metadata_channel */ true,
- session->rotate_count,
+ session->current_archive_id,
&session->rotate_pending_relay);
if (ret < 0) {
goto error;