Basic structure for the rotate command
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.c
index 934af39bd3f6028b69138765b39c22401e6dbfbe..54f8804d667b7b0c935b171c23cce203c205bc89 100644 (file)
@@ -715,11 +715,12 @@ int consumer_set_network_uri(struct consumer_output *obj,
                        goto error;
                }
 
-               if (lttng_strncpy(obj->subdir, tmp_path, sizeof(obj->subdir))) {
+               if (lttng_strncpy(obj->dst.net.base_dir, tmp_path,
+                                       sizeof(obj->dst.net.base_dir))) {
                        ret = -LTTNG_ERR_INVALID;
                        goto error;
                }
-               DBG3("Consumer set network uri subdir path %s", tmp_path);
+               DBG3("Consumer set network uri base_dir path %s", tmp_path);
        }
 
        return 0;
@@ -748,7 +749,6 @@ int consumer_send_fds(struct consumer_socket *sock, int *fds, size_t nb_fd)
        }
 
        ret = consumer_recv_status_reply(sock);
-
 error:
        return ret;
 }
@@ -806,6 +806,7 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
                unsigned int switch_timer_interval,
                unsigned int read_timer_interval,
                unsigned int live_timer_interval,
+               unsigned int monitor_timer_interval,
                int output,
                int type,
                uint64_t session_id,
@@ -822,6 +823,7 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
                uint64_t session_id_per_pid,
                unsigned int monitor,
                uint32_t ust_app_uid,
+               int64_t blocking_timeout,
                const char *root_shm_path,
                const char *shm_path)
 {
@@ -837,6 +839,7 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
        msg->u.ask_channel.switch_timer_interval = switch_timer_interval;
        msg->u.ask_channel.read_timer_interval = read_timer_interval;
        msg->u.ask_channel.live_timer_interval = live_timer_interval;
+       msg->u.ask_channel.monitor_timer_interval = monitor_timer_interval;
        msg->u.ask_channel.output = output;
        msg->u.ask_channel.type = type;
        msg->u.ask_channel.session_id = session_id;
@@ -850,6 +853,7 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
        msg->u.ask_channel.tracefile_count = tracefile_count;
        msg->u.ask_channel.monitor = monitor;
        msg->u.ask_channel.ust_app_uid = ust_app_uid;
+       msg->u.ask_channel.blocking_timeout = blocking_timeout;
 
        memcpy(msg->u.ask_channel.uuid, uuid, sizeof(msg->u.ask_channel.uuid));
 
@@ -892,7 +896,8 @@ void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg *msg,
                uint64_t tracefile_size,
                uint64_t tracefile_count,
                unsigned int monitor,
-               unsigned int live_timer_interval)
+               unsigned int live_timer_interval,
+               unsigned int monitor_timer_interval)
 {
        assert(msg);
 
@@ -913,6 +918,7 @@ void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg *msg,
        msg->u.channel.tracefile_count = tracefile_count;
        msg->u.channel.monitor = monitor;
        msg->u.channel.live_timer_interval = live_timer_interval;
+       msg->u.channel.monitor_timer_interval = monitor_timer_interval;
 
        strncpy(msg->u.channel.pathname, pathname,
                        sizeof(msg->u.channel.pathname));
@@ -1048,6 +1054,64 @@ error:
        return ret;
 }
 
+int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock,
+               int pipe)
+{
+       int ret;
+       struct lttcomm_consumer_msg msg;
+
+       /* Code flow error. Safety net. */
+
+       memset(&msg, 0, sizeof(msg));
+       msg.cmd_type = LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE;
+
+       DBG3("Sending set_channel_monitor_pipe command to consumer");
+       ret = consumer_send_msg(consumer_sock, &msg);
+       if (ret < 0) {
+               goto error;
+       }
+
+       DBG3("Sending channel monitoring pipe %d to consumer on socket %d",
+                       pipe, *consumer_sock->fd_ptr);
+       ret = consumer_send_fds(consumer_sock, &pipe, 1);
+       if (ret < 0) {
+               goto error;
+       }
+
+       DBG2("Channel monitoring pipe successfully sent");
+error:
+       return ret;
+}
+
+int consumer_send_channel_rotate_pipe(struct consumer_socket *consumer_sock,
+               int pipe)
+{
+       int ret;
+       struct lttcomm_consumer_msg msg;
+
+       /* Code flow error. Safety net. */
+
+       memset(&msg, 0, sizeof(msg));
+       msg.cmd_type = LTTNG_CONSUMER_SET_CHANNEL_ROTATE_PIPE;
+
+       DBG3("Sending set_channel_rotate_pipe command to consumer");
+       ret = consumer_send_msg(consumer_sock, &msg);
+       if (ret < 0) {
+               goto error;
+       }
+
+       DBG3("Sending channel rotation pipe %d to consumer on socket %d",
+                       pipe, *consumer_sock->fd_ptr);
+       ret = consumer_send_fds(consumer_sock, &pipe, 1);
+       if (ret < 0) {
+               goto error;
+       }
+
+       DBG2("Channel rotation pipe successfully sent");
+error:
+       return ret;
+}
+
 /*
  * Set consumer subdirectory using the session name and a generated datetime if
  * needed. This is appended to the current subdirectory.
@@ -1191,6 +1255,38 @@ end:
        return ret;
 }
 
+/*
+ * Send a clear quiescent command to consumer using the given channel key.
+ *
+ * Return 0 on success else a negative value.
+ */
+int consumer_clear_quiescent_channel(struct consumer_socket *socket, uint64_t key)
+{
+       int ret;
+       struct lttcomm_consumer_msg msg;
+
+       assert(socket);
+
+       DBG2("Consumer clear quiescent channel key %" PRIu64, key);
+
+       memset(&msg, 0, sizeof(msg));
+       msg.cmd_type = LTTNG_CONSUMER_CLEAR_QUIESCENT_CHANNEL;
+       msg.u.clear_quiescent_channel.key = key;
+
+       pthread_mutex_lock(socket->lock);
+       health_code_update();
+
+       ret = consumer_send_msg(socket, &msg);
+       if (ret < 0) {
+               goto end;
+       }
+
+end:
+       health_code_update();
+       pthread_mutex_unlock(socket->lock);
+       return ret;
+}
+
 /*
  * Send a close metadata command to consumer using the given channel key.
  * Called with registry lock held.
@@ -1339,7 +1435,8 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key,
                msg.u.snapshot_channel.use_relayd = 1;
                ret = snprintf(msg.u.snapshot_channel.pathname,
                                sizeof(msg.u.snapshot_channel.pathname),
-                               "%s/%s-%s-%" PRIu64 "%s", output->consumer->subdir,
+                               "%s/%s/%s-%s-%" PRIu64 "%s", output->consumer->dst.net.base_dir,
+                               output->consumer->subdir,
                                output->name, output->datetime, output->nb_snapshot,
                                session_path);
                if (ret < 0) {
@@ -1349,7 +1446,7 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key,
        } else {
                ret = snprintf(msg.u.snapshot_channel.pathname,
                                sizeof(msg.u.snapshot_channel.pathname),
-                               "%s/%s-%s-%" PRIu64 "%s", output->consumer->dst.trace_path,
+                               "%s/%s-%s-%" PRIu64 "%s", output->consumer->dst.session_root_path,
                                output->name, output->datetime, output->nb_snapshot,
                                session_path);
                if (ret < 0) {
@@ -1493,3 +1590,67 @@ end:
        rcu_read_unlock();
        return ret;
 }
+
+int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key,
+               uid_t uid, gid_t gid, struct consumer_output *output,
+               char *tmp, uint32_t metadata)
+{
+       int ret;
+       struct lttcomm_consumer_msg msg;
+
+       assert(socket);
+
+       DBG("Consumer rotate channel key %" PRIu64, key);
+
+       fprintf(stderr, "rotate socket %p\n", socket);
+       memset(&msg, 0, sizeof(msg));
+       msg.cmd_type = LTTNG_CONSUMER_ROTATE_CHANNEL;
+       msg.u.rotate_channel.key = key;
+       msg.u.rotate_channel.metadata = metadata;
+
+       if (output->type == CONSUMER_DST_NET) {
+               ERR("TODO");
+               ret = -1;
+               goto error;
+               /*
+               msg.u.rotate_channel.relayd_id = output->consumer->net_seq_index;
+               ret = snprintf(msg.u.rotate_channel.pathname,
+                               sizeof(msg.u.rotate_channel.pathname),
+                               "%s/%s-%s-%" PRIu64 "%s", output->consumer->subdir,
+                               output->name, output->datetime, output->nb_rotate,
+                               session_path);
+               if (ret < 0) {
+                       ret = -LTTNG_ERR_NOMEM;
+                       goto error;
+               }
+               */
+       } else {
+               msg.u.rotate_channel.relayd_id = (uint64_t) -1ULL;
+               snprintf(msg.u.rotate_channel.pathname, PATH_MAX, "%s/%s/%s",
+                               output->dst.session_root_path,
+                               output->chunk_path, tmp);
+               fprintf(stderr, "rotate to %s\n",
+                               msg.u.rotate_channel.pathname);
+
+               /* Create directory. Ignore if exist. */
+               ret = run_as_mkdir_recursive(msg.u.rotate_channel.pathname,
+                               S_IRWXU | S_IRWXG, uid, gid);
+               if (ret < 0) {
+                       if (errno != EEXIST) {
+                               ERR("Trace directory creation error");
+                               goto error;
+                       }
+               }
+       }
+
+       health_code_update();
+       fprintf(stderr, "send %d\n", LTTNG_CONSUMER_ROTATE_CHANNEL);
+       ret = consumer_send_msg(socket, &msg);
+       if (ret < 0) {
+               goto error;
+       }
+
+error:
+       health_code_update();
+       return ret;
+}
This page took 0.043005 seconds and 5 git commands to generate.