send the rotate pending to the relay
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.c
index 4a7287b61ba78f46365b76ffc1fd011525d82064..f901466f8d96e9f35590506b829e436a4d9bcd03 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;
@@ -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)
 {
@@ -851,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));
 
@@ -1080,6 +1083,35 @@ 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.
@@ -1403,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) {
@@ -1413,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) {
@@ -1557,3 +1590,144 @@ end:
        rcu_read_unlock();
        return ret;
 }
+
+/*
+ * Ask the consumer to rotate a channel.
+ * app_pathname only used for UST, it contains the path after /ust/.
+ *
+ * The new_chunk_id is the session->rotate_count that has been incremented
+ * when the rotation started. On the relay, this allows to keep track in which
+ * chunk each stream is currently writing to (for the rotate_pending operation).
+ */
+int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key,
+               uid_t uid, gid_t gid, struct consumer_output *output,
+               char *app_pathname, uint32_t metadata, uint64_t new_chunk_id,
+               bool *rotate_pending_relay)
+{
+       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;
+       msg.u.rotate_channel.new_chunk_id = new_chunk_id;
+
+       if (output->type == CONSUMER_DST_NET) {
+               fprintf(stderr, "BASE: %s\n", output->dst.net.base_dir);
+               fprintf(stderr, "CHUNK: %s\n", output->chunk_path);
+               msg.u.rotate_channel.relayd_id = output->net_seq_index;
+               snprintf(msg.u.rotate_channel.pathname, PATH_MAX, "%s%s%s",
+                               output->dst.net.base_dir,
+                               output->chunk_path, app_pathname);
+               fprintf(stderr, "SENDING: %s\n", msg.u.rotate_channel.pathname);
+               *rotate_pending_relay = true;
+       } 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, app_pathname);
+               fprintf(stderr, "rotate to %s\n",
+                               msg.u.rotate_channel.pathname);
+       }
+
+       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;
+}
+
+int consumer_rotate_rename(struct consumer_socket *socket, uint64_t session_id,
+               struct consumer_output *output, char *current_path, char *new_path,
+               uid_t uid, gid_t gid)
+{
+       int ret;
+       struct lttcomm_consumer_msg msg;
+
+       assert(socket);
+
+       DBG("Consumer rotate rename session %" PRIu64, session_id);
+
+       memset(&msg, 0, sizeof(msg));
+       msg.cmd_type = LTTNG_CONSUMER_ROTATE_RENAME;
+       msg.u.rotate_rename.session_id = session_id;
+       msg.u.rotate_rename.uid = uid;
+       msg.u.rotate_rename.gid = gid;
+       snprintf(msg.u.rotate_rename.current_path, PATH_MAX, "%s", current_path);
+       snprintf(msg.u.rotate_rename.new_path, PATH_MAX, "%s", new_path);
+
+       if (output->type == CONSUMER_DST_NET) {
+               msg.u.rotate_rename.relayd_id = output->net_seq_index;
+       } else {
+               msg.u.rotate_rename.relayd_id = (uint64_t) -1ULL;
+       }
+
+       health_code_update();
+       ret = consumer_send_msg(socket, &msg);
+       if (ret < 0) {
+               goto error;
+       }
+
+error:
+       health_code_update();
+       return ret;
+}
+
+/*
+ * Ask the relay if a rotation is still pending. Must be called with the socket
+ * lock held.
+ *
+ * Return 1 if the rotation is still pending, 0 if finished, a negative value
+ * on error.
+ */
+int consumer_rotate_pending_relay(struct consumer_socket *socket,
+               struct consumer_output *output, uint64_t session_id,
+               uint64_t chunk_id)
+{
+       int ret;
+       struct lttcomm_consumer_msg msg;
+       int32_t ret_code = 0;
+
+       assert(socket);
+
+       DBG("Consumer rotate pending on relay for session %" PRIu64, session_id);
+       assert(output->type == CONSUMER_DST_NET);
+
+       memset(&msg, 0, sizeof(msg));
+       msg.cmd_type = LTTNG_CONSUMER_ROTATE_PENDING_RELAY;
+       msg.u.rotate_pending_relay.session_id = session_id;
+       msg.u.rotate_pending_relay.relayd_id = output->net_seq_index;
+       msg.u.rotate_pending_relay.chunk_id = chunk_id;
+
+       health_code_update();
+       ret = consumer_send_msg(socket, &msg);
+       if (ret < 0) {
+               goto error;
+       }
+
+       /*
+        * No need for a recv reply status because the answer to the command is
+        * the reply status message.
+        */
+       ret = consumer_socket_recv(socket, &ret_code, sizeof(ret_code));
+       if (ret < 0) {
+               goto error;
+       }
+
+       ret = ret_code;
+
+error:
+       health_code_update();
+       return ret;
+}
This page took 0.030426 seconds and 5 git commands to generate.