From b892e907e8519dd9cd0863a7da6d7cf86a9ed54e Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Tue, 12 Feb 2019 11:51:42 -0500 Subject: [PATCH 01/16] Add kernel uid/gid contexts Signed-off-by: Michael Jeanson --- include/lttng/event.h | 12 +++++++ src/bin/lttng-sessiond/context.c | 36 +++++++++++++++++++ src/bin/lttng-sessiond/save.c | 36 +++++++++++++++++++ src/bin/lttng/commands/add_context.c | 24 +++++++++++++ src/common/config/config-session-abi.h | 12 +++++++ src/common/config/session-config.c | 48 ++++++++++++++++++++++++++ src/common/lttng-kernel.h | 12 +++++++ 7 files changed, 180 insertions(+) diff --git a/include/lttng/event.h b/include/lttng/event.h index 35c8d96f5..451a43351 100644 --- a/include/lttng/event.h +++ b/include/lttng/event.h @@ -153,6 +153,18 @@ enum lttng_event_context_type { LTTNG_EVENT_CONTEXT_PID_NS = 26, LTTNG_EVENT_CONTEXT_USER_NS = 27, LTTNG_EVENT_CONTEXT_UTS_NS = 28, + LTTNG_EVENT_CONTEXT_UID = 29, + LTTNG_EVENT_CONTEXT_EUID = 30, + LTTNG_EVENT_CONTEXT_SUID = 31, + LTTNG_EVENT_CONTEXT_GID = 32, + LTTNG_EVENT_CONTEXT_EGID = 33, + LTTNG_EVENT_CONTEXT_SGID = 34, + LTTNG_EVENT_CONTEXT_VUID = 35, + LTTNG_EVENT_CONTEXT_VEUID = 36, + LTTNG_EVENT_CONTEXT_VSUID = 37, + LTTNG_EVENT_CONTEXT_VGID = 38, + LTTNG_EVENT_CONTEXT_VEGID = 39, + LTTNG_EVENT_CONTEXT_VSGID = 40, }; enum lttng_event_field_type { diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index 6f7847b0d..3dd89cfdd 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -287,6 +287,42 @@ int context_kernel_add(struct ltt_kernel_session *ksession, case LTTNG_EVENT_CONTEXT_UTS_NS: kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_UTS_NS; break; + case LTTNG_EVENT_CONTEXT_UID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_UID; + break; + case LTTNG_EVENT_CONTEXT_EUID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_EUID; + break; + case LTTNG_EVENT_CONTEXT_SUID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_SUID; + break; + case LTTNG_EVENT_CONTEXT_GID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_GID; + break; + case LTTNG_EVENT_CONTEXT_EGID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_EGID; + break; + case LTTNG_EVENT_CONTEXT_SGID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_SGID; + break; + case LTTNG_EVENT_CONTEXT_VUID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_VUID; + break; + case LTTNG_EVENT_CONTEXT_VEUID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_VEUID; + break; + case LTTNG_EVENT_CONTEXT_VSUID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_VSUID; + break; + case LTTNG_EVENT_CONTEXT_VGID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_VGID; + break; + case LTTNG_EVENT_CONTEXT_VEGID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_VEGID; + break; + case LTTNG_EVENT_CONTEXT_VSGID: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_VSGID; + break; default: ret = LTTNG_ERR_KERN_CONTEXT_FAIL; goto error; diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index bb305b440..993c3716a 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -315,6 +315,42 @@ const char *get_kernel_context_type_string( case LTTNG_KERNEL_CONTEXT_UTS_NS: context_type_string = config_event_context_uts_ns; break; + case LTTNG_KERNEL_CONTEXT_UID: + context_type_string = config_event_context_uid; + break; + case LTTNG_KERNEL_CONTEXT_EUID: + context_type_string = config_event_context_euid; + break; + case LTTNG_KERNEL_CONTEXT_SUID: + context_type_string = config_event_context_suid; + break; + case LTTNG_KERNEL_CONTEXT_GID: + context_type_string = config_event_context_gid; + break; + case LTTNG_KERNEL_CONTEXT_EGID: + context_type_string = config_event_context_egid; + break; + case LTTNG_KERNEL_CONTEXT_SGID: + context_type_string = config_event_context_sgid; + break; + case LTTNG_KERNEL_CONTEXT_VUID: + context_type_string = config_event_context_vuid; + break; + case LTTNG_KERNEL_CONTEXT_VEUID: + context_type_string = config_event_context_veuid; + break; + case LTTNG_KERNEL_CONTEXT_VSUID: + context_type_string = config_event_context_vsuid; + break; + case LTTNG_KERNEL_CONTEXT_VGID: + context_type_string = config_event_context_vgid; + break; + case LTTNG_KERNEL_CONTEXT_VEGID: + context_type_string = config_event_context_vegid; + break; + case LTTNG_KERNEL_CONTEXT_VSGID: + context_type_string = config_event_context_vsgid; + break; default: context_type_string = NULL; } diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index a9ef0ddad..9fcb16d6e 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -93,6 +93,18 @@ enum context_type { CONTEXT_PID_NS = 26, CONTEXT_USER_NS = 27, CONTEXT_UTS_NS = 28, + CONTEXT_UID = 29, + CONTEXT_EUID = 30, + CONTEXT_SUID = 31, + CONTEXT_GID = 32, + CONTEXT_EGID = 33, + CONTEXT_SGID = 34, + CONTEXT_VUID = 35, + CONTEXT_VEUID = 36, + CONTEXT_VSUID = 37, + CONTEXT_VGID = 38, + CONTEXT_VEGID = 39, + CONTEXT_VSGID = 40, }; /* @@ -260,6 +272,18 @@ const struct ctx_opts { { "pid_ns", CONTEXT_PID_NS }, { "user_ns", CONTEXT_USER_NS }, { "uts_ns", CONTEXT_UTS_NS }, + { "uid", CONTEXT_UID }, + { "euid", CONTEXT_EUID }, + { "suid", CONTEXT_SUID }, + { "gid", CONTEXT_GID }, + { "egid", CONTEXT_EGID }, + { "sgid", CONTEXT_SGID }, + { "vuid", CONTEXT_VUID }, + { "veuid", CONTEXT_VEUID }, + { "vsuid", CONTEXT_VSUID }, + { "vgid", CONTEXT_VGID }, + { "vegid", CONTEXT_VEGID }, + { "vsgid", CONTEXT_VSGID }, /* Perf options */ diff --git a/src/common/config/config-session-abi.h b/src/common/config/config-session-abi.h index ced35254d..12dfe600c 100644 --- a/src/common/config/config-session-abi.h +++ b/src/common/config/config-session-abi.h @@ -158,5 +158,17 @@ extern const char * const config_event_context_net_ns; extern const char * const config_event_context_pid_ns; extern const char * const config_event_context_user_ns; extern const char * const config_event_context_uts_ns; +extern const char * const config_event_context_uid; +extern const char * const config_event_context_euid; +extern const char * const config_event_context_suid; +extern const char * const config_event_context_gid; +extern const char * const config_event_context_egid; +extern const char * const config_event_context_sgid; +extern const char * const config_event_context_vuid; +extern const char * const config_event_context_veuid; +extern const char * const config_event_context_vsuid; +extern const char * const config_event_context_vgid; +extern const char * const config_event_context_vegid; +extern const char * const config_event_context_vsgid; #endif /* CONFIG_SESSION_INTERNAL_H */ diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index 2c9f69266..df0603b2e 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -212,6 +212,18 @@ LTTNG_HIDDEN const char * const config_event_context_net_ns = "NET_NS"; LTTNG_HIDDEN const char * const config_event_context_pid_ns = "PID_NS"; LTTNG_HIDDEN const char * const config_event_context_user_ns = "USER_NS"; LTTNG_HIDDEN const char * const config_event_context_uts_ns = "UTS_NS"; +LTTNG_HIDDEN const char * const config_event_context_uid = "UID"; +LTTNG_HIDDEN const char * const config_event_context_euid = "EUID"; +LTTNG_HIDDEN const char * const config_event_context_suid = "SUID"; +LTTNG_HIDDEN const char * const config_event_context_gid = "GID"; +LTTNG_HIDDEN const char * const config_event_context_egid = "EGID"; +LTTNG_HIDDEN const char * const config_event_context_sgid = "SGID"; +LTTNG_HIDDEN const char * const config_event_context_vuid = "VUID"; +LTTNG_HIDDEN const char * const config_event_context_veuid = "VEUID"; +LTTNG_HIDDEN const char * const config_event_context_vsuid = "VSUID"; +LTTNG_HIDDEN const char * const config_event_context_vgid = "VGID"; +LTTNG_HIDDEN const char * const config_event_context_vegid = "VEGID"; +LTTNG_HIDDEN const char * const config_event_context_vsgid = "VSGID"; /* Deprecated symbols */ const char * const config_element_perf; @@ -1075,6 +1087,42 @@ int get_context_type(xmlChar *context_type) } else if (!strcmp((char *) context_type, config_event_context_uts_ns)) { ret = LTTNG_EVENT_CONTEXT_UTS_NS; + } else if (!strcmp((char *) context_type, + config_event_context_uid)) { + ret = LTTNG_EVENT_CONTEXT_UID; + } else if (!strcmp((char *) context_type, + config_event_context_euid)) { + ret = LTTNG_EVENT_CONTEXT_EUID; + } else if (!strcmp((char *) context_type, + config_event_context_suid)) { + ret = LTTNG_EVENT_CONTEXT_SUID; + } else if (!strcmp((char *) context_type, + config_event_context_gid)) { + ret = LTTNG_EVENT_CONTEXT_GID; + } else if (!strcmp((char *) context_type, + config_event_context_egid)) { + ret = LTTNG_EVENT_CONTEXT_EGID; + } else if (!strcmp((char *) context_type, + config_event_context_sgid)) { + ret = LTTNG_EVENT_CONTEXT_SGID; + } else if (!strcmp((char *) context_type, + config_event_context_vuid)) { + ret = LTTNG_EVENT_CONTEXT_VUID; + } else if (!strcmp((char *) context_type, + config_event_context_veuid)) { + ret = LTTNG_EVENT_CONTEXT_VEUID; + } else if (!strcmp((char *) context_type, + config_event_context_vsuid)) { + ret = LTTNG_EVENT_CONTEXT_VSUID; + } else if (!strcmp((char *) context_type, + config_event_context_vgid)) { + ret = LTTNG_EVENT_CONTEXT_VGID; + } else if (!strcmp((char *) context_type, + config_event_context_vegid)) { + ret = LTTNG_EVENT_CONTEXT_VEGID; + } else if (!strcmp((char *) context_type, + config_event_context_vsgid)) { + ret = LTTNG_EVENT_CONTEXT_VSGID; } else { goto error; } diff --git a/src/common/lttng-kernel.h b/src/common/lttng-kernel.h index 9445b3740..9d777ee77 100644 --- a/src/common/lttng-kernel.h +++ b/src/common/lttng-kernel.h @@ -71,6 +71,18 @@ enum lttng_kernel_context_type { LTTNG_KERNEL_CONTEXT_PID_NS = 22, LTTNG_KERNEL_CONTEXT_USER_NS = 23, LTTNG_KERNEL_CONTEXT_UTS_NS = 24, + LTTNG_KERNEL_CONTEXT_UID = 25, + LTTNG_KERNEL_CONTEXT_EUID = 26, + LTTNG_KERNEL_CONTEXT_SUID = 27, + LTTNG_KERNEL_CONTEXT_GID = 28, + LTTNG_KERNEL_CONTEXT_EGID = 29, + LTTNG_KERNEL_CONTEXT_SGID = 30, + LTTNG_KERNEL_CONTEXT_VUID = 31, + LTTNG_KERNEL_CONTEXT_VEUID = 32, + LTTNG_KERNEL_CONTEXT_VSUID = 33, + LTTNG_KERNEL_CONTEXT_VGID = 34, + LTTNG_KERNEL_CONTEXT_VEGID = 35, + LTTNG_KERNEL_CONTEXT_VSGID = 36, }; /* Perf counter attributes */ -- 2.34.1 From b9eae072b95834277ac34fcb5a88f7b88b7814a2 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Tue, 12 Feb 2019 11:51:55 -0500 Subject: [PATCH 02/16] Add UST uid/gid contexts Signed-off-by: Michael Jeanson --- src/bin/lttng-sessiond/lttng-ust-abi.h | 6 ++++++ src/bin/lttng-sessiond/save.c | 18 ++++++++++++++++++ src/bin/lttng-sessiond/trace-ust.c | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/bin/lttng-sessiond/lttng-ust-abi.h b/src/bin/lttng-sessiond/lttng-ust-abi.h index b88d8a698..bb022e3d7 100644 --- a/src/bin/lttng-sessiond/lttng-ust-abi.h +++ b/src/bin/lttng-sessiond/lttng-ust-abi.h @@ -152,6 +152,12 @@ enum lttng_ust_context_type { LTTNG_UST_CONTEXT_PID_NS = 12, LTTNG_UST_CONTEXT_USER_NS = 13, LTTNG_UST_CONTEXT_UTS_NS = 14, + LTTNG_UST_CONTEXT_VUID = 15, + LTTNG_UST_CONTEXT_VEUID = 16, + LTTNG_UST_CONTEXT_VSUID = 17, + LTTNG_UST_CONTEXT_VGID = 18, + LTTNG_UST_CONTEXT_VEGID = 19, + LTTNG_UST_CONTEXT_VSGID = 20, }; struct lttng_ust_perf_counter_ctx { diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index 993c3716a..d3a702ab6 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -404,6 +404,24 @@ const char *get_ust_context_type_string( case LTTNG_UST_CONTEXT_UTS_NS: context_type_string = config_event_context_uts_ns; break; + case LTTNG_UST_CONTEXT_VUID: + context_type_string = config_event_context_vuid; + break; + case LTTNG_UST_CONTEXT_VEUID: + context_type_string = config_event_context_veuid; + break; + case LTTNG_UST_CONTEXT_VSUID: + context_type_string = config_event_context_vsuid; + break; + case LTTNG_UST_CONTEXT_VGID: + context_type_string = config_event_context_vgid; + break; + case LTTNG_UST_CONTEXT_VEGID: + context_type_string = config_event_context_vegid; + break; + case LTTNG_UST_CONTEXT_VSGID: + context_type_string = config_event_context_vsgid; + break; case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER: /* * Error, should not be stored in the XML, perf contexts diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index a37161865..3095c8617 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -584,6 +584,24 @@ int trace_ust_context_type_event_to_ust( case LTTNG_EVENT_CONTEXT_UTS_NS: utype = LTTNG_UST_CONTEXT_UTS_NS; break; + case LTTNG_EVENT_CONTEXT_VUID: + utype = LTTNG_UST_CONTEXT_VUID; + break; + case LTTNG_EVENT_CONTEXT_VEUID: + utype = LTTNG_UST_CONTEXT_VEUID; + break; + case LTTNG_EVENT_CONTEXT_VSUID: + utype = LTTNG_UST_CONTEXT_VSUID; + break; + case LTTNG_EVENT_CONTEXT_VGID: + utype = LTTNG_UST_CONTEXT_VGID; + break; + case LTTNG_EVENT_CONTEXT_VEGID: + utype = LTTNG_UST_CONTEXT_VEGID; + break; + case LTTNG_EVENT_CONTEXT_VSGID: + utype = LTTNG_UST_CONTEXT_VSGID; + break; default: utype = -1; break; -- 2.34.1 From 9f2b96ba4c09d9df2739fcc36769691e53c0c8cf Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 2 Apr 2019 17:51:01 -0400 Subject: [PATCH 03/16] mi: Add support for namespace and uid/gid contexts Signed-off-by: Jonathan Rajotte Signed-off-by: Michael Jeanson --- src/common/mi-lttng-3.0.xsd | 19 +++++++++++++++++++ src/common/mi-lttng.c | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/common/mi-lttng-3.0.xsd b/src/common/mi-lttng-3.0.xsd index 017956ccc..b15491a6e 100644 --- a/src/common/mi-lttng-3.0.xsd +++ b/src/common/mi-lttng-3.0.xsd @@ -119,6 +119,25 @@ THE SOFTWARE. + + + + + + + + + + + + + + + + + + + diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index 69b3cc041..d889a4029 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -428,6 +428,44 @@ const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val) return config_event_context_callstack_user; case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL: return config_event_context_callstack_kernel; + case LTTNG_EVENT_CONTEXT_CGROUP_NS: + return config_event_context_cgroup_ns; + case LTTNG_EVENT_CONTEXT_IPC_NS: + return config_event_context_ipc_ns; + case LTTNG_EVENT_CONTEXT_MNT_NS: + return config_event_context_mnt_ns; + case LTTNG_EVENT_CONTEXT_NET_NS: + return config_event_context_net_ns; + case LTTNG_EVENT_CONTEXT_PID_NS: + return config_event_context_pid_ns; + case LTTNG_EVENT_CONTEXT_USER_NS: + return config_event_context_user_ns; + case LTTNG_EVENT_CONTEXT_UTS_NS: + return config_event_context_uts_ns; + case LTTNG_EVENT_CONTEXT_UID: + return config_event_context_uid; + case LTTNG_EVENT_CONTEXT_EUID: + return config_event_context_euid; + case LTTNG_EVENT_CONTEXT_SUID: + return config_event_context_suid; + case LTTNG_EVENT_CONTEXT_GID: + return config_event_context_gid; + case LTTNG_EVENT_CONTEXT_EGID: + return config_event_context_egid; + case LTTNG_EVENT_CONTEXT_SGID: + return config_event_context_sgid; + case LTTNG_EVENT_CONTEXT_VUID: + return config_event_context_vuid; + case LTTNG_EVENT_CONTEXT_VEUID: + return config_event_context_veuid; + case LTTNG_EVENT_CONTEXT_VSUID: + return config_event_context_vsuid; + case LTTNG_EVENT_CONTEXT_VGID: + return config_event_context_vgid; + case LTTNG_EVENT_CONTEXT_VEGID: + return config_event_context_vegid; + case LTTNG_EVENT_CONTEXT_VSGID: + return config_event_context_vsgid; default: return NULL; } -- 2.34.1 From a57cded1a4ee20cd81d618a9921e07c2fe54110e Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 1 Apr 2019 11:51:52 -0400 Subject: [PATCH 04/16] Add UST namespace contexts tests Signed-off-by: Michael Jeanson --- configure.ac | 1 + tests/regression/Makefile.am | 3 +- tests/regression/ust/Makefile.am | 2 +- tests/regression/ust/namespaces/Makefile.am | 16 +++ .../ust/namespaces/test_ns_contexts | 106 ++++++++++++++++++ 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 tests/regression/ust/namespaces/Makefile.am create mode 100755 tests/regression/ust/namespaces/test_ns_contexts diff --git a/configure.ac b/configure.ac index 214d58ac8..e833c9d79 100644 --- a/configure.ac +++ b/configure.ac @@ -1158,6 +1158,7 @@ AC_CONFIG_FILES([ tests/regression/ust/type-declarations/Makefile tests/regression/ust/rotation-destroy-flush/Makefile tests/regression/ust/blocking/Makefile + tests/regression/ust/namespaces/Makefile tests/stress/Makefile tests/unit/Makefile tests/unit/ini_config/Makefile diff --git a/tests/regression/Makefile.am b/tests/regression/Makefile.am index 775240405..1d3cda3bb 100644 --- a/tests/regression/Makefile.am +++ b/tests/regression/Makefile.am @@ -50,7 +50,8 @@ TESTS += ust/before-after/test_before_after \ ust/test_event_perf \ ust/blocking/test_blocking \ ust/multi-lib/test_multi_lib \ - ust/rotation-destroy-flush/test_rotation_destroy_flush + ust/rotation-destroy-flush/test_rotation_destroy_flush \ + ust/namespaces/test_ns_contexts endif # HAVE_LIBLTTNG_UST_CTL if PYTHON_BINDING diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am index 6237b1610..cf6f20dd4 100644 --- a/tests/regression/ust/Makefile.am +++ b/tests/regression/ust/Makefile.am @@ -3,7 +3,7 @@ SUBDIRS = nprocesses high-throughput low-throughput before-after multi-session \ overlap buffers-pid linking daemon exit-fast fork libc-wrapper \ periodical-metadata-flush java-jul java-log4j python-logging \ getcpu-override clock-override type-declarations \ - rotation-destroy-flush blocking multi-lib + rotation-destroy-flush blocking multi-lib namespaces if HAVE_OBJCOPY SUBDIRS += baddr-statedump ust-dl diff --git a/tests/regression/ust/namespaces/Makefile.am b/tests/regression/ust/namespaces/Makefile.am new file mode 100644 index 000000000..11f4d8508 --- /dev/null +++ b/tests/regression/ust/namespaces/Makefile.am @@ -0,0 +1,16 @@ +noinst_SCRIPTS = test_ns_contexts +EXTRA_DIST = test_ns_contexts + +all-local: + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(EXTRA_DIST); do \ + cp -f $(srcdir)/$$script $(builddir); \ + done; \ + fi + +clean-local: + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(EXTRA_DIST); do \ + rm -f $(builddir)/$$script; \ + done; \ + fi diff --git a/tests/regression/ust/namespaces/test_ns_contexts b/tests/regression/ust/namespaces/test_ns_contexts new file mode 100755 index 000000000..105c4f03a --- /dev/null +++ b/tests/regression/ust/namespaces/test_ns_contexts @@ -0,0 +1,106 @@ +#!/bin/bash +# +# Copyright (C) 2019 Michael Jeanson +# +# This library is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +TEST_DESC="UST - Namespace contexts" + +CURDIR=$(dirname "$0")/ +TESTDIR=$CURDIR/../../.. + +TESTAPP_PATH="$TESTDIR/utils/testapp" +TESTAPP_NAME="gen-ust-events" +TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" +NUM_EVENT=10000 +EVENT_NAME="tp:tptest" + +TESTS_PER_NS=13 + +NUM_TESTS=$((TESTS_PER_NS * 7)) + +source "$TESTDIR/utils/utils.sh" + +# MUST set TESTDIR before calling those functions +function run_app() +{ + $TESTAPP_BIN $NUM_EVENT + ok $? "Application done" +} + +function test_ns() +{ + local ns=$1 + + local session_name="${ns}_ns" + local chan_name="${ns}_ns" + local context_name="${ns}_ns" + + local trace_path + local ns_inode + + # Check if the kernel has support for this ns type + if [ ! -f "/proc/$$/ns/$ns" ]; then + skip 0 "System has no $ns namespace support" $TESTS_PER_NS + return + fi + + # Get the current ns inode number + ns_inode=$(stat -c '%i' -L "/proc/$$/ns/$ns") + ok $? "Get current $ns namespace inode: $ns_inode" + + trace_path=$(mktemp -d) + + start_lttng_sessiond + + create_lttng_session_ok "$session_name" "$trace_path" + enable_ust_lttng_channel_ok "$session_name" "$chan_name" + add_context_ust_ok "$session_name" "$chan_name" "$context_name" + enable_ust_lttng_event_ok "$session_name" "$EVENT_NAME" "$chan_name" + start_lttng_tracing_ok "$session_name" + + run_app + + # stop and destroy + stop_lttng_tracing_ok "$session_name" + destroy_lttng_session_ok "$session_name" + stop_lttng_sessiond + + # Check that the events contain the right namespace inode number + validate_trace_count "${ns}_ns = $ns_inode" "$trace_path" $NUM_EVENT + + rm -rf "$trace_path" + +} + + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +system_has_ns=0 +if [ -d "/proc/$$/ns" ]; then + system_has_ns=1 +fi + +skip $system_has_ns "System has no namespaces support" $NUM_TESTS && exit 0 + + +test_ns cgroup +test_ns ipc +test_ns mnt +test_ns net +test_ns pid +test_ns user +test_ns uts -- 2.34.1 From 05faae16a88328171e6c7d4ad700f5226239025d Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 1 Apr 2019 11:53:20 -0400 Subject: [PATCH 05/16] Add kernel namespace contexts tests Signed-off-by: Michael Jeanson --- tests/regression/kernel/Makefile.am | 3 +- tests/regression/kernel/test_ns_contexts | 146 +++++++++++++++++++++++ tests/root_regression | 1 + 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100755 tests/regression/kernel/test_ns_contexts diff --git a/tests/regression/kernel/Makefile.am b/tests/regression/kernel/Makefile.am index 3ab6d75bd..169267adb 100644 --- a/tests/regression/kernel/Makefile.am +++ b/tests/regression/kernel/Makefile.am @@ -2,7 +2,8 @@ EXTRA_DIST = test_event_basic test_all_events test_syscall \ test_clock_override test_rotation_destroy_flush \ test_select_poll_epoll test_lttng_logger \ test_userspace_probe test_callstack \ - test_syscall validate_select_poll_epoll.py + test_syscall validate_select_poll_epoll.py \ + test_ns_contexts noinst_PROGRAMS = select_poll_epoll select_poll_epoll_SOURCES = select_poll_epoll.c diff --git a/tests/regression/kernel/test_ns_contexts b/tests/regression/kernel/test_ns_contexts new file mode 100755 index 000000000..406814cb4 --- /dev/null +++ b/tests/regression/kernel/test_ns_contexts @@ -0,0 +1,146 @@ +#!/bin/bash +# +# Copyright (C) 2019 Michael Jeanson +# +# This library is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +TEST_DESC="Kernel tracer - Namespace contexts" + +CURDIR=$(dirname "$0")/ +TESTDIR=$CURDIR/../.. + +TESTS_PER_NS=11 + +NUM_TESTS=$((TESTS_PER_NS * 7)) + +source "$TESTDIR/utils/utils.sh" + +# MUST set TESTDIR before calling those functions +function add_context_kernel_skip_ok() +{ + local session_name=$1 + local channel_name=$2 + local context_name=$3 + local skip_num=$4 + + local ret + + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" add-context -k \ + -s "$session_name" -c "$channel_name" \ + -t "$context_name" 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST" + ret=$? + + if [ "$ret" == "4" ]; then + skip 0 "Current kernel doesn't implement '$context_name' context" $((skip_num + 1)) + else + ok $ret "Add context command for type: $context_name" + fi + + return $ret +} + +function enable_kernel_lttng_event_filter_ok() +{ + local session_name=$1 + local syscall_name=$2 + local channel_name=$3 + local filter=$4 + + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event -k \ + -c "$channel_name" -s "$session_name" \ + --syscall "$syscall_name" \ + -f "$filter" \ + 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST" + + ok $? "Add syscall with filter" +} + +function test_ns() +{ + local ns=$1 + + local session_name="${ns}_ns" + local chan_name="${ns}_ns" + local context_name="${ns}_ns" + + local trace_path + local ns_inode + + # Check if the kernel has support for this ns type + if [ ! -f "/proc/$$/ns/$ns" ]; then + skip 0 "System has no $ns namespace support" $TESTS_PER_NS + return + fi + + # Get the current ns inode number + ns_inode=$(stat -c '%i' -L "/proc/$$/ns/$ns") + ok $? "Get current $ns namespace inode: $ns_inode" + + trace_path=$(mktemp -d) + + start_lttng_sessiond + + create_lttng_session_ok "$session_name" "$trace_path" + enable_kernel_lttng_channel_ok "$session_name" "$chan_name" + add_context_kernel_skip_ok "$session_name" "$chan_name" "$context_name" 4 + if [ "$?" != "4" ]; then + enable_kernel_lttng_event_filter_ok "$session_name" "read" "$chan_name" "\$ctx.$context_name == $ns_inode" + start_lttng_tracing_ok "$session_name" + + # Make sure there is at least one read syscall + cat /proc/cmdline >/dev/null + + stop_lttng_tracing_ok "$session_name" + + # Check that the events contain the right namespace inode number + validate_trace "${ns}_ns = $ns_inode" "$trace_path" + fi + + destroy_lttng_session_ok "$session_name" + stop_lttng_sessiond + + rm -rf "$trace_path" +} + + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + + +isroot=0 +if [ "$(id -u)" == "0" ]; then + isroot=1 +fi + +skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0 + + +system_has_ns=0 +if [ -d "/proc/$$/ns" ]; then + system_has_ns=1 +fi + +skip $system_has_ns "System has no namespaces support" $NUM_TESTS && exit 0 + + +validate_lttng_modules_present + +test_ns cgroup +test_ns ipc +test_ns mnt +test_ns net +test_ns pid +test_ns user +test_ns uts diff --git a/tests/root_regression b/tests/root_regression index f1f661997..c9394aa2c 100644 --- a/tests/root_regression +++ b/tests/root_regression @@ -8,6 +8,7 @@ regression/kernel/test_select_poll_epoll regression/kernel/test_lttng_logger regression/kernel/test_callstack regression/kernel/test_userspace_probe +regression/kernel/test_ns_contexts regression/tools/live/test_kernel regression/tools/live/test_lttng_kernel regression/tools/streaming/test_high_throughput_limits -- 2.34.1 From 135801fce994bbed911e17d5522ca4fdb51e564d Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 1 Apr 2019 11:53:57 -0400 Subject: [PATCH 06/16] Add UST namespace context change tests Signed-off-by: Michael Jeanson --- .gitignore | 1 + configure.ac | 1 + tests/regression/Makefile.am | 3 +- tests/regression/ust/namespaces/Makefile.am | 4 +- .../ust/namespaces/test_ns_contexts_change | 135 +++++++++++ tests/utils/testapp/Makefile.am | 1 + .../testapp/gen-ust-events-ns/Makefile.am | 10 + .../gen-ust-events-ns/gen-ust-events-ns.c | 229 ++++++++++++++++++ tests/utils/testapp/gen-ust-events-ns/tp.c | 16 ++ tests/utils/testapp/gen-ust-events-ns/tp.h | 35 +++ 10 files changed, 432 insertions(+), 3 deletions(-) create mode 100755 tests/regression/ust/namespaces/test_ns_contexts_change create mode 100644 tests/utils/testapp/gen-ust-events-ns/Makefile.am create mode 100644 tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c create mode 100644 tests/utils/testapp/gen-ust-events-ns/tp.c create mode 100644 tests/utils/testapp/gen-ust-events-ns/tp.h diff --git a/.gitignore b/.gitignore index 19276012e..080df57ec 100644 --- a/.gitignore +++ b/.gitignore @@ -117,6 +117,7 @@ health_check /tests/regression/ust/multi-lib/exec-without-callsites /tests/utils/testapp/gen-syscall-events-callstack/gen-syscall-events-callstack /tests/utils/testapp/gen-ust-events/gen-ust-events +/tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns /tests/utils/testapp/gen-ust-nevents-str/gen-ust-nevents-str /tests/utils/testapp/gen-ust-nevents/gen-ust-nevents /tests/utils/testapp/gen-ust-tracef/gen-ust-tracef diff --git a/configure.ac b/configure.ac index e833c9d79..324e11314 100644 --- a/configure.ac +++ b/configure.ac @@ -1167,6 +1167,7 @@ AC_CONFIG_FILES([ tests/utils/tap/Makefile tests/utils/testapp/Makefile tests/utils/testapp/gen-ust-events/Makefile + tests/utils/testapp/gen-ust-events-ns/Makefile tests/utils/testapp/gen-syscall-events-callstack/Makefile tests/utils/testapp/gen-ust-nevents/Makefile tests/utils/testapp/gen-ust-nevents-str/Makefile diff --git a/tests/regression/Makefile.am b/tests/regression/Makefile.am index 1d3cda3bb..2071b28b7 100644 --- a/tests/regression/Makefile.am +++ b/tests/regression/Makefile.am @@ -51,7 +51,8 @@ TESTS += ust/before-after/test_before_after \ ust/blocking/test_blocking \ ust/multi-lib/test_multi_lib \ ust/rotation-destroy-flush/test_rotation_destroy_flush \ - ust/namespaces/test_ns_contexts + ust/namespaces/test_ns_contexts \ + ust/namespaces/test_ns_contexts_change endif # HAVE_LIBLTTNG_UST_CTL if PYTHON_BINDING diff --git a/tests/regression/ust/namespaces/Makefile.am b/tests/regression/ust/namespaces/Makefile.am index 11f4d8508..78f659cc1 100644 --- a/tests/regression/ust/namespaces/Makefile.am +++ b/tests/regression/ust/namespaces/Makefile.am @@ -1,5 +1,5 @@ -noinst_SCRIPTS = test_ns_contexts -EXTRA_DIST = test_ns_contexts +noinst_SCRIPTS = test_ns_contexts test_ns_contexts_change +EXTRA_DIST = test_ns_contexts test_ns_contexts_change all-local: @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ diff --git a/tests/regression/ust/namespaces/test_ns_contexts_change b/tests/regression/ust/namespaces/test_ns_contexts_change new file mode 100755 index 000000000..18a22e588 --- /dev/null +++ b/tests/regression/ust/namespaces/test_ns_contexts_change @@ -0,0 +1,135 @@ +#!/bin/bash +# +# Copyright (C) 2019 Michael Jeanson +# +# This library is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +TEST_DESC="UST - Namespace contexts change" + +CURDIR=$(dirname "$0")/ +TESTDIR=$CURDIR/../../.. + +TESTAPP_PATH="$TESTDIR/utils/testapp" +TESTAPP_NAME="gen-ust-events-ns" +TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" +NUM_EVENT=1000 +EVENT_NAME="tp:tptest" + +TESTS_PER_NS=16 + +NUM_TESTS=$((TESTS_PER_NS * 5)) + +source "$TESTDIR/utils/utils.sh" + +# MUST set TESTDIR before calling those functions + +function test_ns() +{ + local ns=$1 + + local session_name="${ns}_ns" + local chan_name="${ns}_ns" + local context_name="${ns}_ns" + + local trace_path + local ns_inode + local file_sync_before_last + local file_sync_after_unshare + + # Check if the kernel has support for this ns type + if [ ! -f "/proc/$$/ns/$ns" ]; then + skip 0 "System has no $ns namespace support" $TESTS_PER_NS + return + fi + + # Get the current ns inode number + ns_inode=$(stat -c '%i' -L "/proc/$$/ns/$ns") + ok $? "Get current $ns namespace inode: $ns_inode" || ns_inode="invalid" + + trace_path=$(mktemp -d) + file_sync_before_last=$(mktemp -u) + file_sync_after_unshare=$(mktemp -u) + + start_lttng_sessiond + + create_lttng_session_ok "$session_name" "$trace_path" + enable_ust_lttng_channel_ok "$session_name" "$chan_name" + add_context_ust_ok "$session_name" "$chan_name" "$context_name" + enable_ust_lttng_event_ok "$session_name" "$EVENT_NAME" "$chan_name" + start_lttng_tracing_ok "$session_name" + + $TESTAPP_BIN -n "$ns" -i $NUM_EVENT -a "$file_sync_after_unshare" -b "$file_sync_before_last" & + app_pid=$! + + # Let the app do it's thing before entering the synchronisation loop + sleep 0.5 + + while [ ! -f "$file_sync_after_unshare" ]; do + # Break if the app failed / died + if [ ! -f "/proc/$app_pid" ]; then + break + fi + echo "# Waiting for app..." + sleep 0.5 + done + + app_ns_inode=$(stat -c '%i' -L "/proc/$app_pid/ns/$ns") + ok $? "Get current $ns namespace inode: $app_ns_inode" || app_ns_inode="invalid" + + test "$ns_inode" != "invalid" && test "$app_ns_inode" != "invalid" && test "$ns_inode" != "$app_ns_inode" + ok $? "Reported namespace inode changed after unshare" + + touch "$file_sync_before_last" + + # stop and destroy + stop_lttng_tracing_ok "$session_name" + destroy_lttng_session_ok "$session_name" + stop_lttng_sessiond + + # Check that the events contain the right namespace inode number + validate_trace_count "${ns}_ns = $ns_inode" "$trace_path" $NUM_EVENT + validate_trace_count "${ns}_ns = $app_ns_inode" "$trace_path" $NUM_EVENT + + rm -rf "$trace_path" + rm -f "$file_sync_before_last" + rm -f "$file_sync_after_unshare" +} + + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +isroot=0 +if [ "$(id -u)" == "0" ]; then + isroot=1 +fi + +skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0 + +system_has_ns=0 +if [ -d "/proc/$$/ns" ]; then + system_has_ns=1 +fi + +skip $system_has_ns "System has no namespaces support" $NUM_TESTS && exit 0 + + +test_ns cgroup +test_ns ipc +test_ns mnt +test_ns net +#test_ns pid # pid_ns is special, can't be changed that way +#test_ns user # user_ns can only be change when the app is single threaded, this is always false for an ust instrumented app +test_ns uts diff --git a/tests/utils/testapp/Makefile.am b/tests/utils/testapp/Makefile.am index e54ac890a..e98f4b571 100644 --- a/tests/utils/testapp/Makefile.am +++ b/tests/utils/testapp/Makefile.am @@ -1,4 +1,5 @@ SUBDIRS = gen-ust-events \ + gen-ust-events-ns \ gen-ust-nevents \ gen-ust-nevents-str \ gen-ust-tracef \ diff --git a/tests/utils/testapp/gen-ust-events-ns/Makefile.am b/tests/utils/testapp/gen-ust-events-ns/Makefile.am new file mode 100644 index 000000000..39f991240 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-ns/Makefile.am @@ -0,0 +1,10 @@ +AM_CPPFLAGS += -I$(top_srcdir)/tests/utils -I$(srcdir) \ + -I$(top_srcdir)/tests/utils/testapp + +if HAVE_LIBLTTNG_UST_CTL +noinst_PROGRAMS = gen-ust-events-ns +gen_ust_events_ns_SOURCES = gen-ust-events-ns.c tp.c tp.h +gen_ust_events_ns_LDADD = -llttng-ust -lurcu-bp -llttng-ust-fork \ + $(top_builddir)/tests/utils/libtestutils.la \ + $(DL_LIBS) $(POPT_LIBS) +endif diff --git a/tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c b/tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c new file mode 100644 index 000000000..61611853b --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2019 Michael Jeanson + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "utils.h" +#include "signal-helper.h" + +#define TRACEPOINT_DEFINE +#include "tp.h" + +#define LTTNG_PROC_NS_PATH_MAX 40 + +static int nr_iter = 100; +static int debug = 0; +static char *ns_opt = NULL; +static char *after_unshare_file_path = NULL; +static char *before_second_event_file_path = NULL; + +static +struct poptOption opts[] = { + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ + { "debug", 'd', POPT_ARG_NONE, &debug, 0, "Enable debug output", NULL }, + { "ns", 'n', POPT_ARG_STRING, &ns_opt, 0, "Namespace short identifier", NULL }, + { "iter", 'i', POPT_ARG_INT, &nr_iter, 0, "Number of tracepoint iterations", NULL }, + { "after", 'a', POPT_ARG_STRING, &after_unshare_file_path, 0, "after_unshare_file_path,", NULL }, + { "before", 'b', POPT_ARG_STRING, &before_second_event_file_path, 0, "before_second_event_file_path,", NULL }, + POPT_AUTOHELP + { NULL, 0, 0, NULL, 0 } +}; + +static +void debug_printf(const char *format, ...) { + va_list args; + va_start(args, format); + + if (debug) + vfprintf(stderr, format, args); + + va_end(args); +} + +static +ino_t get_ns_inum(char ns[]) { + struct stat sb; + char proc_ns_path[LTTNG_PROC_NS_PATH_MAX]; + + /* + * /proc/thread-self was introduced in kernel v3.17 + */ + if (snprintf(proc_ns_path, LTTNG_PROC_NS_PATH_MAX, + "/proc/thread-self/ns/%s", ns) >= 0) { + if (stat(proc_ns_path, &sb) == 0) { + return sb.st_ino; + } + } + + if (snprintf(proc_ns_path, LTTNG_PROC_NS_PATH_MAX, + "/proc/self/task/%d/%s/net", + gettid(), ns) >= 0) { + + if (stat(proc_ns_path, &sb) == 0) { + return sb.st_ino; + } + } + + return 1; +} + +static +int do_the_needful(int ns_flag, char ns_str[]) { + int ret = 0, i; + ino_t ns1, ns2; + + ns1 = get_ns_inum(ns_str); + debug_printf("Initial %s ns inode number: %lu\n", ns_str, ns1); + + for (i = 0; nr_iter < 0 || i < nr_iter; i++) { + + tracepoint(tp, tptest, ns1); + + if (should_quit) { + break; + } + } + + ret = unshare(ns_flag); + + if (ret == -1) { + perror("unshare"); + ret = 0; + } + + ns2 = get_ns_inum(ns_str); + debug_printf("Post unshare %s ns inode number: %lu\n", ns_str, ns2); + + /* + * Signal that we emited the first event group and that the + * unshare call is completed. + */ + if (after_unshare_file_path) { + ret = create_file(after_unshare_file_path); + + if (ret != 0) { + goto end; + } + } + + /* + * Wait on synchronization before writing second event group. + */ + if (before_second_event_file_path) { + ret = wait_on_file(before_second_event_file_path); + if (ret != 0) { + goto end; + } + } + + for (i = 0; nr_iter < 0 || i < nr_iter; i++) { + + tracepoint(tp, tptest, ns2); + + if (should_quit) { + break; + } + } + +end: + return ret; +} + +// Send X events, change NS, wait for file to sync with test script, send X events in new NS + + +int main(int argc, const char **argv) { + int opt; + int ret = EXIT_SUCCESS; + poptContext pc; + + pc = poptGetContext(NULL, argc, argv, opts, 0); + poptReadDefaultConfig(pc, 0); + + if (argc < 2) { + poptPrintHelp(pc, stderr, 0); + ret = EXIT_FAILURE; + goto end; + } + + while ((opt = poptGetNextOpt(pc)) >= 0) { + switch(opt) { + default: + poptPrintUsage(pc, stderr, 0); + ret = EXIT_FAILURE; + goto end; + } + } + + if (opt < -1) { + /* an error occurred during option processing */ + poptPrintUsage(pc, stderr, 0); + fprintf(stderr, "%s: %s\n", + poptBadOption(pc, POPT_BADOPTION_NOALIAS), + poptStrerror(opt)); + ret = EXIT_FAILURE; + goto end; + } + + if (ns_opt == NULL) { + poptPrintUsage(pc, stderr, 0); + ret = EXIT_FAILURE; + goto end; + } + + if (set_signal_handler()) { + ret = EXIT_FAILURE; + goto end; + } + + if (strncmp(ns_opt, "cgroup", 3) == 0) { + do_the_needful(CLONE_NEWCGROUP, "cgroup"); + } else if (strncmp(ns_opt, "ipc", 3) == 0) { + do_the_needful(CLONE_NEWIPC, "ipc"); + } else if (strncmp(ns_opt, "mnt", 3) == 0) { + do_the_needful(CLONE_NEWNS, "mnt"); + } else if (strncmp(ns_opt, "net", 3) == 0) { + do_the_needful(CLONE_NEWNET, "net"); + } else if (strncmp(ns_opt, "pid", 3) == 0) { + do_the_needful(CLONE_NEWPID, "pid"); + } else if (strncmp(ns_opt, "user", 3) == 0) { + // Will always fail, requires a single threaded application, which can't happen with UST. + do_the_needful(CLONE_NEWUSER, "user"); + } else if (strncmp(ns_opt, "uts", 3) == 0) { + do_the_needful(CLONE_NEWUTS, "uts"); + } else { + printf("invalid ns id\n"); + ret = EXIT_FAILURE; + } + +end: + poptFreeContext(pc); + return ret; +} diff --git a/tests/utils/testapp/gen-ust-events-ns/tp.c b/tests/utils/testapp/gen-ust-events-ns/tp.c new file mode 100644 index 000000000..6f5341436 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-ns/tp.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) - 2012 David Goulet + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR + * IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program for any purpose, + * provided the above notices are retained on all copies. Permission to modify + * the code and to distribute modified code is granted, provided the above + * notices are retained, and a notice that the code was modified is included + * with the above copyright notice. + */ + +#define _LGPL_SOURCE +#define TRACEPOINT_CREATE_PROBES +#include "tp.h" diff --git a/tests/utils/testapp/gen-ust-events-ns/tp.h b/tests/utils/testapp/gen-ust-events-ns/tp.h new file mode 100644 index 000000000..59b3f295b --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-ns/tp.h @@ -0,0 +1,35 @@ +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER tp + +#if !defined(_TRACEPOINT_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACEPOINT_TP_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ + +#include + +TRACEPOINT_EVENT(tp, tptest, + TP_ARGS(ino_t, ns_ino), + TP_FIELDS( + ctf_integer(ino_t, ns_ino, ns_ino) + ) +) + +#endif /* _TRACEPOINT_TP_H */ + +#undef TRACEPOINT_INCLUDE_FILE +#define TRACEPOINT_INCLUDE_FILE ./tp.h + +/* This part must be outside ifdef protection */ +#include -- 2.34.1 From e26422e8271348d43f1282cb2ee46e01ea73adbd Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Tue, 2 Apr 2019 13:38:07 -0400 Subject: [PATCH 07/16] Add kernel namespace context change tests Signed-off-by: Michael Jeanson --- .gitignore | 1 + configure.ac | 1 + tests/regression/kernel/Makefile.am | 2 +- .../regression/kernel/test_ns_contexts_change | 189 +++++++++++++++ tests/utils/testapp/Makefile.am | 4 +- tests/utils/testapp/gen-ns-events/Makefile.am | 8 + .../testapp/gen-ns-events/gen-ns-events.c | 215 ++++++++++++++++++ 7 files changed, 418 insertions(+), 2 deletions(-) create mode 100755 tests/regression/kernel/test_ns_contexts_change create mode 100644 tests/utils/testapp/gen-ns-events/Makefile.am create mode 100644 tests/utils/testapp/gen-ns-events/gen-ns-events.c diff --git a/.gitignore b/.gitignore index 080df57ec..abde871fc 100644 --- a/.gitignore +++ b/.gitignore @@ -132,6 +132,7 @@ health_check /tests/utils/testapp/userspace-probe-elf-cxx-binary/userspace-probe-elf-cxx-binary /tests/utils/testapp/userspace-probe-sdt-binary/foobar_provider.h /tests/utils/testapp/userspace-probe-sdt-binary/userspace-probe-sdt-binary +/tests/utils/testapp/gen-ns-events/gen-ns-events # man pages /doc/man/*.1 diff --git a/configure.ac b/configure.ac index 324e11314..cd58c2648 100644 --- a/configure.ac +++ b/configure.ac @@ -1166,6 +1166,7 @@ AC_CONFIG_FILES([ tests/utils/Makefile tests/utils/tap/Makefile tests/utils/testapp/Makefile + tests/utils/testapp/gen-ns-events/Makefile tests/utils/testapp/gen-ust-events/Makefile tests/utils/testapp/gen-ust-events-ns/Makefile tests/utils/testapp/gen-syscall-events-callstack/Makefile diff --git a/tests/regression/kernel/Makefile.am b/tests/regression/kernel/Makefile.am index 169267adb..f539b80b6 100644 --- a/tests/regression/kernel/Makefile.am +++ b/tests/regression/kernel/Makefile.am @@ -3,7 +3,7 @@ EXTRA_DIST = test_event_basic test_all_events test_syscall \ test_select_poll_epoll test_lttng_logger \ test_userspace_probe test_callstack \ test_syscall validate_select_poll_epoll.py \ - test_ns_contexts + test_ns_contexts test_ns_contexts_change noinst_PROGRAMS = select_poll_epoll select_poll_epoll_SOURCES = select_poll_epoll.c diff --git a/tests/regression/kernel/test_ns_contexts_change b/tests/regression/kernel/test_ns_contexts_change new file mode 100755 index 000000000..b97f12f22 --- /dev/null +++ b/tests/regression/kernel/test_ns_contexts_change @@ -0,0 +1,189 @@ +#!/bin/bash +# +# Copyright (C) 2019 Michael Jeanson +# +# This library is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +TEST_DESC="Kernel tracer - Namespace contexts change" + +CURDIR=$(dirname "$0")/ +TESTDIR=$CURDIR/../.. + +TESTAPP_PATH="$TESTDIR/utils/testapp" +TESTAPP_NAME="gen-ns-events" +TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" + +TESTS_PER_NS=19 + +NUM_TESTS=$((TESTS_PER_NS * 6)) + +source "$TESTDIR/utils/utils.sh" + +# MUST set TESTDIR before calling those functions + +function add_context_kernel_skip_ok() +{ + local session_name=$1 + local channel_name=$2 + local context_name=$3 + local skip_num=$4 + + local ret + + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" add-context -k \ + -s "$session_name" -c "$channel_name" \ + -t "$context_name" 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST" + ret=$? + + if [ "$ret" == "4" ]; then + skip 0 "Current kernel doesn't implement '$context_name' context" $((skip_num + 1)) + else + ok $ret "Add context command for type: $context_name" + fi + + return $ret +} + +function enable_kernel_lttng_event_filter_ok() +{ + local session_name=$1 + local syscall_name=$2 + local channel_name=$3 + local filter=$4 + + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event -k \ + -c "$channel_name" -s "$session_name" \ + --syscall "$syscall_name" \ + -f "$filter" \ + 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST" + + ok $? "Add syscall with filter" +} + +function test_ns() +{ + local ns=$1 + + local session_name="${ns}_ns" + local chan_name="${ns}_ns" + local context_name="${ns}_ns" + + local trace_path + local ns_inode + local file_sync_wait_before_unshare + local file_sync_wait_after_unshare + local file_sync_signal_after_unshare + + # Check if the kernel has support for this ns type + if [ ! -f "/proc/$$/ns/$ns" ]; then + skip 0 "System has no $ns namespace support" $TESTS_PER_NS + return + fi + + trace_path=$(mktemp -d) + file_sync_wait_before_unshare=$(mktemp -u) + file_sync_wait_after_unshare=$(mktemp -u) + file_sync_signal_after_unshare=$(mktemp -u) + + # Get the current ns inode number + ns_inode=$(stat -c '%i' -L "/proc/$$/ns/$ns") + ok $? "Get current $ns namespace inode: $ns_inode" || ns_inode="invalid" + + $TESTAPP_BIN -n "$ns" -a "$file_sync_wait_after_unshare" -b "$file_sync_wait_before_unshare" -s "$file_sync_signal_after_unshare" & + ok $? "Launch test app." + app_pid=$! + + app_ns_inode=$(stat -c '%i' -L "/proc/$app_pid/ns/$ns") + ok $? "Get app current $ns namespace inode: $app_ns_inode" || app_ns_inode="invalid" + + start_lttng_sessiond + + create_lttng_session_ok "$session_name" "$trace_path" + enable_kernel_lttng_channel_ok "$session_name" "$chan_name" + add_context_kernel_skip_ok "$session_name" "$chan_name" "$context_name" 10 + if [ "$?" != "4" ]; then + lttng_enable_kernel_syscall_ok "$session_name" "unshare" "$chan_name" + lttng_track_pid_ok "$app_pid" + start_lttng_tracing_ok "$session_name" + + touch "$file_sync_wait_before_unshare" + + # Let the app do it's thing before entering the synchronisation loop + sleep 0.5 + + while [ ! -f "$file_sync_signal_after_unshare" ]; do + # Break if the app failed / died + if [ ! -f "/proc/$app_pid" ]; then + break + fi + echo "# Waiting for app..." + sleep 0.5 + done + + app_unshare_ns_inode=$(stat -c '%i' -L "/proc/$app_pid/ns/$ns") + ok $? "Get app current $ns namespace inode: $app_unshare_ns_inode" || app_unshare_ns_inode="invalid" + + test "$app_ns_inode" != "invalid" && test "$app_unshare_ns_inode" != "invalid" && test "$app_ns_inode" != "$app_unshare_ns_inode" + ok $? "Reported namespace inode changed after unshare" + + touch "$file_sync_wait_after_unshare" + + stop_lttng_tracing_ok "$session_name" + + # Check that the events contain the right namespace inode number + validate_trace_count "${ns}_ns = $app_ns_inode" "$trace_path" 1 + validate_trace_count "${ns}_ns = $app_unshare_ns_inode" "$trace_path" 1 + fi + + # stop and destroy + destroy_lttng_session_ok "$session_name" + stop_lttng_sessiond + + rm -rf "$trace_path" + rm -f "$file_sync_wait_after_unshare" + rm -f "$file_sync_wait_before_unshare" + rm -f "$file_sync_signal_after_unshare" +} + + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + + +isroot=0 +if [ "$(id -u)" == "0" ]; then + isroot=1 +fi + +skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0 + + +system_has_ns=0 +if [ -d "/proc/$$/ns" ]; then + system_has_ns=1 +fi + +skip $system_has_ns "System has no namespaces support" $NUM_TESTS && exit 0 + + +validate_lttng_modules_present + +test_ns cgroup +test_ns ipc +test_ns mnt +test_ns net +#test_ns pid # pid_ns is special, can't be changed that way +test_ns user +test_ns uts diff --git a/tests/utils/testapp/Makefile.am b/tests/utils/testapp/Makefile.am index e98f4b571..2a4cf5c7b 100644 --- a/tests/utils/testapp/Makefile.am +++ b/tests/utils/testapp/Makefile.am @@ -1,4 +1,6 @@ -SUBDIRS = gen-ust-events \ +SUBDIRS = \ + gen-ns-events \ + gen-ust-events \ gen-ust-events-ns \ gen-ust-nevents \ gen-ust-nevents-str \ diff --git a/tests/utils/testapp/gen-ns-events/Makefile.am b/tests/utils/testapp/gen-ns-events/Makefile.am new file mode 100644 index 000000000..17bc21ffe --- /dev/null +++ b/tests/utils/testapp/gen-ns-events/Makefile.am @@ -0,0 +1,8 @@ +AM_CPPFLAGS += -I$(top_srcdir)/tests/utils -I$(srcdir) \ + -I$(top_srcdir)/tests/utils/testapp + +noinst_PROGRAMS = gen-ns-events +gen_ns_events_SOURCES = gen-ns-events.c +gen_ns_events_LDADD = \ + $(top_builddir)/tests/utils/libtestutils.la \ + $(DL_LIBS) $(POPT_LIBS) diff --git a/tests/utils/testapp/gen-ns-events/gen-ns-events.c b/tests/utils/testapp/gen-ns-events/gen-ns-events.c new file mode 100644 index 000000000..d841b2726 --- /dev/null +++ b/tests/utils/testapp/gen-ns-events/gen-ns-events.c @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2019 Michael Jeanson + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "utils.h" +#include "signal-helper.h" + +#define LTTNG_PROC_NS_PATH_MAX 40 + +static int debug = 0; +static char *ns_opt = NULL; +static char *before_unshare_wait_file_path = NULL; +static char *after_unshare_wait_file_path = NULL; +static char *after_unshare_signal_file_path = NULL; + +static +struct poptOption opts[] = { + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ + { "debug", 'd', POPT_ARG_NONE, &debug, 0, "Enable debug output", NULL }, + { "ns", 'n', POPT_ARG_STRING, &ns_opt, 0, "Namespace short identifier", NULL }, + { "before", 'b', POPT_ARG_STRING, &before_unshare_wait_file_path, 0, "Wait for file before unshare", NULL }, + { "after", 'a', POPT_ARG_STRING, &after_unshare_wait_file_path, 0, "Wait for file after unshare", NULL }, + { "signal", 's', POPT_ARG_STRING, &after_unshare_signal_file_path, 0, "Create signal file after unshare", NULL }, + POPT_AUTOHELP + { NULL, 0, 0, NULL, 0 } +}; + +static +void debug_printf(const char *format, ...) { + va_list args; + va_start(args, format); + + if (debug) + vfprintf(stderr, format, args); + + va_end(args); +} + +static +ino_t get_ns_inum(char ns[]) { + struct stat sb; + char proc_ns_path[LTTNG_PROC_NS_PATH_MAX]; + + /* + * /proc/thread-self was introduced in kernel v3.17 + */ + if (snprintf(proc_ns_path, LTTNG_PROC_NS_PATH_MAX, + "/proc/thread-self/ns/%s", ns) >= 0) { + if (stat(proc_ns_path, &sb) == 0) { + return sb.st_ino; + } + } + + if (snprintf(proc_ns_path, LTTNG_PROC_NS_PATH_MAX, + "/proc/self/task/%d/%s/net", + gettid(), ns) >= 0) { + + if (stat(proc_ns_path, &sb) == 0) { + return sb.st_ino; + } + } + + return 1; +} + +static +int do_the_needful(int ns_flag, char ns_str[]) { + int ret = 0; + ino_t ns1, ns2; + + ns1 = get_ns_inum(ns_str); + debug_printf("Initial %s ns inode number: %lu\n", ns_str, ns1); + + /* + * Wait on synchronization before unshare + */ + if (before_unshare_wait_file_path) { + ret = wait_on_file(before_unshare_wait_file_path); + if (ret != 0) { + goto end; + } + } + + ret = unshare(ns_flag); + + if (ret == -1) { + perror("unshare"); + ret = 0; + } + + ns2 = get_ns_inum(ns_str); + debug_printf("Post unshare %s ns inode number: %lu\n", ns_str, ns2); + + /* + * Signal that the unshare call is completed. + */ + if (after_unshare_signal_file_path) { + ret = create_file(after_unshare_signal_file_path); + + if (ret != 0) { + goto end; + } + } + + /* + * Wait on synchronization after unshare + */ + if (after_unshare_wait_file_path) { + ret = wait_on_file(after_unshare_wait_file_path); + if (ret != 0) { + goto end; + } + } + +end: + return ret; +} + +int main(int argc, const char **argv) { + int opt; + int ret = EXIT_SUCCESS; + poptContext pc; + + pc = poptGetContext(NULL, argc, argv, opts, 0); + poptReadDefaultConfig(pc, 0); + + if (argc < 2) { + poptPrintHelp(pc, stderr, 0); + ret = EXIT_FAILURE; + goto end; + } + + while ((opt = poptGetNextOpt(pc)) >= 0) { + switch(opt) { + default: + poptPrintUsage(pc, stderr, 0); + ret = EXIT_FAILURE; + goto end; + } + } + + if (opt < -1) { + /* an error occurred during option processing */ + poptPrintUsage(pc, stderr, 0); + fprintf(stderr, "%s: %s\n", + poptBadOption(pc, POPT_BADOPTION_NOALIAS), + poptStrerror(opt)); + ret = EXIT_FAILURE; + goto end; + } + + if (ns_opt == NULL) { + poptPrintUsage(pc, stderr, 0); + ret = EXIT_FAILURE; + goto end; + } + + if (set_signal_handler()) { + ret = EXIT_FAILURE; + goto end; + } + + if (strncmp(ns_opt, "cgroup", 3) == 0) { + do_the_needful(CLONE_NEWCGROUP, "cgroup"); + } else if (strncmp(ns_opt, "ipc", 3) == 0) { + do_the_needful(CLONE_NEWIPC, "ipc"); + } else if (strncmp(ns_opt, "mnt", 3) == 0) { + do_the_needful(CLONE_NEWNS, "mnt"); + } else if (strncmp(ns_opt, "net", 3) == 0) { + do_the_needful(CLONE_NEWNET, "net"); + } else if (strncmp(ns_opt, "pid", 3) == 0) { + do_the_needful(CLONE_NEWPID, "pid"); + } else if (strncmp(ns_opt, "user", 3) == 0) { + // Will always fail, requires a single threaded application, which can't happen with UST. + do_the_needful(CLONE_NEWUSER, "user"); + } else if (strncmp(ns_opt, "uts", 3) == 0) { + do_the_needful(CLONE_NEWUTS, "uts"); + } else { + printf("invalid ns id\n"); + ret = EXIT_FAILURE; + } + +end: + poptFreeContext(pc); + return ret; +} -- 2.34.1 From d77fb8c7d20b34918268fea841acd11c0507b034 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Fri, 19 Apr 2019 12:45:44 -0400 Subject: [PATCH 08/16] Metadata: add env fields to ease life of viewer MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add the following field in the env section of the metadata: - trace_name The session name without datetime information. Hence when the session is an auto-generated one, only print LTTNG_DEFAULT_NAME. - trace_creation_time: The time at which the session was created. We use session->creation time for it. - tracer_buffering_scheme The buffering scheme used. The value can be uid or pid. - tracer_buffering_id The key used by the buffering scheme (uid/pid). - isa_length The length of the ISA used. (e.g 32 or 64) Addend these fields ensure that the trace itself carry information that is normally carried via folder hierarchy. e.g test-20190417-174951/ <- trace_name └── ust <- domain └── uid <- tracer_buffering_scheme └── 1000 <- tracer_buffering_id └── 64-bit <- isa_length ├── channel0_0 ├── channel0_1 ├── channel0_2 ├── channel0_3 ├── index │ ├── channel0_0.idx │ ├── channel0_1.idx │ ├── channel0_2.idx │ └── channel0_3.idx └── metadata Per-pid buffering is quite similar. Signed-off-by: Jonathan Rajotte --- src/bin/lttng-sessiond/ust-app.c | 5 +- src/bin/lttng-sessiond/ust-metadata.c | 122 +++++++++++++++++++++++--- src/bin/lttng-sessiond/ust-registry.c | 7 +- src/bin/lttng-sessiond/ust-registry.h | 18 +++- src/common/time.c | 32 +++++++ src/common/time.h | 9 ++ 6 files changed, 178 insertions(+), 15 deletions(-) diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 4bee50496..faa51c759 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -1993,7 +1993,7 @@ static int setup_buffer_reg_pid(struct ust_app_session *ua_sess, app->byte_order, app->version.major, app->version.minor, reg_pid->root_shm_path, reg_pid->shm_path, - ua_sess->euid, ua_sess->egid); + ua_sess->euid, ua_sess->egid, ua_sess->tracing_id, app->uid); if (ret < 0) { /* * reg_pid->registry->reg.ust is NULL upon error, so we need to @@ -2060,7 +2060,8 @@ static int setup_buffer_reg_uid(struct ltt_ust_session *usess, app->uint64_t_alignment, app->long_alignment, app->byte_order, app->version.major, app->version.minor, reg_uid->root_shm_path, - reg_uid->shm_path, usess->uid, usess->gid); + reg_uid->shm_path, usess->uid, usess->gid, + ua_sess->tracing_id, app->uid); if (ret < 0) { /* * reg_uid->registry->reg.ust is NULL upon error, so we need to diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c index a657f7c5d..f05c14c32 100644 --- a/src/bin/lttng-sessiond/ust-metadata.c +++ b/src/bin/lttng-sessiond/ust-metadata.c @@ -217,6 +217,41 @@ void sanitize_ctf_identifier(char *out, const char *in) } } +static +int print_escaped_ctf_string(struct ust_registry_session *session, const char *string) +{ + int ret; + size_t i; + char cur; + + i = 0; + cur = string[i]; + while (cur != '\0') { + switch (cur) { + case '\n': + ret = lttng_metadata_printf(session, "%s", "\\n"); + break; + case '\\': + case '"': + ret = lttng_metadata_printf(session, "%c", '\\'); + if (ret) + goto error; + /* We still print the current char */ + /* Fallthrough */ + default: + ret = lttng_metadata_printf(session, "%c", cur); + break; + } + + if (ret) + goto error; + + cur = string[++i]; + } +error: + return ret; +} + /* Called with session registry mutex held. */ static int ust_metadata_enum_statedump(struct ust_registry_session *session, @@ -869,6 +904,71 @@ int64_t measure_clock_offset(void) return offset_best_sample.offset; } +static +int print_metadata_session_information(struct ust_registry_session *registry) +{ + int ret; + struct ltt_session *session = NULL; + char creation_time[ISO8601_LEN]; + + rcu_read_lock(); + session = session_find_by_id(registry->tracing_id); + if (!session) { + ret = -1; + goto error; + } + + + /* Print the trace name */ + ret = lttng_metadata_printf(registry, " trace_name = \""); + if (ret) { + goto error; + } + + /* + * This is necessary since the creation time is present in the session + * name when it is generated. + */ + if (session->has_auto_generated_name) { + ret = print_escaped_ctf_string(registry, DEFAULT_SESSION_NAME); + } else { + ret = print_escaped_ctf_string(registry, session->name); + } + if (ret) { + goto error; + } + + ret = lttng_metadata_printf(registry, "\";\n"); + if (ret) { + goto error; + } + + /* Prepare creation time */ + ret = time_t_to_ISO8601(creation_time, sizeof(creation_time), + session->creation_time); + + if (ret) { + goto error; + } + + /* Output the reste of the information */ + ret = lttng_metadata_printf(registry, + " trace_creation_time = \"%s\";\n" + " hostname = \"%s\";\n", + creation_time, + session->hostname); + if (ret) { + goto error; + } + +error: + if (session) { + session_put(session); + } + rcu_read_unlock(); + return ret; +} + /* * Should be called with session registry mutex held. */ @@ -880,7 +980,6 @@ int ust_metadata_session_statedump(struct ust_registry_session *session, char uuid_s[UUID_STR_LEN], clock_uuid_s[UUID_STR_LEN]; int ret = 0; - char hostname[HOST_NAME_MAX]; assert(session); @@ -930,25 +1029,28 @@ int ust_metadata_session_statedump(struct ust_registry_session *session, if (ret) goto end; - /* ignore error, just use empty string if error. */ - hostname[0] = '\0'; - ret = gethostname(hostname, sizeof(hostname)); - if (ret && errno == ENAMETOOLONG) - hostname[HOST_NAME_MAX - 1] = '\0'; ret = lttng_metadata_printf(session, "env {\n" - " hostname = \"%s\";\n" " domain = \"ust\";\n" " tracer_name = \"lttng-ust\";\n" " tracer_major = %u;\n" - " tracer_minor = %u;\n", - hostname, + " tracer_minor = %u;\n" + " tracer_buffering_scheme = \"%s\";\n" + " tracer_buffering_id = %u;\n" + " isa_length = %u;\n", major, - minor + minor, + app ? "pid" : "uid", + app ? (int) app->uid : (int) session->tracing_uid, + session->bits_per_long ); if (ret) goto end; + ret = print_metadata_session_information(session); + if (ret) + goto end; + /* * If per-application registry, we can output extra information * about the application. diff --git a/src/bin/lttng-sessiond/ust-registry.c b/src/bin/lttng-sessiond/ust-registry.c index a8db79ea6..c495d86b7 100644 --- a/src/bin/lttng-sessiond/ust-registry.c +++ b/src/bin/lttng-sessiond/ust-registry.c @@ -880,7 +880,9 @@ int ust_registry_session_init(struct ust_registry_session **sessionp, const char *root_shm_path, const char *shm_path, uid_t euid, - gid_t egid) + gid_t egid, + uint64_t tracing_id, + uid_t tracing_uid) { int ret; struct ust_registry_session *session; @@ -962,6 +964,9 @@ int ust_registry_session_init(struct ust_registry_session **sessionp, goto error; } + session->tracing_id = tracing_id; + session->tracing_uid = tracing_uid; + pthread_mutex_lock(&session->lock); ret = ust_metadata_session_statedump(session, app, major, minor); pthread_mutex_unlock(&session->lock); diff --git a/src/bin/lttng-sessiond/ust-registry.h b/src/bin/lttng-sessiond/ust-registry.h index 2940ab7ac..2fc2dff87 100644 --- a/src/bin/lttng-sessiond/ust-registry.h +++ b/src/bin/lttng-sessiond/ust-registry.h @@ -131,6 +131,10 @@ struct ust_registry_session { */ uint32_t major; uint32_t minor; + + /* The id of the parent session */ + uint64_t tracing_id; + uid_t tracing_uid; }; struct ust_registry_channel { @@ -291,7 +295,9 @@ int ust_registry_session_init(struct ust_registry_session **sessionp, const char *root_shm_path, const char *shm_path, uid_t euid, - gid_t egid); + gid_t egid, + uint64_t tracing_id, + uid_t tracing_uid); void ust_registry_session_destroy(struct ust_registry_session *session); int ust_registry_create_event(struct ust_registry_session *session, @@ -351,7 +357,15 @@ int ust_registry_session_init(struct ust_registry_session **sessionp, uint32_t uint32_t_alignment, uint32_t uint64_t_alignment, uint32_t long_alignment, - int byte_order) + int byte_order, + uint32_t major, + uint32_t minor, + const char *root_shm_path, + const char *shm_path, + uid_t euid, + gid_t egid, + uint64_t tracing_id, + uid_t tracing_uid); { return 0; } diff --git a/src/common/time.c b/src/common/time.c index a01c16df5..387db3e32 100644 --- a/src/common/time.c +++ b/src/common/time.c @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -68,6 +69,37 @@ struct timespec timespec_abs_diff(struct timespec t1, struct timespec t2) return res; } +LTTNG_HIDDEN +int time_t_to_ISO8601(char *dest, size_t dest_size, time_t time) +{ + int ret; + struct tm tm, *timeinfo; + + if (dest_size < ISO8601_LEN) { + ERR("Failed to format time to ISO8601 destination too small"); + ret = -1; + goto end; + } + + timeinfo = localtime_r(&time, &tm); + if (!timeinfo) { + PERROR("localtime"); + ret = -1; + goto end; + } + + ret = strftime(dest, dest_size, ISO8601_FORMAT, timeinfo); + if (ret == 0) { + ERR("Failed to format time to ISO8601"); + ret = -1; + goto end; + } + + ret = 0; +end: + return ret; +} + static void __attribute__((constructor)) init_locale_utf8_support(void) { diff --git a/src/common/time.h b/src/common/time.h index 24513d30b..7e760599f 100644 --- a/src/common/time.h +++ b/src/common/time.h @@ -46,6 +46,9 @@ bool locale_supports_utf8(void); #define MIN_UNIT "m" #define HR_UNIT "h" +#define ISO8601_FORMAT "%Y%m%dT%H%M%S%z" +#define ISO8601_LEN 21 + /* * timespec_to_ms: Convert timespec to milliseconds. * @@ -61,4 +64,10 @@ int timespec_to_ms(struct timespec ts, unsigned long *ms); LTTNG_HIDDEN struct timespec timespec_abs_diff(struct timespec ts_a, struct timespec ts_b); +/* + * Format time_t to ISO8601 compatible format. + */ +LTTNG_HIDDEN +int time_t_to_ISO8601(char *s, size_t s_size, time_t time); + #endif /* LTTNG_TIME_H */ -- 2.34.1 From cb0d8c49f51db9be5b72ddefd2c8c4b7ee539c95 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 23 Apr 2019 14:14:10 -0400 Subject: [PATCH 09/16] Fix: max len for iso8601 format is 26 The expended format of iso8601 is: 2019-04-23T18:03:48+00:00 Signed-off-by: Jonathan Rajotte --- src/common/time.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/time.h b/src/common/time.h index 7e760599f..5ea8c6628 100644 --- a/src/common/time.h +++ b/src/common/time.h @@ -47,7 +47,7 @@ bool locale_supports_utf8(void); #define HR_UNIT "h" #define ISO8601_FORMAT "%Y%m%dT%H%M%S%z" -#define ISO8601_LEN 21 +#define ISO8601_LEN 26 /* * timespec_to_ms: Convert timespec to milliseconds. -- 2.34.1 From 49938fb6a42264963829418b06238dd6aa529a32 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Wed, 17 Apr 2019 17:58:04 -0400 Subject: [PATCH 10/16] Support LTTNG_KERNEL_SESSION_SET_NAME of lttng-modules Signed-off-by: Jonathan Rajotte --- src/bin/lttng-sessiond/kernel.c | 5 +++++ src/common/kernel-ctl/kernel-ctl.c | 10 ++++++++++ src/common/kernel-ctl/kernel-ctl.h | 1 + src/common/kernel-ctl/kernel-ioctl.h | 2 ++ src/common/lttng-kernel.h | 9 +++++++++ 5 files changed, 27 insertions(+) diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index b4fc995ce..75b76db2e 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -125,6 +125,11 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd) DBG("Kernel session created (fd: %d)", lks->fd); + ret = kernctl_session_set_name(lks->fd, session->name); + if (ret) { + WARN("Could not set kernel session name"); + } + return 0; error: diff --git a/src/common/kernel-ctl/kernel-ctl.c b/src/common/kernel-ctl/kernel-ctl.c index 047d40a34..6a37015ae 100644 --- a/src/common/kernel-ctl/kernel-ctl.c +++ b/src/common/kernel-ctl/kernel-ctl.c @@ -238,6 +238,16 @@ int kernctl_session_regenerate_statedump(int fd) return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_STATEDUMP); } +int kernctl_session_set_name(int fd, const char *name) +{ + struct lttng_kernel_session_name session_name; + + strncpy(session_name.name, name, LTTNG_KERNEL_SESSION_NAME_LEN); + + return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_SET_NAME, + &session_name); +} + int kernctl_create_stream(int fd) { return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_STREAM, diff --git a/src/common/kernel-ctl/kernel-ctl.h b/src/common/kernel-ctl/kernel-ctl.h index 841c31da0..884929ac1 100644 --- a/src/common/kernel-ctl/kernel-ctl.h +++ b/src/common/kernel-ctl/kernel-ctl.h @@ -67,6 +67,7 @@ int kernctl_list_tracker_pids(int fd); int kernctl_session_regenerate_metadata(int fd); int kernctl_session_regenerate_statedump(int fd); +int kernctl_session_set_name(int fd, const char *name); /* Buffer operations */ diff --git a/src/common/kernel-ctl/kernel-ioctl.h b/src/common/kernel-ctl/kernel-ioctl.h index e7ff50b24..ce910e96f 100644 --- a/src/common/kernel-ctl/kernel-ioctl.h +++ b/src/common/kernel-ctl/kernel-ioctl.h @@ -145,6 +145,8 @@ #define LTTNG_KERNEL_SESSION_METADATA_REGEN _IO(0xF6, 0x59) /* 0x5A and 0x5B are reserved for a future ABI-breaking cleanup. */ #define LTTNG_KERNEL_SESSION_STATEDUMP _IO(0xF6, 0x5C) +#define LTTNG_KERNEL_SESSION_SET_NAME \ + _IOR(0xF6, 0x5D, struct lttng_kernel_session_name) /* Channel FD ioctl */ #define LTTNG_KERNEL_STREAM _IO(0xF6, 0x62) diff --git a/src/common/lttng-kernel.h b/src/common/lttng-kernel.h index 9d777ee77..66cc99681 100644 --- a/src/common/lttng-kernel.h +++ b/src/common/lttng-kernel.h @@ -27,6 +27,7 @@ #define LTTNG_KERNEL_SYM_NAME_LEN 256 #define LTTNG_KERNEL_MAX_UPROBE_NUM 32 +#define LTTNG_KERNEL_SESSION_NAME_LEN 256 /* * LTTng DebugFS ABI structures. @@ -197,4 +198,12 @@ struct lttng_kernel_filter_bytecode { char data[0]; } LTTNG_PACKED; +/* + * kernel session + */ +struct lttng_kernel_session_name { + char name[LTTNG_KERNEL_SESSION_NAME_LEN]; +} LTTNG_PACKED; + + #endif /* _LTTNG_KERNEL_H */ -- 2.34.1 From da7587b7850040b371b3a588a9d84535ea6cf530 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 23 Apr 2019 14:13:42 -0400 Subject: [PATCH 11/16] Support LTTNG_KERNEL_SESSION_SET_CREATION_NAME of lttng-modules Signed-off-by: Jonathan Rajotte --- src/bin/lttng-sessiond/kernel.c | 5 +++++ src/common/kernel-ctl/kernel-ctl.c | 15 +++++++++++++++ src/common/kernel-ctl/kernel-ctl.h | 1 + src/common/kernel-ctl/kernel-ioctl.h | 2 ++ src/common/lttng-kernel.h | 5 +++++ 5 files changed, 28 insertions(+) diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 75b76db2e..251d93456 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -130,6 +130,11 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd) WARN("Could not set kernel session name"); } + ret = kernctl_session_set_creation_time(lks->fd, session->creation_time); + if (ret) { + WARN("Could not set kernel session creation time"); + } + return 0; error: diff --git a/src/common/kernel-ctl/kernel-ctl.c b/src/common/kernel-ctl/kernel-ctl.c index 6a37015ae..8c0025c93 100644 --- a/src/common/kernel-ctl/kernel-ctl.c +++ b/src/common/kernel-ctl/kernel-ctl.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "kernel-ctl.h" #include "kernel-ioctl.h" @@ -248,6 +249,20 @@ int kernctl_session_set_name(int fd, const char *name) &session_name); } +int kernctl_session_set_creation_time(int fd, time_t time) +{ + int ret; + struct lttng_kernel_session_creation_time creation_time; + + ret = time_t_to_ISO8601(creation_time.iso8601, sizeof(creation_time.iso8601), time); + if (ret) { + return -1; + } + + return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_SET_CREATION_TIME, + &creation_time); +} + int kernctl_create_stream(int fd) { return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_STREAM, diff --git a/src/common/kernel-ctl/kernel-ctl.h b/src/common/kernel-ctl/kernel-ctl.h index 884929ac1..053e7df63 100644 --- a/src/common/kernel-ctl/kernel-ctl.h +++ b/src/common/kernel-ctl/kernel-ctl.h @@ -68,6 +68,7 @@ int kernctl_list_tracker_pids(int fd); int kernctl_session_regenerate_metadata(int fd); int kernctl_session_regenerate_statedump(int fd); int kernctl_session_set_name(int fd, const char *name); +int kernctl_session_set_creation_time(int fd, time_t time); /* Buffer operations */ diff --git a/src/common/kernel-ctl/kernel-ioctl.h b/src/common/kernel-ctl/kernel-ioctl.h index ce910e96f..8d39abbe3 100644 --- a/src/common/kernel-ctl/kernel-ioctl.h +++ b/src/common/kernel-ctl/kernel-ioctl.h @@ -147,6 +147,8 @@ #define LTTNG_KERNEL_SESSION_STATEDUMP _IO(0xF6, 0x5C) #define LTTNG_KERNEL_SESSION_SET_NAME \ _IOR(0xF6, 0x5D, struct lttng_kernel_session_name) +#define LTTNG_KERNEL_SESSION_SET_CREATION_TIME \ + _IOR(0xF6, 0x5E, struct lttng_kernel_session_creation_time) /* Channel FD ioctl */ #define LTTNG_KERNEL_STREAM _IO(0xF6, 0x62) diff --git a/src/common/lttng-kernel.h b/src/common/lttng-kernel.h index 66cc99681..54a0738b7 100644 --- a/src/common/lttng-kernel.h +++ b/src/common/lttng-kernel.h @@ -28,6 +28,7 @@ #define LTTNG_KERNEL_SYM_NAME_LEN 256 #define LTTNG_KERNEL_MAX_UPROBE_NUM 32 #define LTTNG_KERNEL_SESSION_NAME_LEN 256 +#define LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN 26 /* * LTTng DebugFS ABI structures. @@ -205,5 +206,9 @@ struct lttng_kernel_session_name { char name[LTTNG_KERNEL_SESSION_NAME_LEN]; } LTTNG_PACKED; +struct lttng_kernel_session_creation_time { + char iso8601[LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN]; +} LTTNG_PACKED; + #endif /* _LTTNG_KERNEL_H */ -- 2.34.1 From b2543b2047a84638b3c8eb8bb7babdc8824c0a94 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 23 Apr 2019 14:40:05 -0400 Subject: [PATCH 12/16] Fix: use DEFAULT_SESSION_NAME when name was generated Signed-off-by: Jonathan Rajotte --- src/bin/lttng-sessiond/kernel.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 251d93456..cedb9346c 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -125,14 +125,24 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd) DBG("Kernel session created (fd: %d)", lks->fd); - ret = kernctl_session_set_name(lks->fd, session->name); + /* + * This is necessary since the creation time is present in the session + * name when it is generated. + */ + if (session->has_auto_generated_name) { + ret = kernctl_session_set_name(lks->fd, DEFAULT_SESSION_NAME); + } else { + ret = kernctl_session_set_name(lks->fd, session->name); + } if (ret) { - WARN("Could not set kernel session name"); + WARN("Could not set kernel session name for session %" PRIu64 " name: %s", + session->id, session->name); } ret = kernctl_session_set_creation_time(lks->fd, session->creation_time); if (ret) { - WARN("Could not set kernel session creation time"); + WARN("Could not set kernel session creation time for session %" PRIu64 " name: %s", + session->id, session->name); } return 0; -- 2.34.1 From 7af87e598b8412631cf3f48975a57965fad49fcf Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 23 Apr 2019 14:52:30 -0400 Subject: [PATCH 13/16] Fix: creation_time is actually a datetime Name it accordingly. Signed-off-by: Jonathan Rajotte --- src/bin/lttng-sessiond/ust-metadata.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c index f05c14c32..324169559 100644 --- a/src/bin/lttng-sessiond/ust-metadata.c +++ b/src/bin/lttng-sessiond/ust-metadata.c @@ -909,7 +909,7 @@ int print_metadata_session_information(struct ust_registry_session *registry) { int ret; struct ltt_session *session = NULL; - char creation_time[ISO8601_LEN]; + char creation_datetime[ISO8601_LEN]; rcu_read_lock(); session = session_find_by_id(registry->tracing_id); @@ -944,7 +944,7 @@ int print_metadata_session_information(struct ust_registry_session *registry) } /* Prepare creation time */ - ret = time_t_to_ISO8601(creation_time, sizeof(creation_time), + ret = time_t_to_ISO8601(creation_datetime, sizeof(creation_datetime), session->creation_time); if (ret) { @@ -953,9 +953,9 @@ int print_metadata_session_information(struct ust_registry_session *registry) /* Output the reste of the information */ ret = lttng_metadata_printf(registry, - " trace_creation_time = \"%s\";\n" + " trace_creation_datetime = \"%s\";\n" " hostname = \"%s\";\n", - creation_time, + creation_datetime, session->hostname); if (ret) { goto error; -- 2.34.1 From d7912dd1d4af8e8f0e92b2479a2de73f9da0fd11 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Wed, 24 Apr 2019 11:22:23 -0400 Subject: [PATCH 14/16] Metadata: add vpid_datetime field to metadta env This information can be used by viewer and previously contain in the path hierarchy of a trace. Add the registration_time field to ust_app to access it when printing metadata. Reuse this field to generate the trace path. Signed-off-by: Jonathan Rajotte --- src/bin/lttng-sessiond/ust-app.c | 7 ++-- src/bin/lttng-sessiond/ust-app.h | 5 +++ src/bin/lttng-sessiond/ust-metadata.c | 49 ++++++++++++++++++++------- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index faa51c759..8b3028c57 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -1831,15 +1831,12 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan, static void shadow_copy_session(struct ust_app_session *ua_sess, struct ltt_ust_session *usess, struct ust_app *app) { - time_t rawtime; struct tm *timeinfo; char datetime[16]; int ret; char tmp_shm_path[PATH_MAX]; - /* Get date and time for unique app path */ - time(&rawtime); - timeinfo = localtime(&rawtime); + timeinfo = localtime(&app->registration_time); strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo); DBG2("Shadow copy of session handle %d", ua_sess->handle); @@ -3377,6 +3374,8 @@ void ust_app_add(struct ust_app *app) assert(app); assert(app->notify_sock >= 0); + app->registration_time = time(NULL); + rcu_read_lock(); /* diff --git a/src/bin/lttng-sessiond/ust-app.h b/src/bin/lttng-sessiond/ust-app.h index b90ff4bce..d9279f0e4 100644 --- a/src/bin/lttng-sessiond/ust-app.h +++ b/src/bin/lttng-sessiond/ust-app.h @@ -298,6 +298,11 @@ struct ust_app { * to a negative value indicating that the agent application is gone. */ int agent_app_sock; + /* + * Time at which the app is registred. + * Used for path creation + */ + time_t registration_time; }; #ifdef HAVE_LIBLTTNG_UST_CTL diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c index 324169559..48db2cc56 100644 --- a/src/bin/lttng-sessiond/ust-metadata.c +++ b/src/bin/lttng-sessiond/ust-metadata.c @@ -969,6 +969,39 @@ error: return ret; } +static +int print_metadata_app_information(struct ust_registry_session *registry, + struct ust_app *app) +{ + int ret; + char datetime[ISO8601_LEN]; + + if (!app) { + ret = 0; + goto end; + } + + ret = time_t_to_ISO8601(datetime, sizeof(datetime), + app->registration_time); + if (ret) { + goto end; + } + + ret = lttng_metadata_printf(registry, + " tracer_patchlevel = %u;\n" + " vpid = %d;\n" + " procname = \"%s\";\n" + " vpid_datetime = \"%s\";\n" , + app->version.patchlevel, + (int) app->pid, + app->name, + datetime + ); + +end: + return ret; +} + /* * Should be called with session registry mutex held. */ @@ -1055,18 +1088,10 @@ int ust_metadata_session_statedump(struct ust_registry_session *session, * If per-application registry, we can output extra information * about the application. */ - if (app) { - ret = lttng_metadata_printf(session, - " tracer_patchlevel = %u;\n" - " vpid = %d;\n" - " procname = \"%s\";\n", - app->version.patchlevel, - (int) app->pid, - app->name - ); - if (ret) - goto end; - } + ret = print_metadata_app_information(session, app); + if (ret) + goto end; + ret = lttng_metadata_printf(session, "};\n\n" -- 2.34.1 From 7b5f9b209f57ad2633fb270ba2c11ffb4c985c4f Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Wed, 24 Apr 2019 16:52:47 -0400 Subject: [PATCH 15/16] Fix: use app-pid when in pid mode for buffering_scheme_id Signed-off-by: Jonathan Rajotte --- src/bin/lttng-sessiond/ust-metadata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c index 48db2cc56..f27b6e832 100644 --- a/src/bin/lttng-sessiond/ust-metadata.c +++ b/src/bin/lttng-sessiond/ust-metadata.c @@ -1074,7 +1074,7 @@ int ust_metadata_session_statedump(struct ust_registry_session *session, major, minor, app ? "pid" : "uid", - app ? (int) app->uid : (int) session->tracing_uid, + app ? (int) app->pid : (int) session->tracing_uid, session->bits_per_long ); if (ret) -- 2.34.1 From db14a5c98fe64b74230422ec4c6affb27ab830fc Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Wed, 24 Apr 2019 09:12:57 -0400 Subject: [PATCH 16/16] Fix: libcompat is now part of libcommon 18710679a8ac57fda5dbd26cf16bb180dce9e286 includes libcompat into libcommon. This also make the compat_(e)poll_* symbols visible through liblttng-ctl. Same for fcntl compat. Mark them as hidden. These symbols are not visible on the 2.10/2.11 branches. Signed-off-by: Jonathan Rajotte --- src/bin/lttng-relayd/Makefile.am | 1 - src/bin/lttng-sessiond/Makefile.am | 1 - src/common/compat/compat-epoll.c | 6 +++++ src/common/compat/compat-fcntl.c | 1 + src/common/compat/compat-poll.c | 5 +++++ src/common/compat/fcntl.h | 4 +++- src/common/compat/poll.h | 36 ++++++++++++++++++++---------- tests/unit/Makefile.am | 4 ---- 8 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/bin/lttng-relayd/Makefile.am b/src/bin/lttng-relayd/Makefile.am index cf56ea495..6320375b4 100644 --- a/src/bin/lttng-relayd/Makefile.am +++ b/src/bin/lttng-relayd/Makefile.am @@ -29,7 +29,6 @@ lttng_relayd_LDADD = -lurcu-common -lurcu \ $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \ $(top_builddir)/src/common/hashtable/libhashtable.la \ $(top_builddir)/src/common/libcommon.la \ - $(top_builddir)/src/common/compat/libcompat.la \ $(top_builddir)/src/common/index/libindex.la \ $(top_builddir)/src/common/health/libhealth.la \ $(top_builddir)/src/common/config/libconfig.la \ diff --git a/src/bin/lttng-sessiond/Makefile.am b/src/bin/lttng-sessiond/Makefile.am index 9800c4b2c..6bfa5f389 100644 --- a/src/bin/lttng-sessiond/Makefile.am +++ b/src/bin/lttng-sessiond/Makefile.am @@ -68,7 +68,6 @@ lttng_sessiond_LDADD = -lurcu-common -lurcu $(KMOD_LIBS) \ $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la \ $(top_builddir)/src/common/hashtable/libhashtable.la \ $(top_builddir)/src/common/libcommon.la \ - $(top_builddir)/src/common/compat/libcompat.la \ $(top_builddir)/src/common/relayd/librelayd.la \ $(top_builddir)/src/common/testpoint/libtestpoint.la \ $(top_builddir)/src/common/health/libhealth.la \ diff --git a/src/common/compat/compat-epoll.c b/src/common/compat/compat-epoll.c index 6a781c7ae..cf92c63b4 100644 --- a/src/common/compat/compat-epoll.c +++ b/src/common/compat/compat-epoll.c @@ -67,6 +67,7 @@ error: /* * Create epoll set and allocate returned events structure. */ +LTTNG_HIDDEN int compat_epoll_create(struct lttng_poll_event *events, int size, int flags) { int ret; @@ -119,6 +120,7 @@ error: /* * Add a fd to the epoll set with requesting events. */ +LTTNG_HIDDEN int compat_epoll_add(struct lttng_poll_event *events, int fd, uint32_t req_events) { int ret; @@ -166,6 +168,7 @@ error: /* * Remove a fd from the epoll set. */ +LTTNG_HIDDEN int compat_epoll_del(struct lttng_poll_event *events, int fd) { int ret; @@ -200,6 +203,7 @@ error: /* * Set an fd's events. */ +LTTNG_HIDDEN int compat_epoll_mod(struct lttng_poll_event *events, int fd, uint32_t req_events) { int ret; @@ -241,6 +245,7 @@ error: /* * Wait on epoll set. This is a blocking call of timeout value. */ +LTTNG_HIDDEN int compat_epoll_wait(struct lttng_poll_event *events, int timeout) { int ret; @@ -293,6 +298,7 @@ error: /* * Setup poll set maximum size. */ +LTTNG_HIDDEN int compat_epoll_set_max_size(void) { int ret, fd, retval = 0; diff --git a/src/common/compat/compat-fcntl.c b/src/common/compat/compat-fcntl.c index c6c6b4e99..a0f4a1997 100644 --- a/src/common/compat/compat-fcntl.c +++ b/src/common/compat/compat-fcntl.c @@ -21,6 +21,7 @@ #ifdef __linux__ +LTTNG_HIDDEN int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags) { diff --git a/src/common/compat/compat-poll.c b/src/common/compat/compat-poll.c index b45b39dc6..11149f4d4 100644 --- a/src/common/compat/compat-poll.c +++ b/src/common/compat/compat-poll.c @@ -102,6 +102,7 @@ error: /* * Create pollfd data structure. */ +LTTNG_HIDDEN int compat_poll_create(struct lttng_poll_event *events, int size) { struct compat_poll_event_array *current, *wait; @@ -200,6 +201,7 @@ error: /* * Modify an fd's events.. */ +LTTNG_HIDDEN int compat_poll_mod(struct lttng_poll_event *events, int fd, uint32_t req_events) { @@ -236,6 +238,7 @@ error: /* * Remove a fd from the pollfd structure. */ +LTTNG_HIDDEN int compat_poll_del(struct lttng_poll_event *events, int fd) { int new_size, i, count = 0, ret; @@ -281,6 +284,7 @@ error: /* * Wait on poll() with timeout. Blocking call. */ +LTTNG_HIDDEN int compat_poll_wait(struct lttng_poll_event *events, int timeout) { int ret; @@ -328,6 +332,7 @@ error: /* * Setup poll set maximum size. */ +LTTNG_HIDDEN int compat_poll_set_max_size(void) { int ret, retval = 0; diff --git a/src/common/compat/fcntl.h b/src/common/compat/fcntl.h index 1efcea797..edb19906d 100644 --- a/src/common/compat/fcntl.h +++ b/src/common/compat/fcntl.h @@ -21,6 +21,7 @@ #include #include #include +#include #if (defined(__FreeBSD__) || defined(__CYGWIN__)) typedef long long off64_t; @@ -31,7 +32,8 @@ typedef off64_t loff_t; #endif #ifdef __linux__ -extern int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes, +LTTNG_HIDDEN +int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags); #define lttng_sync_file_range(fd, offset, nbytes, flags) \ compat_sync_file_range(fd, offset, nbytes, flags) diff --git a/src/common/compat/poll.h b/src/common/compat/poll.h index d4bd87f58..5379c806a 100644 --- a/src/common/compat/poll.h +++ b/src/common/compat/poll.h @@ -122,7 +122,8 @@ static inline int __lttng_epoll_get_prev_fd(struct lttng_poll_event *events, /* * Create the epoll set. No memory allocation is done here. */ -extern int compat_epoll_create(struct lttng_poll_event *events, +LTTNG_HIDDEN +int compat_epoll_create(struct lttng_poll_event *events, int size, int flags); #define lttng_poll_create(events, size, flags) \ compat_epoll_create(events, size, flags) @@ -152,14 +153,16 @@ static inline int compat_glibc_epoll_create(int size, int flags) * Wait on epoll set with the number of fd registered to the lttng_poll_event * data structure (events). */ -extern int compat_epoll_wait(struct lttng_poll_event *events, int timeout); +LTTNG_HIDDEN +int compat_epoll_wait(struct lttng_poll_event *events, int timeout); #define lttng_poll_wait(events, timeout) \ compat_epoll_wait(events, timeout) /* * Add a fd to the epoll set and resize the epoll_event structure if needed. */ -extern int compat_epoll_add(struct lttng_poll_event *events, +LTTNG_HIDDEN +int compat_epoll_add(struct lttng_poll_event *events, int fd, uint32_t req_events); #define lttng_poll_add(events, fd, req_events) \ compat_epoll_add(events, fd, req_events) @@ -167,14 +170,16 @@ extern int compat_epoll_add(struct lttng_poll_event *events, /* * Remove a fd from the epoll set. */ -extern int compat_epoll_del(struct lttng_poll_event *events, int fd); +LTTNG_HIDDEN +int compat_epoll_del(struct lttng_poll_event *events, int fd); #define lttng_poll_del(events, fd) \ compat_epoll_del(events, fd) /* * Modify an fd's events in the epoll set. */ -extern int compat_epoll_mod(struct lttng_poll_event *events, +LTTNG_HIDDEN +int compat_epoll_mod(struct lttng_poll_event *events, int fd, uint32_t req_events); #define lttng_poll_mod(events, fd, req_events) \ compat_epoll_add(events, fd, req_events) @@ -182,7 +187,8 @@ extern int compat_epoll_mod(struct lttng_poll_event *events, /* * Set up the poll set limits variable poll_max_size */ -extern int compat_epoll_set_max_size(void); +LTTNG_HIDDEN +int compat_epoll_set_max_size(void); #define lttng_poll_set_max_size() \ compat_epoll_set_max_size() @@ -326,7 +332,8 @@ static inline int __lttng_poll_get_prev_fd(struct lttng_poll_event *events, /* * Create a pollfd structure of size 'size'. */ -extern int compat_poll_create(struct lttng_poll_event *events, int size); +LTTNG_HIDDEN +int compat_poll_create(struct lttng_poll_event *events, int size); #define lttng_poll_create(events, size, flags) \ compat_poll_create(events, size) @@ -334,14 +341,16 @@ extern int compat_poll_create(struct lttng_poll_event *events, int size); * Wait on poll(2) event with nb_fd registered to the lttng_poll_event data * structure. */ -extern int compat_poll_wait(struct lttng_poll_event *events, int timeout); +LTTNG_HIDDEN +int compat_poll_wait(struct lttng_poll_event *events, int timeout); #define lttng_poll_wait(events, timeout) \ compat_poll_wait(events, timeout) /* * Add the fd to the pollfd structure. Resize if needed. */ -extern int compat_poll_add(struct lttng_poll_event *events, +LTTNG_HIDDEN +int compat_poll_add(struct lttng_poll_event *events, int fd, uint32_t req_events); #define lttng_poll_add(events, fd, req_events) \ compat_poll_add(events, fd, req_events) @@ -351,14 +360,16 @@ extern int compat_poll_add(struct lttng_poll_event *events, * pollfd, data is copied from the old pollfd to the new and, finally, the old * one is freed(). */ -extern int compat_poll_del(struct lttng_poll_event *events, int fd); +LTTNG_HIDDEN +int compat_poll_del(struct lttng_poll_event *events, int fd); #define lttng_poll_del(events, fd) \ compat_poll_del(events, fd) /* * Modify an fd's events in the epoll set. */ -extern int compat_poll_mod(struct lttng_poll_event *events, +LTTNG_HIDDEN +int compat_poll_mod(struct lttng_poll_event *events, int fd, uint32_t req_events); #define lttng_poll_mod(events, fd, req_events) \ compat_poll_add(events, fd, req_events) @@ -366,7 +377,8 @@ extern int compat_poll_mod(struct lttng_poll_event *events, /* * Set up the poll set limits variable poll_max_size */ -extern int compat_poll_set_max_size(void); +LTTNG_HIDDEN +int compat_poll_set_max_size(void); #define lttng_poll_set_max_size() \ compat_poll_set_max_size() diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 5f485f007..bd25d6a3f 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -70,9 +70,7 @@ SESSIOND_OBJS = $(top_builddir)/src/bin/lttng-sessiond/buffer-registry.$(OBJEXT) $(top_builddir)/src/bin/lttng-sessiond/thread-utils.$(OBJEXT) \ $(top_builddir)/src/bin/lttng-sessiond/process-utils.$(OBJEXT) \ $(top_builddir)/src/bin/lttng-sessiond/thread.$(OBJEXT) \ - $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/common/testpoint/libtestpoint.la \ - $(top_builddir)/src/common/compat/libcompat.la \ $(top_builddir)/src/common/health/libhealth.la \ $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la @@ -93,7 +91,6 @@ test_session_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBRELAYD) $(LIBSESSIOND_COMM) \ $(KMOD_LIBS) \ $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \ $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la \ - $(top_builddir)/src/common/compat/libcompat.la \ $(top_builddir)/src/common/testpoint/libtestpoint.la \ $(top_builddir)/src/common/health/libhealth.la \ $(top_builddir)/src/common/config/libconfig.la \ @@ -114,7 +111,6 @@ test_ust_data_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBRELAYD) $(LIBSESSIOND_COMM) \ $(KMOD_LIBS) \ $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \ $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la \ - $(top_builddir)/src/common/compat/libcompat.la \ $(top_builddir)/src/common/testpoint/libtestpoint.la \ $(top_builddir)/src/common/health/libhealth.la \ $(top_builddir)/src/common/config/libconfig.la \ -- 2.34.1