+
+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;
+}