From c7496bc7efafa45857abc6b3e97862256b3aec61 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 3 Apr 2019 16:34:27 -0400 Subject: [PATCH] sessiond: Implement clear for sessions with local and remote output Signed-off-by: Mathieu Desnoyers --- src/bin/lttng-sessiond/clear.c | 43 +++++++++--------- src/bin/lttng-sessiond/consumer.c | 74 ++++++++++++++++++++++++++++--- src/bin/lttng-sessiond/consumer.h | 2 + src/bin/lttng-sessiond/ust-app.c | 2 +- 4 files changed, 95 insertions(+), 26 deletions(-) diff --git a/src/bin/lttng-sessiond/clear.c b/src/bin/lttng-sessiond/clear.c index a0917dca8..e83818dc0 100644 --- a/src/bin/lttng-sessiond/clear.c +++ b/src/bin/lttng-sessiond/clear.c @@ -41,28 +41,21 @@ int cmd_clear_session(struct ltt_session *session) goto end; } - /* - * Unsupported feature in lttng-relayd before 2.12. - */ - if (session->consumer->type == CONSUMER_DST_NET && - (session->consumer->relay_major_version == 2 && - session->consumer->relay_minor_version < 12)) { - ret = LTTNG_ERR_CLEAR_NOT_AVAILABLE_RELAY; - goto end; - } - - /* TODO: Should we check for disallowed here or consumer side? */ - - /* Snapshot session are the only one supported for now */ - if (!session->snapshot_mode) { - /* - * TODO: this error code is temporary and will be removed since - * we will be supporting all session type - */ - ret = LTTNG_ERR_CLEAR_NOT_AVAILABLE; - goto end; + if (session->ust_session) { + switch (session->ust_session->buffer_type) { + case LTTNG_BUFFER_PER_PID: + ERR("Clear command not supported for per-pid buffers."); + ret = LTTNG_ERR_CLEAR_NOT_AVAILABLE; + goto error; + case LTTNG_BUFFER_PER_UID: + case LTTNG_BUFFER_GLOBAL: + break; + } } + /* + * Clear kernel and UST session buffers and local files (if any). + */ if (session->kernel_session) { ret = kernel_clear_session(session); if (ret != LTTNG_OK) { @@ -75,6 +68,16 @@ int cmd_clear_session(struct ltt_session *session) goto error; } } + + /* + * Clear remote (relayd) session files. + */ + ret = consumer_clear_session(session); + if (ret < 0) { + ret = LTTNG_ERR_CLEAR_FAIL_CONSUMER; + goto error; + } + ret = LTTNG_OK; error: end: return ret; diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 382815e6b..f286df943 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -1588,11 +1588,36 @@ int consumer_clear_channel(struct consumer_socket *socket, uint64_t key, msg.cmd_type = LTTNG_CONSUMER_CLEAR_CHANNEL; msg.u.clear_channel.key = key; - if (output->type == CONSUMER_DST_NET) { - ERR("Relayd clear is not supported for now"); - ret = -LTTNG_ERR_INVALID; - goto error; + health_code_update(); + + pthread_mutex_lock(socket->lock); + ret = consumer_send_msg(socket, &msg); + if (ret < 0) { + goto error_socket; } + +error_socket: + pthread_mutex_unlock(socket->lock); + + health_code_update(); + return ret; +} + +static +int consumer_msg_clear_session(struct consumer_socket *socket, uint64_t session_id, + struct consumer_output *output) +{ + int ret; + struct lttcomm_consumer_msg msg; + + assert(socket); + + DBG("Consumer clear session %" PRIu64, session_id); + + memset(&msg, 0, sizeof(msg)); + msg.cmd_type = LTTNG_CONSUMER_CLEAR_SESSION; + msg.u.clear_session.session_id = session_id; + health_code_update(); pthread_mutex_lock(socket->lock); @@ -1604,7 +1629,46 @@ int consumer_clear_channel(struct consumer_socket *socket, uint64_t key, error_socket: pthread_mutex_unlock(socket->lock); -error: health_code_update(); return ret; } + +int consumer_clear_session(struct ltt_session *session) +{ + struct ltt_ust_session *usess = session->ust_session; + struct ltt_kernel_session *ksess = session->kernel_session; + int ret; + + rcu_read_lock(); + if (ksess) { + struct consumer_socket *socket; + struct lttng_ht_iter iter; + + cds_lfht_for_each_entry(ksess->consumer->socks->ht, &iter.iter, + socket, node.node) { + ret = consumer_msg_clear_session(socket, session->id, + ksess->consumer); + if (ret < 0) { + goto error; + } + } + } + if (usess) { + struct consumer_socket *socket; + struct lttng_ht_iter iter; + + cds_lfht_for_each_entry(usess->consumer->socks->ht, &iter.iter, + socket, node.node) { + ret = consumer_msg_clear_session(socket, session->id, + usess->consumer); + if (ret < 0) { + goto error; + } + } + } + rcu_read_unlock(); + return 0; +error: + rcu_read_unlock(); + return ret; +} diff --git a/src/bin/lttng-sessiond/consumer.h b/src/bin/lttng-sessiond/consumer.h index f81a328f8..1ce682523 100644 --- a/src/bin/lttng-sessiond/consumer.h +++ b/src/bin/lttng-sessiond/consumer.h @@ -27,6 +27,7 @@ struct snapshot; struct snapshot_output; +struct ltt_session; enum consumer_dst_type { CONSUMER_DST_LOCAL, @@ -308,4 +309,5 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key, /* Clear command */ int consumer_clear_channel(struct consumer_socket *socket, uint64_t key, struct consumer_output *output); +int consumer_clear_session(struct ltt_session *session); #endif /* _CONSUMER_H */ diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 81edd21c2..ffe6c80cc 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -6366,7 +6366,7 @@ enum lttng_error_code ust_app_clear_session(struct ltt_session *session) continue; } - /* Rotate the data channels. */ + /* Clear the data channels. */ cds_lfht_for_each_entry(ua_sess->channels->ht, &chan_iter.iter, ua_chan, node.node) { ret = consumer_clear_channel(socket, ua_chan->key, -- 2.34.1