sessiond: refactoring: introduce start/stop_kernel_session
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 11 Dec 2019 16:39:59 +0000 (11:39 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 19 Dec 2019 22:32:41 +0000 (17:32 -0500)
The clear feature will need to stop kernel session as well, so move this
code to its own function rather than duplicate it.

start_kernel_session already exists, but is static. Expose it so it
can be used from a separate compile unit.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I68da1ee2e51105278265866590734c320a9789bd
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/cmd.h

index 02a92be1e07e45ba71e4c767ebca0f6a18050ec9..869215b8d920cb7d2a0bd33d22129c34024e199e 100644 (file)
@@ -1260,7 +1260,7 @@ error:
 /*
  * Start a kernel session by opening all necessary streams.
  */
-static int start_kernel_session(struct ltt_kernel_session *ksess)
+int start_kernel_session(struct ltt_kernel_session *ksess)
 {
        int ret;
        struct ltt_kernel_channel *kchan;
@@ -1322,6 +1322,53 @@ error:
        return ret;
 }
 
+int stop_kernel_session(struct ltt_kernel_session *ksess)
+{
+       struct ltt_kernel_channel *kchan;
+       bool error_occurred = false;
+       int ret;
+
+       if (!ksess || !ksess->active) {
+               return LTTNG_OK;
+       }
+       DBG("Stopping kernel tracing");
+
+       ret = kernel_stop_session(ksess);
+       if (ret < 0) {
+               ret = LTTNG_ERR_KERN_STOP_FAIL;
+               goto error;
+       }
+
+       kernel_wait_quiescent();
+
+       /* Flush metadata after stopping (if exists) */
+       if (ksess->metadata_stream_fd >= 0) {
+               ret = kernel_metadata_flush_buffer(ksess->metadata_stream_fd);
+               if (ret < 0) {
+                       ERR("Kernel metadata flush failed");
+                       error_occurred = true;
+               }
+       }
+
+       /* Flush all buffers after stopping */
+       cds_list_for_each_entry(kchan, &ksess->channel_list.head, list) {
+               ret = kernel_flush_buffer(kchan);
+               if (ret < 0) {
+                       ERR("Kernel flush buffer error");
+                       error_occurred = true;
+               }
+       }
+
+       ksess->active = 0;
+       if (error_occurred) {
+               ret = LTTNG_ERR_UNK;
+       } else {
+               ret = LTTNG_OK;
+       }
+error:
+       return ret;
+}
+
 /*
  * Command LTTNG_DISABLE_CHANNEL processed by the client thread.
  */
@@ -2716,14 +2763,12 @@ error:
 int cmd_stop_trace(struct ltt_session *session)
 {
        int ret;
-       struct ltt_kernel_channel *kchan;
        struct ltt_kernel_session *ksession;
        struct ltt_ust_session *usess;
-       bool error_occurred = false;
 
        assert(session);
 
-       DBG("Begin stop session %s (id %" PRIu64 ")", session->name, session->id);
+       DBG("Begin stop session \"%s\" (id %" PRIu64 ")", session->name, session->id);
        /* Short cut */
        ksession = session->kernel_session;
        usess = session->ust_session;
@@ -2734,39 +2779,9 @@ int cmd_stop_trace(struct ltt_session *session)
                goto error;
        }
 
-       /* Kernel tracer */
-       if (ksession && ksession->active) {
-               DBG("Stop kernel tracing");
-
-               ret = kernel_stop_session(ksession);
-               if (ret < 0) {
-                       ret = LTTNG_ERR_KERN_STOP_FAIL;
-                       goto error;
-               }
-
-               kernel_wait_quiescent();
-
-               /* Flush metadata after stopping (if exists) */
-               if (ksession->metadata_stream_fd >= 0) {
-                       ret = kernel_metadata_flush_buffer(ksession->metadata_stream_fd);
-                       if (ret < 0) {
-                               ERR("Kernel metadata flush failed");
-                               error_occurred = true;
-                       }
-               }
-
-               /* Flush all buffers after stopping */
-               cds_list_for_each_entry(kchan, &ksession->channel_list.head, list) {
-                       ret = kernel_flush_buffer(kchan);
-                       if (ret < 0) {
-                               ERR("Kernel flush buffer error");
-                               error_occurred = true;
-                       }
-               }
-
-               ksession->active = 0;
-               DBG("Kernel session stopped %s (id %" PRIu64 ")", session->name,
-                               session->id);
+       ret = stop_kernel_session(ksession);
+       if (ret != LTTNG_OK) {
+               goto error;
        }
 
        if (usess && usess->active) {
@@ -2777,9 +2792,11 @@ int cmd_stop_trace(struct ltt_session *session)
                }
        }
 
+       DBG("Completed stop session \"%s\" (id %" PRIu64 ")", session->name,
+                       session->id);
        /* Flag inactive after a successful stop. */
        session->active = 0;
-       ret = !error_occurred ? LTTNG_OK : LTTNG_ERR_UNK;
+       ret = LTTNG_OK;
 
 error:
        return ret;
index a59bc220fe8109cde78097e562070a87931976a7..87a40c884afda432bc393ae1fd18e1fa1c007747 100644 (file)
@@ -145,5 +145,7 @@ int cmd_rotation_set_schedule(struct ltt_session *session,
                struct notification_thread_handle *notification_thread_handle);
 
 const struct cmd_completion_handler *cmd_pop_completion_handler(void);
+int start_kernel_session(struct ltt_kernel_session *ksess);
+int stop_kernel_session(struct ltt_kernel_session *ksess);
 
 #endif /* CMD_H */
This page took 0.040533 seconds and 5 git commands to generate.