sessiond: implement kernel clear session
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 12 Dec 2019 16:34:10 +0000 (11:34 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 19 Dec 2019 23:07:50 +0000 (18:07 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ie47c128fc951b206c7ae50933395e9ade9d0012d
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/kernel.c
src/bin/lttng-sessiond/kernel.h

index 93afc9d6fb25e795aab694bc77b9ace813c5aacb..1f987ef7d365a2890146d5c5cccdc1f3cf72660a 100644 (file)
@@ -1647,3 +1647,83 @@ bool kernel_tracer_is_initialized(void)
 {
        return kernel_tracer_fd >= 0;
 }
+
+/*
+ *  Clear a kernel session.
+ *
+ * Return LTTNG_OK on success or else an LTTng error code.
+ */
+enum lttng_error_code kernel_clear_session(struct ltt_session *session)
+{
+       int ret;
+       enum lttng_error_code status = LTTNG_OK;
+       struct consumer_socket *socket;
+       struct lttng_ht_iter iter;
+       struct ltt_kernel_session *ksess = session->kernel_session;
+
+       assert(ksess);
+       assert(ksess->consumer);
+
+       DBG("Clear kernel session %s (session %" PRIu64 ")",
+                       session->name, session->id);
+
+       rcu_read_lock();
+
+       if (ksess->active) {
+               ERR("Expecting inactive session %s (%" PRIu64 ")", session->name, session->id);
+               status = LTTNG_ERR_FATAL;
+               goto end;
+       }
+
+       /*
+        * Note that this loop will end after one iteration given that there is
+        * only one kernel consumer.
+        */
+       cds_lfht_for_each_entry(ksess->consumer->socks->ht, &iter.iter,
+                       socket, node.node) {
+               struct ltt_kernel_channel *chan;
+
+               /* For each channel, ask the consumer to clear it. */
+               cds_list_for_each_entry(chan, &ksess->channel_list.head, list) {
+                       DBG("Clear kernel channel %" PRIu64 ", session %s",
+                                       chan->key, session->name);
+                       ret = consumer_clear_channel(socket, chan->key);
+                       if (ret < 0) {
+                               goto error;
+                       }
+               }
+
+               if (!ksess->metadata) {
+                       /*
+                        * Nothing to do for the metadata.
+                        * This is a snapshot session.
+                        * The metadata is genererated on the fly.
+                        */
+                       continue;
+               }
+
+               /*
+                * Clear the metadata channel.
+                * Metadata channel is not cleared per se but we still need to
+                * perform a rotation operation on it behind the scene.
+                */
+               ret = consumer_clear_channel(socket, ksess->metadata->key);
+               if (ret < 0) {
+                       goto error;
+               }
+       }
+
+       goto end;
+error:
+       switch (-ret) {
+       case LTTCOMM_CONSUMERD_RELAYD_CLEAR_DISALLOWED:
+             status = LTTNG_ERR_CLEAR_RELAY_DISALLOWED;
+             break;
+       default:
+             status = LTTNG_ERR_CLEAR_FAIL_CONSUMER;
+             break;
+       }
+end:
+       rcu_read_unlock();
+       return status;
+}
index fe14589b7f3e0f3ff637858857d1bc7f8ca6b671..16a70124d33b0ac35f3d0fe9b6f92b1038bd4901 100644 (file)
@@ -65,6 +65,7 @@ enum lttng_error_code kernel_snapshot_record(
                uint64_t nb_packets_per_stream);
 int kernel_syscall_mask(int chan_fd, char **syscall_mask, uint32_t *nr_bits);
 enum lttng_error_code kernel_rotate_session(struct ltt_session *session);
+enum lttng_error_code kernel_clear_session(struct ltt_session *session);
 
 int init_kernel_workarounds(void);
 ssize_t kernel_list_tracker_pids(struct ltt_kernel_session *session,
This page took 0.049384 seconds and 4 git commands to generate.