From db1da059574b86008035b12968446863ab6de866 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 19 Jul 2019 18:54:10 -0400 Subject: [PATCH] Send session creation time to relay daemon when supported MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit A recent commit changed the way the creation timestamp was added to a session's output path; the session creation timestamp is now (2.11+) sampled at creation time and formatted when the session's output directory is created. The 2.11+ version of the session and stream creation commands allow the relay daemon to use all components of the path independently to format an output path rather than relying on the session daemon peer to format it ahead of time. In order to maintain the timestamped session folder name created by previous versions, the relay daemon now receives the session's creation timestamp and formats it rather than relying on it being "cooked" into the transmitted session name. Signed-off-by: Jérémie Galarneau --- src/bin/lttng-relayd/cmd-2-11.c | 5 ++++- src/bin/lttng-relayd/cmd-2-11.h | 3 ++- src/bin/lttng-relayd/main.c | 22 +++++++++++++++------- src/bin/lttng-relayd/session.c | 16 ++++++++++++---- src/bin/lttng-relayd/session.h | 14 ++++++++++---- src/bin/lttng-sessiond/cmd.c | 20 ++++++++++++-------- src/bin/lttng-sessiond/consumer.c | 6 ++++-- src/bin/lttng-sessiond/consumer.h | 3 ++- src/common/relayd/relayd.c | 10 +++++++--- src/common/relayd/relayd.h | 3 ++- src/common/sessiond-comm/relayd.h | 4 +++- 11 files changed, 73 insertions(+), 33 deletions(-) diff --git a/src/bin/lttng-relayd/cmd-2-11.c b/src/bin/lttng-relayd/cmd-2-11.c index 363e0f000..7d90be9f9 100644 --- a/src/bin/lttng-relayd/cmd-2-11.c +++ b/src/bin/lttng-relayd/cmd-2-11.c @@ -33,7 +33,8 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload, char *session_name, char *hostname, uint32_t *live_timer, bool *snapshot, uint64_t *id_sessiond, lttng_uuid sessiond_uuid, - bool *has_current_chunk, uint64_t *current_chunk_id) + bool *has_current_chunk, uint64_t *current_chunk_id, + time_t *creation_time) { int ret; struct lttcomm_relayd_create_session_2_11 header; @@ -56,6 +57,7 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload, header.live_timer = be32toh(header.live_timer); header.current_chunk_id.value = be64toh(header.current_chunk_id.value); header.current_chunk_id.is_set = !!header.current_chunk_id.is_set; + header.creation_time = be64toh(header.creation_time); lttng_uuid_copy(sessiond_uuid, header.sessiond_uuid); @@ -108,6 +110,7 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload, *snapshot = !!header.snapshot; *current_chunk_id = header.current_chunk_id.value; *has_current_chunk = header.current_chunk_id.is_set; + *creation_time = (time_t) header.creation_time; ret = 0; diff --git a/src/bin/lttng-relayd/cmd-2-11.h b/src/bin/lttng-relayd/cmd-2-11.h index 7961d91ff..d2af45817 100644 --- a/src/bin/lttng-relayd/cmd-2-11.h +++ b/src/bin/lttng-relayd/cmd-2-11.h @@ -25,7 +25,8 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload, char *session_name, char *hostname, uint32_t *live_timer, bool *snapshot, uint64_t *id_sessiond, lttng_uuid sessiond_uuid, - bool *has_current_chunk, uint64_t *current_chunk_id); + bool *has_current_chunk, uint64_t *current_chunk_id, + time_t *creation_time); int cmd_recv_stream_2_11(const struct lttng_buffer_view *payload, char **ret_path_name, char **ret_channel_name, diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index b5ae34ebf..c0e9d76df 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -1104,6 +1104,7 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr, lttng_uuid sessiond_uuid = {}; LTTNG_OPTIONAL(uint64_t) id_sessiond = {}; LTTNG_OPTIONAL(uint64_t) current_chunk_id = {}; + LTTNG_OPTIONAL(time_t) creation_time = {}; if (conn->minor < 4) { /* From 2.1 to 2.3 */ @@ -1114,21 +1115,27 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr, hostname, &live_timer, &snapshot); } else { bool has_current_chunk; + uint64_t current_chunk_id_value; + time_t creation_time_value; + uint64_t id_sessiond_value; /* From 2.11 to ... */ - ret = cmd_create_session_2_11(payload, session_name, - hostname, &live_timer, &snapshot, - &id_sessiond.value, sessiond_uuid, - &has_current_chunk, - ¤t_chunk_id.value); + ret = cmd_create_session_2_11(payload, session_name, hostname, + &live_timer, &snapshot, &id_sessiond_value, + sessiond_uuid, &has_current_chunk, + ¤t_chunk_id_value, &creation_time_value); if (lttng_uuid_is_nil(sessiond_uuid)) { /* The nil UUID is reserved for pre-2.11 clients. */ ERR("Illegal nil UUID announced by peer in create session command"); ret = -1; goto send_reply; } - id_sessiond.is_set = true; - current_chunk_id.is_set = has_current_chunk; + LTTNG_OPTIONAL_SET(&id_sessiond, id_sessiond_value); + LTTNG_OPTIONAL_SET(&creation_time, creation_time_value); + if (has_current_chunk) { + LTTNG_OPTIONAL_SET(¤t_chunk_id, + current_chunk_id_value); + } } if (ret < 0) { @@ -1139,6 +1146,7 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr, snapshot, sessiond_uuid, id_sessiond.is_set ? &id_sessiond.value : NULL, current_chunk_id.is_set ? ¤t_chunk_id.value : NULL, + creation_time.is_set ? &creation_time.value : NULL, conn->major, conn->minor); if (!session) { ret = -1; diff --git a/src/bin/lttng-relayd/session.c b/src/bin/lttng-relayd/session.c index e087b51c3..fa211fe02 100644 --- a/src/bin/lttng-relayd/session.c +++ b/src/bin/lttng-relayd/session.c @@ -74,10 +74,15 @@ end: * Return allocated session or else NULL. */ struct relay_session *session_create(const char *session_name, - const char *hostname, uint32_t live_timer, - bool snapshot, const lttng_uuid sessiond_uuid, - uint64_t *id_sessiond, uint64_t *current_chunk_id, - uint32_t major, uint32_t minor) + const char *hostname, + uint32_t live_timer, + bool snapshot, + const lttng_uuid sessiond_uuid, + const uint64_t *id_sessiond, + const uint64_t *current_chunk_id, + const time_t *creation_time, + uint32_t major, + uint32_t minor) { int ret; struct relay_session *session; @@ -156,6 +161,9 @@ struct relay_session *session_create(const char *session_name, } lttng_ht_add_unique_u64(sessions_ht, &session->session_n); + if (creation_time) { + LTTNG_OPTIONAL_SET(&session->creation_time, *creation_time); + } return session; error: diff --git a/src/bin/lttng-relayd/session.h b/src/bin/lttng-relayd/session.h index 8c679da9c..8b8ae1f21 100644 --- a/src/bin/lttng-relayd/session.h +++ b/src/bin/lttng-relayd/session.h @@ -52,6 +52,7 @@ struct relay_session { * the other cases. */ lttng_uuid sessiond_uuid; + LTTNG_OPTIONAL(time_t) creation_time; char session_name[LTTNG_NAME_MAX]; char hostname[LTTNG_HOST_NAME_MAX]; uint32_t live_timer; @@ -123,10 +124,15 @@ struct relay_session { }; struct relay_session *session_create(const char *session_name, - const char *hostname, uint32_t live_timer, - bool snapshot, const lttng_uuid sessiond_uuid, - uint64_t *id_sessiond, uint64_t *current_chunk_id, - uint32_t major, uint32_t minor); + const char *hostname, + uint32_t live_timer, + bool snapshot, + const lttng_uuid sessiond_uuid, + const uint64_t *id_sessiond, + const uint64_t *current_chunk_id, + const time_t *creation_time, + uint32_t major, + uint32_t minor); struct relay_session *session_get_by_id(uint64_t id); bool session_get(struct relay_session *session); void session_put(struct relay_session *session); diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 6e5128917..5e1a59a50 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1039,7 +1039,8 @@ static enum lttng_error_code send_consumer_relayd_socket( struct consumer_socket *consumer_sock, const char *session_name, const char *hostname, int session_live_timer, - const uint64_t *current_chunk_id) + const uint64_t *current_chunk_id, + time_t session_creation_time) { int ret; struct lttcomm_relayd_sock *rsock = NULL; @@ -1068,7 +1069,7 @@ static enum lttng_error_code send_consumer_relayd_socket( ret = consumer_send_relayd_socket(consumer_sock, rsock, consumer, relayd_uri->stype, session_id, session_name, hostname, session_live_timer, - current_chunk_id); + current_chunk_id, session_creation_time); if (ret < 0) { status = LTTNG_ERR_ENABLE_CONSUMER_FAIL; goto close_sock; @@ -1116,7 +1117,7 @@ static enum lttng_error_code send_consumer_relayd_sockets( unsigned int session_id, struct consumer_output *consumer, struct consumer_socket *sock, const char *session_name, const char *hostname, int session_live_timer, - const uint64_t *current_chunk_id) + const uint64_t *current_chunk_id, time_t session_creation_time) { enum lttng_error_code status = LTTNG_OK; @@ -1128,7 +1129,7 @@ static enum lttng_error_code send_consumer_relayd_sockets( status = send_consumer_relayd_socket(session_id, &consumer->dst.net.control, consumer, sock, session_name, hostname, session_live_timer, - current_chunk_id); + current_chunk_id, session_creation_time); if (status != LTTNG_OK) { goto error; } @@ -1139,7 +1140,7 @@ static enum lttng_error_code send_consumer_relayd_sockets( status = send_consumer_relayd_socket(session_id, &consumer->dst.net.data, consumer, sock, session_name, hostname, session_live_timer, - current_chunk_id); + current_chunk_id, session_creation_time); if (status != LTTNG_OK) { goto error; } @@ -1195,7 +1196,8 @@ int cmd_setup_relayd(struct ltt_session *session) usess->consumer, socket, session->name, session->hostname, session->live_timer, - current_chunk_id.is_set ? ¤t_chunk_id.value : NULL); + current_chunk_id.is_set ? ¤t_chunk_id.value : NULL, + session->creation_time); pthread_mutex_unlock(socket->lock); if (ret != LTTNG_OK) { goto error; @@ -1218,7 +1220,8 @@ int cmd_setup_relayd(struct ltt_session *session) ksess->consumer, socket, session->name, session->hostname, session->live_timer, - current_chunk_id.is_set ? ¤t_chunk_id.value : NULL); + current_chunk_id.is_set ? ¤t_chunk_id.value : NULL, + session->creation_time); pthread_mutex_unlock(socket->lock); if (ret != LTTNG_OK) { goto error; @@ -4243,7 +4246,8 @@ static enum lttng_error_code set_relayd_for_snapshot( snap_output->consumer, socket, session->name, session->hostname, session->live_timer, - current_chunk_id.is_set ? ¤t_chunk_id.value : NULL); + current_chunk_id.is_set ? ¤t_chunk_id.value : NULL, + session->creation_time); pthread_mutex_unlock(socket->lock); if (status != LTTNG_OK) { rcu_read_unlock(); diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 155f2b053..10152864e 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -1079,7 +1079,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock, struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer, enum lttng_stream_type type, uint64_t session_id, const char *session_name, const char *hostname, - int session_live_timer, const uint64_t *current_chunk_id) + int session_live_timer, const uint64_t *current_chunk_id, + time_t session_creation_time) { int ret; struct lttcomm_consumer_msg msg; @@ -1101,7 +1102,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock, &msg.u.relayd_sock.relayd_session_id, session_name, hostname, session_live_timer, consumer->snapshot, session_id, - sessiond_uuid, current_chunk_id); + sessiond_uuid, current_chunk_id, + session_creation_time); if (ret < 0) { /* Close the control socket. */ (void) relayd_close(rsock); diff --git a/src/bin/lttng-sessiond/consumer.h b/src/bin/lttng-sessiond/consumer.h index 13ebcd035..59585eda3 100644 --- a/src/bin/lttng-sessiond/consumer.h +++ b/src/bin/lttng-sessiond/consumer.h @@ -219,7 +219,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock, struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer, enum lttng_stream_type type, uint64_t session_id, const char *session_name, const char *hostname, - int session_live_timer, const uint64_t *current_chunk_id); + int session_live_timer, const uint64_t *current_chunk_id, + time_t session_creation_time); int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock, int pipe); int consumer_send_destroy_relayd(struct consumer_socket *sock, diff --git a/src/common/relayd/relayd.c b/src/common/relayd/relayd.c index 830c7c263..87782e994 100644 --- a/src/common/relayd/relayd.c +++ b/src/common/relayd/relayd.c @@ -130,7 +130,8 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock, const char *session_name, const char *hostname, int session_live_timer, unsigned int snapshot, uint64_t sessiond_session_id, const lttng_uuid sessiond_uuid, - const uint64_t *current_chunk_id) + const uint64_t *current_chunk_id, + time_t creation_time) { int ret; struct lttcomm_relayd_create_session_2_11 *msg = NULL; @@ -176,6 +177,8 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock, htobe64(*current_chunk_id)); } + msg->creation_time = htobe64((uint64_t) creation_time); + /* Send command */ ret = send_command(rsock, RELAYD_CREATE_SESSION, msg, msg_length, 0); if (ret < 0) { @@ -248,7 +251,8 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock, int session_live_timer, unsigned int snapshot, uint64_t sessiond_session_id, const lttng_uuid sessiond_uuid, - const uint64_t *current_chunk_id) + const uint64_t *current_chunk_id, + time_t creation_time) { int ret; struct lttcomm_relayd_status_session reply; @@ -270,7 +274,7 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock, ret = relayd_create_session_2_11(rsock, session_name, hostname, session_live_timer, snapshot, sessiond_session_id, sessiond_uuid, - current_chunk_id); + current_chunk_id, creation_time); } if (ret < 0) { diff --git a/src/common/relayd/relayd.h b/src/common/relayd/relayd.h index eb7782de0..033189bf1 100644 --- a/src/common/relayd/relayd.h +++ b/src/common/relayd/relayd.h @@ -32,7 +32,8 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock, int session_live_timer, unsigned int snapshot, uint64_t sessiond_session_id, const lttng_uuid sessiond_uuid, - const uint64_t *current_chunk_id); + const uint64_t *current_chunk_id, + time_t creation_time); int relayd_add_stream(struct lttcomm_relayd_sock *sock, const char *channel_name, const char *pathname, uint64_t *stream_id, uint64_t tracefile_size, uint64_t tracefile_count, diff --git a/src/common/sessiond-comm/relayd.h b/src/common/sessiond-comm/relayd.h index 1568f5113..2ae94b365 100644 --- a/src/common/sessiond-comm/relayd.h +++ b/src/common/sessiond-comm/relayd.h @@ -212,7 +212,9 @@ struct lttcomm_relayd_create_session_2_11 { lttng_uuid sessiond_uuid; /* Sessiond session id */ uint64_t session_id; - LTTNG_OPTIONAL_COMM(uint64_t) current_chunk_id; + /* Session creation time, in seconds since UNIX Epoch. */ + uint64_t creation_time; + LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED current_chunk_id; /* Contains the session_name and hostname */ char names[]; } LTTNG_PACKED; -- 2.34.1