move the rename code at the end of the rotation
[deliverable/lttng-tools.git] / src / common / consumer / consumer.c
index 54491b89f37d44aa4f47123ef5bb08f454061f2d..ef69d65a4892a29b40b82954b46d55935c06020c 100644 (file)
@@ -3961,37 +3961,46 @@ int lttng_consumer_rotate_channel(uint64_t key, char *path,
                        ht->hash_fct(&channel->key, lttng_ht_seed),
                        ht->match_fct, &channel->key, &iter.iter,
                        stream, node_channel_id.node) {
+               uint64_t consumed_pos;
+
                health_code_update();
 
                /*
                 * Lock stream because we are about to change its state.
                 */
                pthread_mutex_lock(&stream->lock);
+               ret = utils_mkdir_recursive(channel->pathname, S_IRWXU | S_IRWXG,
+                               stream->uid, stream->gid);
+               if (ret < 0) {
+                       if (errno != EEXIST) {
+                               ERR("Trace directory creation error");
+                               goto end_unlock;
+                       }
+               }
+
                memcpy(stream->channel_ro_pathname, channel->pathname, PATH_MAX);
                ret = lttng_consumer_sample_snapshot_positions(stream);
                if (ret < 0) {
                        ERR("Taking kernel snapshot positions");
                        goto end_unlock;
-               } else {
-                       uint64_t consumed_pos;
+               }
 
-                       ret = lttng_consumer_get_produced_snapshot(stream,
-                                       &stream->rotate_position);
-                       if (ret < 0) {
-                               ERR("Produced kernel snapshot position");
-                               goto end_unlock;
-                       }
-                       fprintf(stderr, "Stream %lu should rotate after %lu to %s\n",
-                                       stream->key, stream->rotate_position,
-                                       channel->pathname);
-                       lttng_consumer_get_consumed_snapshot(stream,
-                                       &consumed_pos);
-                       fprintf(stderr, "consumed %lu\n", consumed_pos);
-                       if (consumed_pos == stream->rotate_position) {
-                               stream->rotate_ready = 1;
-                               fprintf(stderr, "Stream %lu ready to rotate to %s\n",
-                                               stream->key, channel->pathname);
-                       }
+               ret = lttng_consumer_get_produced_snapshot(stream,
+                               &stream->rotate_position);
+               if (ret < 0) {
+                       ERR("Produced kernel snapshot position");
+                       goto end_unlock;
+               }
+               fprintf(stderr, "Stream %lu should rotate after %lu to %s\n",
+                               stream->key, stream->rotate_position,
+                               channel->pathname);
+               lttng_consumer_get_consumed_snapshot(stream,
+                               &consumed_pos);
+               fprintf(stderr, "consumed %lu\n", consumed_pos);
+               if (consumed_pos == stream->rotate_position) {
+                       stream->rotate_ready = 1;
+                       fprintf(stderr, "Stream %lu ready to rotate to %s\n",
+                                       stream->key, channel->pathname);
                }
                channel->nr_stream_rotate_pending++;
 
This page took 0.028974 seconds and 5 git commands to generate.