]> git.efficios.com Git - deliverable/lttng-tools.git/commitdiff
CLI: Add lttng_trace_format_descriptor to lttng_session_extended
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 25 Apr 2022 17:43:45 +0000 (13:43 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 19 Aug 2022 16:05:36 +0000 (12:05 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Change-Id: Ib51f94036df5137419797a1b1a484ac4c7f2fc59

include/lttng/session-internal.hpp
include/lttng/session.h
src/bin/lttng-sessiond/cmd.cpp
src/common/session.cpp
src/lib/lttng-ctl/liblttng-ctl.sym

index b56ab214cb268c5042545b02512633d5baa49711..52edf4d3dcf36097824fd498cad4aa381df96c9b 100644 (file)
 #include <common/optional.hpp>
 #include <lttng/constant.h>
 #include <lttng/lttng-error.h>
+#include <lttng/trace-format-descriptor-internal.hpp>
 
 struct lttng_session;
 struct lttng_payload_view;
 
 struct lttng_session_extended {
        LTTNG_OPTIONAL(uint64_t) creation_time;
+       /*
+        * This is done this way to satisfy the API memory restriction for lttng_session on listing.
+        * The caller must be able to simply call free on the return object and all memory be freed.
+        */
+       struct lttng_buffer_view serialized_trace_format_descriptor;
 };
 
 struct lttng_session_comm {
@@ -27,12 +33,14 @@ struct lttng_session_comm {
        uint8_t enabled;
        uint32_t snapshot_mode;
        uint32_t live_timer_interval;
+       uint32_t trace_format_descriptor_len;
        /* lttng_session_extended data */
        LTTNG_OPTIONAL(uint64_t) LTTNG_PACKED creation_time;
        /*
         * Dynamic payload:
         *   - name[name_len]
         *   - path[path_len]
+        *   - trace_format_descriptor
         */
        char payload[];
 } LTTNG_PACKED;
index 153a37b03680da361e97f0f64bdee979ae16c6fe..7ef03e54e253744da3c1b85971ed24d8ed58a700 100644 (file)
@@ -208,6 +208,24 @@ LTTNG_EXPORT extern enum lttng_error_code lttng_session_get_creation_time(
 LTTNG_EXPORT extern int lttng_set_session_shm_path(const char *session_name,
                const char *shm_path);
 
+/*
+ * Get the trace format descriptor of an lttng_session object on the session daemon.
+ *
+ * This function must only be used with lttng_session objects returned
+ * by lttng_list_sessions() or lttng_session_create().
+ *
+ * The returned object is a copy of the session trace_format_descriptor for
+ * backward compatibility purpose.
+ *
+ * The returned object must be freed by using lttng_trace_format_descriptor_delete.
+ *
+ * Returns LTTNG_OK on success. See lttng-error.h for the meaning of the other
+ * return codes.
+ */
+LTTNG_EXPORT extern enum lttng_error_code lttng_session_get_trace_format_descriptor(
+               const struct lttng_session *session,
+               struct lttng_trace_format_descriptor **p_lttng_trace_format_descriptor);
+
 #ifdef __cplusplus
 }
 #endif
index b519f9e70e54ad7ce32e1f1205b4750f800006bf..214085c55a29bd11c4f548db101eb64e6c488989 100644 (file)
@@ -4055,10 +4055,13 @@ enum lttng_error_code cmd_list_lttng_sessions(
        cds_list_for_each_entry(session, &list->head, list) {
                struct lttng_session tmp_session = {};
                struct lttng_session_extended tmp_extended = {};
+               struct lttng_payload trace_format_buffer;
+               lttng_payload_init(&trace_format_buffer);
 
                tmp_session.extended.ptr = &tmp_extended;
 
                if (!session_get(session)) {
+                       lttng_payload_reset(&trace_format_buffer);
                        continue;
                }
                /*
@@ -4067,6 +4070,7 @@ enum lttng_error_code cmd_list_lttng_sessions(
                if (!session_access_ok(session, uid) ||
                                session->destroyed) {
                        session_put(session);
+                       lttng_payload_reset(&trace_format_buffer);
                        continue;
                }
 
@@ -4088,13 +4092,19 @@ enum lttng_error_code cmd_list_lttng_sessions(
                        continue;
                }
 
+               session->trace_format->serialize(&trace_format_buffer);
+
                strncpy(tmp_session.name, session->name, NAME_MAX);
                tmp_session.name[NAME_MAX - 1] = '\0';
                tmp_session.enabled = session->active;
                tmp_session.snapshot_mode = session->snapshot_mode;
                tmp_session.live_timer_interval = session->live_timer;
                LTTNG_OPTIONAL_SET(&tmp_extended.creation_time, (uint64_t) session->creation_time);
+               tmp_extended.serialized_trace_format_descriptor =
+                               lttng_buffer_view_from_dynamic_buffer(&trace_format_buffer.buffer,
+                                               0, trace_format_buffer.buffer.size);
                ret = lttng_session_serialize(&tmp_session, reply_payload);
+               lttng_payload_reset(&trace_format_buffer);
                if (ret) {
                        ret_code = LTTNG_ERR_FATAL;
                        goto error;
index 0af62f7a7783d897a749a9301f6c551eea6c505f..dbd77fad80d7ddd98f1b3467b397b40265bc5f5f 100644 (file)
@@ -63,6 +63,8 @@ int lttng_session_serialize(const struct lttng_session *session, lttng_payload *
        session_comm.enabled = (uint8_t) session->enabled;
        session_comm.snapshot_mode = session->snapshot_mode;
        session_comm.live_timer_interval = session->live_timer_interval;
+       session_comm.trace_format_descriptor_len =
+                       extended->serialized_trace_format_descriptor.size;
        if (extended->creation_time.is_set) {
                LTTNG_OPTIONAL_SET(&session_comm.creation_time,
                                LTTNG_OPTIONAL_GET(extended->creation_time));
@@ -88,6 +90,14 @@ int lttng_session_serialize(const struct lttng_session *session, lttng_payload *
                goto end;
        }
 
+       /* Serialized trace_format_descriptor */
+       ret = lttng_dynamic_buffer_append(&payload->buffer,
+                       extended->serialized_trace_format_descriptor.data,
+                       extended->serialized_trace_format_descriptor.size);
+       if (ret) {
+               goto end;
+       }
+
 end:
        return ret;
 }
@@ -117,8 +127,9 @@ ssize_t lttng_session_create_from_payload(
                offset += sizeof(*session_comm);
        }
 
-       local_session = zmalloc<struct lttng_session>(
-                       sizeof(struct lttng_session) + sizeof(struct lttng_session_extended));
+       local_session = zmalloc<struct lttng_session>(sizeof(struct lttng_session) +
+                       sizeof(struct lttng_session_extended) +
+                       (size_t) session_comm->trace_format_descriptor_len);
        if (local_session == nullptr) {
                ret = -1;
                goto end;
@@ -131,6 +142,12 @@ ssize_t lttng_session_create_from_payload(
                goto end;
        }
 
+       /* Set the view for serialized_trace_format_descriptor */
+       local_extended->serialized_trace_format_descriptor =
+                       lttng_buffer_view_init(reinterpret_cast<const char *>(local_extended),
+                                       sizeof(struct lttng_session_extended),
+                                       (size_t) session_comm->trace_format_descriptor_len);
+
        local_session->extended.ptr = local_extended;
 
        local_session->enabled = session_comm->enabled;
@@ -192,6 +209,20 @@ ssize_t lttng_session_create_from_payload(
 
                offset += session_comm->path_len;
        }
+       {
+               const struct lttng_buffer_view trace_format_view = lttng_buffer_view_from_view(
+                               &view->buffer, offset, session_comm->trace_format_descriptor_len);
+
+               if (!lttng_buffer_view_is_valid(&trace_format_view)) {
+                       ret = -1;
+                       goto end;
+               }
+
+               memcpy((void *) local_extended->serialized_trace_format_descriptor.data,
+                               trace_format_view.data, trace_format_view.size);
+
+               offset += session_comm->trace_format_descriptor_len;
+       }
        /* Transfer ownership to the caller. */
        *out_session = local_session;
        local_session = nullptr;
@@ -206,7 +237,7 @@ static enum lttng_error_code compute_flattened_size(
                struct lttng_dynamic_pointer_array *sessions, size_t *size)
 {
        enum lttng_error_code ret_code;
-       size_t storage_req, session_count;
+       size_t storage_req, session_count, i;
 
        assert(size);
        assert(sessions);
@@ -219,6 +250,15 @@ static enum lttng_error_code compute_flattened_size(
        /* The struct lttng_session_extended */
        storage_req += session_count * sizeof(struct lttng_session_extended);
 
+       for (i = 0; i < session_count; i++) {
+               const struct session_list_element *element = (const struct session_list_element *)
+                               lttng_dynamic_pointer_array_get_pointer(sessions, i);
+
+               storage_req += ((const struct lttng_session_extended *) (element->session->extended
+                                                                                        .ptr))
+                                              ->serialized_trace_format_descriptor.size;
+       }
+
        *size = storage_req;
        ret_code = LTTNG_OK;
 
@@ -282,20 +322,35 @@ static enum lttng_error_code flatten_lttng_sessions(struct lttng_dynamic_pointer
                struct lttng_session_extended *session_extended =
                                (struct lttng_session_extended *) (local_flattened_sessions.data +
                                                local_flattened_sessions.size);
+               size_t currentSize;
 
                assert(element);
 
                /* Insert struct lttng_session_extended. */
-               ret = lttng_dynamic_buffer_set_size(&local_flattened_sessions,
-                               local_flattened_sessions.size + sizeof(*session_extended));
+               ret = lttng_dynamic_buffer_append(&local_flattened_sessions,
+                               element->session->extended.ptr, sizeof(*session_extended));
                if (ret) {
                        ret_code = LTTNG_ERR_NOMEM;
                        goto end;
                }
+               /* Update the location of the extended protion in the base lttng_session object */
                session->extended.ptr = session_extended;
 
-               memcpy(session_extended, element->session->extended.ptr,
-                               sizeof(struct lttng_session_extended));
+               /* Insert serialize_trace_format_descriptor */
+               currentSize = local_flattened_sessions.size;
+               ret = lttng_dynamic_buffer_append(&local_flattened_sessions,
+                               session_extended->serialized_trace_format_descriptor.data,
+                               session_extended->serialized_trace_format_descriptor.size);
+               if (ret) {
+                       ret_code = LTTNG_ERR_NOMEM;
+                       goto end;
+               }
+
+               /* Update the view to point at the flattened memory location for
+                * trace_format_descriptor */
+               session_extended->serialized_trace_format_descriptor = lttng_buffer_view_init(
+                               local_flattened_sessions.data, currentSize,
+                               session_extended->serialized_trace_format_descriptor.size);
        }
 
        /* Don't reset local_flattened_sessions buffer as we return its content. */
@@ -390,3 +445,43 @@ end:
        lttng_dynamic_pointer_array_reset(&local_sessions);
        return ret;
 }
+enum lttng_error_code lttng_session_get_trace_format_descriptor(const struct lttng_session *session,
+               struct lttng_trace_format_descriptor **p_lttng_trace_format_descriptor)
+{
+       lttng_error_code ret_code;
+       const struct lttng_session_extended *extended = nullptr;
+       struct lttng_trace_format_descriptor *local_descriptor = nullptr;
+       ssize_t deserialiazed = 0;
+       lttng::trace_format_descriptor::uptr p_trace_format;
+
+       if (!session || !session->extended.ptr) {
+               ret_code = LTTNG_ERR_INVALID;
+               goto error;
+       }
+
+       extended = (struct lttng_session_extended *) session->extended.ptr;
+
+       {
+               struct lttng_payload_view view = lttng_payload_view_from_buffer_view(
+                               &extended->serialized_trace_format_descriptor, 0,
+                               extended->serialized_trace_format_descriptor.size);
+               deserialiazed = lttng::trace_format_descriptor::create_from_payload(
+                               &view, p_trace_format);
+               if (deserialiazed < 0 ||
+                               deserialiazed !=
+                                               extended->serialized_trace_format_descriptor.size) {
+                       ret_code = LTTNG_ERR_INVALID;
+                       goto error;
+               }
+       }
+
+       local_descriptor = reinterpret_cast<struct lttng_trace_format_descriptor *>(
+                       p_trace_format.release());
+
+       *p_lttng_trace_format_descriptor = local_descriptor;
+       local_descriptor = nullptr;
+       ret_code = LTTNG_OK;
+error:
+       lttng_trace_format_descriptor_destroy(local_descriptor);
+       return ret_code;
+}
index c0092e418060d316dfdddfae155d3622a69d8d00..1866c4801861fc919d23d5df18346e705da53ad5 100644 (file)
@@ -468,6 +468,7 @@ lttng_session_descriptor_snapshot_create
 lttng_session_descriptor_snapshot_local_create
 lttng_session_descriptor_snapshot_network_create
 lttng_session_get_creation_time
+lttng_session_get_trace_format_descriptor
 lttng_session_get_tracker_handle
 lttng_session_list_rotation_schedules
 lttng_session_remove_rotation_schedule
This page took 0.039509 seconds and 5 git commands to generate.