From: Jérémie Galarneau Date: Wed, 12 Dec 2018 21:16:26 +0000 (-0500) Subject: Add a consumer daemon INIT command X-Git-Tag: v2.11.0-rc3~136 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=fc181d72878019621cdf417659beefacebb90c68;p=lttng-tools.git Add a consumer daemon INIT command This commit adds an INIT commands which allows the session daemon to provide its UUID as soon as the consumer daemon is started. The name of this command is generic since other attributes may need to be passed at the initialization of a consumer daemon. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 12db236d0..336c76071 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -1894,3 +1894,27 @@ error: health_code_update(); return ret; } + +int consumer_init(struct consumer_socket *socket, + const lttng_uuid sessiond_uuid) +{ + int ret; + struct lttcomm_consumer_msg msg = { + .cmd_type = LTTNG_CONSUMER_INIT, + }; + + assert(socket); + + DBG("Sending consumer initialization command"); + lttng_uuid_copy(msg.u.init.sessiond_uuid, sessiond_uuid); + + health_code_update(); + ret = consumer_send_msg(socket, &msg); + if (ret < 0) { + goto error; + } + +error: + health_code_update(); + return ret; +} diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index e49ed94d1..32a2d7a4a 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -4485,3 +4485,21 @@ int lttng_consumer_mkdir(const char *path, uid_t uid, gid_t gid, return mkdir_local(path, uid, gid); } } + +enum lttcomm_return_code lttng_consumer_init_command( + struct lttng_consumer_local_data *ctx, + const lttng_uuid sessiond_uuid) +{ + enum lttcomm_return_code ret; + + if (ctx->sessiond_uuid.is_set) { + ret = LTTCOMM_CONSUMERD_ALREADY_SET; + goto end; + } + + ctx->sessiond_uuid.is_set = true; + memcpy(ctx->sessiond_uuid.value, sessiond_uuid, sizeof(lttng_uuid)); + ret = LTTCOMM_CONSUMERD_SUCCESS; +end: + return ret; +} diff --git a/src/common/consumer/consumer.h b/src/common/consumer/consumer.h index 0c757b84f..83196444b 100644 --- a/src/common/consumer/consumer.h +++ b/src/common/consumer/consumer.h @@ -69,6 +69,7 @@ enum lttng_consumer_command { LTTNG_CONSUMER_CHECK_ROTATION_PENDING_LOCAL, LTTNG_CONSUMER_CHECK_ROTATION_PENDING_RELAY, LTTNG_CONSUMER_MKDIR, + LTTNG_CONSUMER_INIT, }; /* State of each fd in consumer */ @@ -600,6 +601,7 @@ struct lttng_consumer_local_data { * to the session daemon (write-only). */ int channel_monitor_pipe; + LTTNG_OPTIONAL(lttng_uuid) sessiond_uuid; }; /* @@ -863,5 +865,8 @@ void lttng_consumer_reset_stream_rotate_state(struct lttng_consumer_stream *stre int lttng_consumer_mkdir(const char *path, uid_t uid, gid_t gid, uint64_t relayd_id); void lttng_consumer_cleanup_relayd(struct consumer_relayd_sock_pair *relayd); +enum lttcomm_return_code lttng_consumer_init_command( + struct lttng_consumer_local_data *ctx, + const lttng_uuid sessiond_uuid); #endif /* LIB_CONSUMER_H */ diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 627cd2a8b..74c6de399 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -1260,6 +1260,19 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, } break; } + case LTTNG_CONSUMER_INIT: + { + ret_code = lttng_consumer_init_command(ctx, + msg.u.init.sessiond_uuid); + + health_code_update(); + ret = consumer_send_status_msg(sock, ret_code); + if (ret < 0) { + /* Somehow, the session daemon is not responding anymore. */ + goto end_nosignal; + } + break; + } default: goto end_nosignal; } diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 94b761cb8..4d1737726 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -2109,6 +2109,19 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, } break; } + case LTTNG_CONSUMER_INIT: + { + ret_code = lttng_consumer_init_command(ctx, + msg.u.init.sessiond_uuid); + + health_code_update(); + ret = consumer_send_status_msg(sock, ret_code); + if (ret < 0) { + /* Somehow, the session daemon is not responding anymore. */ + goto end_nosignal; + } + break; + } default: break; }