From 346732ae37c936dcabc351cbcc3ab34147cc0cea Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Wed, 27 Apr 2022 15:17:57 -0400 Subject: [PATCH] Kernel: add feature check for ctf2 based on lttng-modules ABI TODO: change the actual value when actually upstreaming Signed-off-by: Jonathan Rajotte Change-Id: I80f1fa9281e3ae4db3b7f8d42f19a6ba38bfa23a --- include/lttng/lttng-error.h | 1 + src/bin/lttng-sessiond/cmd.cpp | 24 ++++++++++++++++++++++++ src/bin/lttng-sessiond/kernel.cpp | 16 ++++++++++++++++ src/bin/lttng-sessiond/kernel.hpp | 1 + src/common/error.cpp | 2 ++ 5 files changed, 44 insertions(+) diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index 790a78a0b..1438e0dc2 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -183,6 +183,7 @@ enum lttng_error_code { LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING_FULL = 168, /* Error event notifier error accounting full. */ LTTNG_ERR_INVALID_ERROR_QUERY_TARGET = 169, /* Invalid error query target. */ LTTNG_ERR_BUFFER_FLUSH_FAILED = 170, /* Buffer flush failed */ + LTTNG_ERR_TRACE_FORMAT_UNSUPPORTED_KERNEL_TRACER = 171, /* Kernel tracer does not support the specified trace format */ /* MUST be last element of the manually-assigned section of the enum */ LTTNG_ERR_NR, diff --git a/src/bin/lttng-sessiond/cmd.cpp b/src/bin/lttng-sessiond/cmd.cpp index d5f461888..158fb0d75 100644 --- a/src/bin/lttng-sessiond/cmd.cpp +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -1286,6 +1286,23 @@ end: return ret; } +static enum lttng_error_code kernel_domain_check_trace_format_requirements( + const lttng::trace_format_descriptor& descriptor) +{ + enum lttng_error_code ret_code; + switch (descriptor.type()) { + case LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1: + /* Supported by all kernel tracer. */ + ret_code = LTTNG_OK; + break; + case LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2: + if (!kernel_supports_ctf2()) { + ret_code = LTTNG_ERR_TRACE_FORMAT_UNSUPPORTED_KERNEL_TRACER; + } + } + return LTTNG_OK; +} + static enum lttng_error_code cmd_enable_channel_internal( struct ltt_session *session, const struct lttng_domain *domain, @@ -1343,6 +1360,13 @@ static enum lttng_error_code cmd_enable_channel_internal( attr->name, session->name); lttng_channel_set_monitor_timer_interval(attr, 0); } + + ret_code = kernel_domain_check_trace_format_requirements(*session->trace_format); + if (ret_code != LTTNG_OK) { + WARN("Kernel tracer does not support the configured trace format of session '%s'", + session->name); + goto error; + } break; } case LTTNG_DOMAIN_UST: diff --git a/src/bin/lttng-sessiond/kernel.cpp b/src/bin/lttng-sessiond/kernel.cpp index f7d232ffc..2831a039e 100644 --- a/src/bin/lttng-sessiond/kernel.cpp +++ b/src/bin/lttng-sessiond/kernel.cpp @@ -1837,6 +1837,22 @@ int kernel_supports_event_notifiers(void) return kernel_tracer_abi_greater_or_equal(2, 6); } +/* + * Check for the support of ctf2 via abi version number. + * + * Return 1 on success, 0 when feature is not supported, negative value in case + * of errors. + */ +int kernel_supports_ctf2(void) +{ + /* + * JORAJ TODO: change this for the actual value when merged upstream + * default to 2.7 ABI for now (modules 2.14) + * CTF2 support was introduced in LTTng 2.1XX, lttng-modules ABI 2.XX. + */ + return kernel_tracer_abi_greater_or_equal(2, 7); +} + /* * Rotate a kernel session. * diff --git a/src/bin/lttng-sessiond/kernel.hpp b/src/bin/lttng-sessiond/kernel.hpp index bb0165121..a3fb9e598 100644 --- a/src/bin/lttng-sessiond/kernel.hpp +++ b/src/bin/lttng-sessiond/kernel.hpp @@ -72,6 +72,7 @@ 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); +int kernel_supports_ctf2(void); int kernel_supports_ring_buffer_snapshot_sample_positions(void); int kernel_supports_ring_buffer_packet_sequence_number(void); int kernel_supports_event_notifiers(void); diff --git a/src/common/error.cpp b/src/common/error.cpp index 150d2e53f..40c1faf0b 100644 --- a/src/common/error.cpp +++ b/src/common/error.cpp @@ -404,6 +404,8 @@ const char *lttng_error_code_str(lttng_error_code code) return "Invalid error query target."; case LTTNG_ERR_BUFFER_FLUSH_FAILED: return "Failed to flush stream buffer"; + case LTTNG_ERR_TRACE_FORMAT_UNSUPPORTED_KERNEL_TRACER: + return "Kernel tracer does not support the specified trace format"; case LTTNG_ERR_NR: abort(); } -- 2.34.1