+int relayd_close_trace_chunk(struct lttcomm_relayd_sock *sock,
+ struct lttng_trace_chunk *chunk,
+ char *path)
+{
+ int ret = 0;
+ enum lttng_trace_chunk_status status;
+ struct lttcomm_relayd_close_trace_chunk msg = {};
+ struct lttcomm_relayd_close_trace_chunk_reply reply = {};
+ uint64_t chunk_id;
+ time_t close_timestamp;
+ LTTNG_OPTIONAL(enum lttng_trace_chunk_command_type) close_command = {};
+
+ if (!relayd_supports_chunks(sock)) {
+ DBG("Refusing to close remote trace chunk: relayd does not support chunks");
+ goto end;
+ }
+
+ status = lttng_trace_chunk_get_id(chunk, &chunk_id);
+ if (status != LTTNG_TRACE_CHUNK_STATUS_OK) {
+ ERR("Failed to get trace chunk id");
+ ret = -1;
+ goto end;
+ }
+
+ status = lttng_trace_chunk_get_close_timestamp(chunk, &close_timestamp);
+ if (status != LTTNG_TRACE_CHUNK_STATUS_OK) {
+ ERR("Failed to get trace chunk close timestamp");
+ ret = -1;
+ goto end;
+ }
+
+ status = lttng_trace_chunk_get_close_command(chunk,
+ &close_command.value);
+ switch (status) {
+ case LTTNG_TRACE_CHUNK_STATUS_OK:
+ close_command.is_set = 1;
+ break;
+ case LTTNG_TRACE_CHUNK_STATUS_NONE:
+ break;
+ default:
+ ERR("Failed to get trace chunk close command");
+ ret = -1;
+ goto end;
+ }
+
+ msg = (typeof(msg)){
+ .chunk_id = htobe64(chunk_id),
+ .close_timestamp = htobe64((uint64_t) close_timestamp),
+ .close_command = {
+ .value = htobe32((uint32_t) close_command.value),
+ .is_set = close_command.is_set,
+ },
+ };
+
+ ret = send_command(sock, RELAYD_CLOSE_TRACE_CHUNK, &msg, sizeof(msg),
+ 0);
+ if (ret < 0) {
+ ERR("Failed to send trace chunk close command to relay daemon");
+ goto end;
+ }
+
+ ret = recv_reply(sock, &reply, sizeof(reply));
+ if (ret < 0) {
+ ERR("Failed to receive relay daemon trace chunk close command reply");
+ goto end;
+ }
+
+ reply.path_length = be32toh(reply.path_length);
+ if (reply.path_length >= LTTNG_PATH_MAX) {
+ ERR("Chunk path too long");
+ ret = -1;
+ goto end;
+ }
+
+ ret = recv_reply(sock, path, reply.path_length);
+ if (ret < 0) {
+ ERR("Failed to receive relay daemon trace chunk close command reply");
+ goto end;
+ }
+ if (path[reply.path_length - 1] != '\0') {
+ ERR("Invalid trace chunk path returned by relay daemon (not null-terminated)");
+ ret = -1;
+ goto end;
+ }
+
+ reply.generic.ret_code = be32toh(reply.generic.ret_code);
+ if (reply.generic.ret_code != LTTNG_OK) {
+ ret = -1;
+ ERR("Relayd trace chunk close replied error %d",
+ reply.generic.ret_code);
+ } else {
+ ret = 0;
+ DBG("Relayd successfully closed trace chunk: chunk_id = %" PRIu64,
+ chunk_id);
+ }
+end:
+ return ret;
+}
+
+int relayd_trace_chunk_exists(struct lttcomm_relayd_sock *sock,
+ uint64_t chunk_id, bool *chunk_exists)
+{
+ int ret = 0;
+ struct lttcomm_relayd_trace_chunk_exists msg = {};
+ struct lttcomm_relayd_trace_chunk_exists_reply reply = {};
+
+ if (!relayd_supports_chunks(sock)) {
+ DBG("Refusing to check for trace chunk existence: relayd does not support chunks");
+ /* The chunk will never exist */
+ *chunk_exists = false;
+ goto end;
+ }
+
+ msg = (typeof(msg)){
+ .chunk_id = htobe64(chunk_id),
+ };
+
+ ret = send_command(sock, RELAYD_TRACE_CHUNK_EXISTS, &msg, sizeof(msg),
+ 0);
+ if (ret < 0) {
+ ERR("Failed to send trace chunk exists command to relay daemon");
+ goto end;
+ }
+
+ ret = recv_reply(sock, &reply, sizeof(reply));
+ if (ret < 0) {
+ ERR("Failed to receive relay daemon trace chunk close command reply");
+ goto end;
+ }
+
+ reply.generic.ret_code = be32toh(reply.generic.ret_code);
+ if (reply.generic.ret_code != LTTNG_OK) {
+ ret = -1;
+ ERR("Relayd trace chunk close replied error %d",
+ reply.generic.ret_code);
+ } else {
+ ret = 0;
+ DBG("Relayd successfully checked trace chunk existence: chunk_id = %" PRIu64
+ ", exists = %s", chunk_id,
+ reply.trace_chunk_exists ? "true" : "false");
+ *chunk_exists = !!reply.trace_chunk_exists;
+ }
+end:
+ return ret;
+}
+
+int relayd_get_configuration(struct lttcomm_relayd_sock *sock,
+ uint64_t query_flags,
+ uint64_t *result_flags)
+{
+ int ret = 0;
+ struct lttcomm_relayd_get_configuration msg = (typeof(msg)) {
+ .query_flags = htobe64(query_flags),
+ };
+ struct lttcomm_relayd_get_configuration_reply reply = {};
+
+ if (!relayd_supports_get_configuration(sock)) {
+ DBG("Refusing to get relayd configuration (unsupported by relayd)");
+ if (query_flags) {
+ ret = -1;
+ goto end;
+ }
+ *result_flags = 0;
+ goto end;
+ }
+
+ ret = send_command(sock, RELAYD_GET_CONFIGURATION, &msg, sizeof(msg),
+ 0);
+ if (ret < 0) {
+ ERR("Failed to send get configuration command to relay daemon");
+ goto end;
+ }
+
+ ret = recv_reply(sock, &reply, sizeof(reply));
+ if (ret < 0) {
+ ERR("Failed to receive relay daemon get configuration command reply");
+ goto end;
+ }
+
+ reply.generic.ret_code = be32toh(reply.generic.ret_code);
+ if (reply.generic.ret_code != LTTNG_OK) {
+ ret = -1;
+ ERR("Relayd get configuration replied error %d",
+ reply.generic.ret_code);
+ } else {
+ reply.relayd_configuration_flags =
+ be64toh(reply.relayd_configuration_flags);
+ ret = 0;
+ DBG("Relayd successfully got configuration: query_flags = %" PRIu64
+ ", results_flags = %" PRIu64, query_flags,
+ reply.relayd_configuration_flags);
+ *result_flags = reply.relayd_configuration_flags;
+ }
+end: