From 8c914f59259a286cd684a252adb7c96ad15d5d05 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Fri, 8 Nov 2024 15:59:00 -0500 Subject: [PATCH] lttng-ctl: Add session shm_path to extended session attributes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Observed issue ============== Once a session is created, any lttng clients have no way of checking what the current shared memory path setting for a session is. Solution ======== Expose the configure path via an attribute in the extended structure of lttng sessions. Known drawbacks =============== None. Change-Id: Ie257bcedfc913e09fc6a60e6b9387d2e8d4cb828 Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- include/lttng/session-internal.hpp | 3 +++ include/lttng/session.h | 26 ++++++++++++++++++++++++++ src/bin/lttng-sessiond/cmd.cpp | 1 + src/lib/lttng-ctl/liblttng-ctl.sym | 1 + src/lib/lttng-ctl/lttng-ctl.cpp | 14 ++++++++++++++ 5 files changed, 45 insertions(+) diff --git a/include/lttng/session-internal.hpp b/include/lttng/session-internal.hpp index 61e65981c..6d701389f 100644 --- a/include/lttng/session-internal.hpp +++ b/include/lttng/session-internal.hpp @@ -20,6 +20,9 @@ struct lttng_session_extended { uint64_t value; uint8_t is_set; } LTTNG_PACKED creation_time; + struct { + char value[LTTNG_PATH_MAX]; + } LTTNG_PACKED shm_path; } LTTNG_PACKED; using lttng_session_uptr = std::unique_ptr< diff --git a/include/lttng/session.h b/include/lttng/session.h index a6735edad..a614ab494 100644 --- a/include/lttng/session.h +++ b/include/lttng/session.h @@ -28,6 +28,12 @@ struct lttng_destruction_handle; #define LTTNG_SESSION_PADDING1 8 +enum lttng_get_session_shm_path_status { + LTTNG_GET_SESSION_SHM_PATH_STATUS_OK = 0, + LTTNG_GET_SESSION_SHM_PATH_STATUS_UNSET = 1, + LTTNG_GET_SESSION_SHM_PATH_STATUS_INVALID_PARAMETER = -1, +}; + /*! @brief Recording session summary. @@ -506,6 +512,26 @@ utility. */ LTTNG_EXPORT extern int lttng_set_session_shm_path(const char *session_name, const char *shm_dir); +/*! +@brief + Gets the shm_path set for the given session. + +@param[in] session + Pointer to an struct lttng_session return by lttng_list_sessions. + +@param[out] shm_path + A pointer to the shm_path in the session structure. + +@param[out] set + True when the session's shm_path has been explicitly changed from the default. + +@lt_pre_conn +@lt_pre_not_null{session} +@lt_pre_not_null{shm_path} +@lt_pre_not_null{set} +*/ +LTTNG_EXPORT extern enum lttng_get_session_shm_path_status +lttng_get_session_shm_path_override(const struct lttng_session *session, const char **shm_path); /// @} #ifdef __cplusplus diff --git a/src/bin/lttng-sessiond/cmd.cpp b/src/bin/lttng-sessiond/cmd.cpp index 6f24d0ac5..2151883fc 100644 --- a/src/bin/lttng-sessiond/cmd.cpp +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -4345,6 +4345,7 @@ void cmd_list_lttng_sessions(struct lttng_session *sessions, sessions[i].live_timer_interval = session->live_timer; extended[i].creation_time.value = (uint64_t) session->creation_time; extended[i].creation_time.is_set = 1; + strncpy(extended[i].shm_path.value, session->shm_path, LTTNG_PATH_MAX); i++; } } diff --git a/src/lib/lttng-ctl/liblttng-ctl.sym b/src/lib/lttng-ctl/liblttng-ctl.sym index ff1aa823d..3f702f6dd 100644 --- a/src/lib/lttng-ctl/liblttng-ctl.sym +++ b/src/lib/lttng-ctl/liblttng-ctl.sym @@ -320,6 +320,7 @@ lttng_event_rule_user_tracepoint_set_log_level_rule lttng_event_rule_user_tracepoint_set_name_pattern lttng_event_set_userspace_probe_location lttng_get_kernel_tracer_status +lttng_get_session_shm_path_override lttng_health_create_consumerd lttng_health_create_relayd lttng_health_create_sessiond diff --git a/src/lib/lttng-ctl/lttng-ctl.cpp b/src/lib/lttng-ctl/lttng-ctl.cpp index 029f0b0ef..24733e82e 100644 --- a/src/lib/lttng-ctl/lttng-ctl.cpp +++ b/src/lib/lttng-ctl/lttng-ctl.cpp @@ -2329,6 +2329,20 @@ end: return ret; } +enum lttng_get_session_shm_path_status +lttng_get_session_shm_path_override(const lttng_session *session, const char **shm_path) +{ + struct lttng_session_extended *extended; + if (!session || !shm_path || !session->extended.ptr) { + return LTTNG_GET_SESSION_SHM_PATH_STATUS_INVALID_PARAMETER; + } + + extended = (lttng_session_extended *) session->extended.ptr; + *shm_path = extended->shm_path.value; + return strlen(*shm_path) == 0 ? LTTNG_GET_SESSION_SHM_PATH_STATUS_UNSET : + LTTNG_GET_SESSION_SHM_PATH_STATUS_OK; +} + int lttng_set_session_shm_path(const char *session_name, const char *shm_path) { int ret; -- 2.39.5