Change trace_path to session_root_path and chunk_path
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index a9dff558cbb22940bd6bc75c2041c3e6952c858a..9112cd14e39cf37cafb1d904d3bada5042cfe00b 100644 (file)
@@ -92,6 +92,7 @@ static void copy_channel_attr_to_ustctl(
        attr->switch_timer_interval = uattr->switch_timer_interval;
        attr->read_timer_interval = uattr->read_timer_interval;
        attr->output = uattr->output;
+       attr->blocking_timeout = uattr->u.s.blocking_timeout;
 }
 
 /*
@@ -1040,6 +1041,7 @@ struct ust_app_channel *alloc_ust_app_channel(char *name,
                ua_chan->attr.switch_timer_interval = attr->switch_timer_interval;
                ua_chan->attr.read_timer_interval = attr->read_timer_interval;
                ua_chan->attr.output = attr->output;
+               ua_chan->attr.blocking_timeout = attr->u.s.blocking_timeout;
        }
        /* By default, the channel is a per cpu channel. */
        ua_chan->attr.type = LTTNG_UST_CHAN_PER_CPU;
@@ -1803,6 +1805,8 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan,
        ua_chan->attr.read_timer_interval = uchan->attr.read_timer_interval;
        ua_chan->monitor_timer_interval = uchan->monitor_timer_interval;
        ua_chan->attr.output = uchan->attr.output;
+       ua_chan->attr.blocking_timeout = uchan->attr.u.s.blocking_timeout;
+
        /*
         * Note that the attribute channel type is not set since the channel on the
         * tracing registry side does not have this information.
@@ -2361,7 +2365,7 @@ int create_ust_app_channel_context(struct ust_app_session *ua_sess,
        ua_ctx = alloc_ust_app_ctx(uctx);
        if (ua_ctx == NULL) {
                /* malloc failed */
-               ret = -1;
+               ret = -ENOMEM;
                goto error;
        }
 
@@ -2841,6 +2845,8 @@ error:
 /*
  * Create and send to the application the created buffers with per UID buffers.
  *
+ * This MUST be called with a RCU read side lock acquired.
+ *
  * Return 0 on success else a negative value.
  */
 static int create_channel_per_uid(struct ust_app *app,
@@ -2913,22 +2919,12 @@ static int create_channel_per_uid(struct ust_app *app,
                created = true;
        }
 
-       /* Send buffers to the application. */
-       ret = send_channel_uid_to_ust(reg_chan, app, ua_sess, ua_chan);
-       if (ret < 0) {
-               if (ret != -ENOTCONN) {
-                       ERR("Error sending channel to application");
-               }
-               goto error;
-       }
-
        if (created) {
                enum lttng_error_code cmd_ret;
                struct ltt_session *session;
                uint64_t chan_reg_key;
                struct ust_registry_channel *chan_reg;
 
-               rcu_read_lock();
                chan_reg_key = ua_chan->tracing_channel_id;
 
                pthread_mutex_lock(&reg_uid->registry->reg.ust->lock);
@@ -2949,7 +2945,6 @@ static int create_channel_per_uid(struct ust_app *app,
                                ua_chan->key,
                                LTTNG_DOMAIN_UST,
                                ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf);
-               rcu_read_unlock();
                if (cmd_ret != LTTNG_OK) {
                        ret = - (int) cmd_ret;
                        ERR("Failed to add channel to notification thread");
@@ -2957,6 +2952,15 @@ static int create_channel_per_uid(struct ust_app *app,
                }
        }
 
+       /* Send buffers to the application. */
+       ret = send_channel_uid_to_ust(reg_chan, app, ua_sess, ua_chan);
+       if (ret < 0) {
+               if (ret != -ENOTCONN) {
+                       ERR("Error sending channel to application");
+               }
+               goto error;
+       }
+
 error:
        return ret;
 }
@@ -3573,8 +3577,8 @@ void ust_app_unregister(int sock)
        /*
         * Remove application from notify hash table. The thread handling the
         * notify socket could have deleted the node so ignore on error because
-        * either way it's valid. The close of that socket is handled by the other
-        * thread.
+        * either way it's valid. The close of that socket is handled by the
+        * apps_notify_thread.
         */
        iter.iter.node = &lta->notify_sock_n.node;
        (void) lttng_ht_del(ust_app_ht_by_notify_sock, &iter);
@@ -4413,9 +4417,32 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
 
        /* Create directories if consumer is LOCAL and has a path defined. */
        if (usess->consumer->type == CONSUMER_DST_LOCAL &&
-                       strlen(usess->consumer->dst.trace_path) > 0) {
-               ret = run_as_mkdir_recursive(usess->consumer->dst.trace_path,
-                               S_IRWXU | S_IRWXG, ua_sess->euid, ua_sess->egid);
+                       usess->consumer->dst.session_root_path[0] != '\0') {
+               char *tmp_path;
+
+               tmp_path = zmalloc(PATH_MAX * sizeof(char));
+               if (!tmp_path) {
+                       ERR("Alloc tmp_path");
+                       goto error_unlock;
+               }
+               ret = snprintf(tmp_path, PATH_MAX, "%s%s%s",
+                               usess->consumer->dst.session_root_path,
+                               usess->consumer->chunk_path,
+                               usess->consumer->subdir);
+               if (ret >= PATH_MAX) {
+                       ERR("Local destination path exceeds the maximal allowed length of %i bytes (needs %i bytes) with path = \"%s%s%s\"",
+                                       PATH_MAX, ret,
+                                       usess->consumer->dst.session_root_path,
+                                       usess->consumer->chunk_path,
+                                       usess->consumer->subdir);
+                       goto error_unlock;
+               }
+
+               DBG("Creating directory path for local tracing: \"%s\"",
+                               tmp_path);
+               ret = run_as_mkdir_recursive(tmp_path, S_IRWXU | S_IRWXG,
+                               ua_sess->euid, ua_sess->egid);
+               free(tmp_path);
                if (ret < 0) {
                        if (errno != EEXIST) {
                                ERR("Trace directory creation error");
@@ -6111,21 +6138,24 @@ int ust_app_uid_get_channel_runtime_stats(uint64_t ust_session_id,
        int ret;
        uint64_t consumer_chan_key;
 
+       *discarded = 0;
+       *lost = 0;
+
        ret = buffer_reg_uid_consumer_channel_key(
                        buffer_reg_uid_list, ust_session_id,
                        uchan_id, &consumer_chan_key);
        if (ret < 0) {
+               /* Not found */
+               ret = 0;
                goto end;
        }
 
        if (overwrite) {
                ret = consumer_get_lost_packets(ust_session_id,
                                consumer_chan_key, consumer, lost);
-               *discarded = 0;
        } else {
                ret = consumer_get_discarded_events(ust_session_id,
                                consumer_chan_key, consumer, discarded);
-               *lost = 0;
        }
 
 end:
@@ -6144,10 +6174,13 @@ int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session *usess,
        struct ust_app_session *ua_sess;
        struct ust_app_channel *ua_chan;
 
+       *discarded = 0;
+       *lost = 0;
+
        rcu_read_lock();
        /*
-        * Iterate over every registered applications, return when we
-        * found one in the right session and channel.
+        * Iterate over every registered applications. Sum counters for
+        * all applications containing requested session and channel.
         */
        cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                struct lttng_ht_iter uiter;
@@ -6166,19 +6199,26 @@ int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session *usess,
                ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
 
                if (overwrite) {
+                       uint64_t _lost;
+
                        ret = consumer_get_lost_packets(usess->id, ua_chan->key,
-                                       consumer, lost);
-                       *discarded = 0;
-                       goto end;
+                                       consumer, &_lost);
+                       if (ret < 0) {
+                               break;
+                       }
+                       (*lost) += _lost;
                } else {
+                       uint64_t _discarded;
+
                        ret = consumer_get_discarded_events(usess->id,
-                                       ua_chan->key, consumer, discarded);
-                       *lost = 0;
-                       goto end;
+                                       ua_chan->key, consumer, &_discarded);
+                       if (ret < 0) {
+                               break;
+                       }
+                       (*discarded) += _discarded;
                }
        }
 
-end:
        rcu_read_unlock();
        return ret;
 }
This page took 0.028866 seconds and 4 git commands to generate.