From 06da884333463ac5d2e93eb1f3ba1a2497bf1756 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 1 Dec 2020 12:19:53 -0500 Subject: [PATCH] Fix: snapshot path have domain subdir duplicate "ust/ust" or "kernel/kernel" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is a combination of 2 commits. This is the 1st commit message: Observed issue ============== lttng-ivc observed unexpected path generated for streamed snapshot: joraj-alpa/ test-20190319-120000-20210113-110101/ snapshot-1-20210113-110102-0/ * ust/ * ust/ pid/ app-ust-2362198-20210113-110101/ channel_0 channel_1 metadata channel_2 channel_3 "ust" the domain subdir is present two-time instead off only one time. The same problem is seen for kernel snapshots. Cause ===== Based on dissection the problem was introduced by commit 5da88b0f58d7f838068037ea449ddfb25d3e85ad [1] For snapshots, the consumer output object of the snapshot output and information is fetched from the *original* consumer output. (code block around src/bin/lttng-sessiond/cmd.c:4748) The snapshot consumer output does not contains the necessary information to populate domain_subdir on copy (domain_subdir is '\0'). This would lead to a len evaluation of 1 for the consumer_path_offset in setup_channel_trace_path:70. This would end up not "skipping" the "ust" and "kernel" part of the path. Solution ======== Part of the solution is to copy the domain_subdir from the original session consumer output to the snapshot output. Still, the problem was still present since that now that the domain_subdir was not "\0", the value was suffixed to the passed session_path. In the snapshot code path, "ust/" and "kernel/" were already present in the session_path passed to setup_channel_trace_path. A quick modification at the caller level in the snapshot code path fixes the issues once and for all. Tests ======= The test suit is augmented for certain key tests to validate the complete path of a trace. Path validation is based on crude bash pattern matching. Known drawbacks ========= None References ========== [1] https://github.com/lttng/lttng-tools/commit/5da88b0f58d7f838068037ea449ddfb25d3e85ad Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau This is the commit message #2: Fix: expected procname should not have -ust suffix commit ("Fix: ustcomm: application name uses the '-ust'-suffixed thread name") in LTTng-UST removes "-ust" suffix from procname, which appears in the output trace directory hierarchy. Adapt tests to not expect this quirk. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau Change-Id: Ie7cd2d5471ee3a942fa511e2f4cab09e3aa499e4 --- src/bin/lttng-sessiond/cmd.c | 10 + src/bin/lttng-sessiond/kernel.c | 2 +- src/bin/lttng-sessiond/ust-app.c | 4 +- tests/regression/kernel/test_event_basic | 3 +- tests/regression/tools/base-path/test_ust | 7 +- tests/regression/tools/live/test_lttng_kernel | 3 +- tests/regression/tools/snapshots/test_kernel | 5 +- .../tools/snapshots/test_kernel_streaming | 3 +- .../tools/snapshots/test_ust_streaming | 12 +- tests/regression/tools/snapshots/ust_test | 10 +- tests/regression/tools/streaming/test_kernel | 3 +- tests/regression/tools/streaming/test_ust | 3 +- .../tracefile-limits/test_tracefile_size | 4 +- tests/utils/utils.sh | 225 ++++++++++++++++++ 14 files changed, 276 insertions(+), 18 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 3e3169f7b..b608df1e1 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -4690,6 +4690,11 @@ enum lttng_error_code snapshot_record(struct ltt_session *session, consumer_copy_output(snapshot_output->consumer); strcpy(snapshot_kernel_consumer_output->chunk_path, snapshot_chunk_name); + + /* Copy the original domain subdir. */ + strcpy(snapshot_kernel_consumer_output->domain_subdir, + original_kernel_consumer_output->domain_subdir); + ret = consumer_copy_sockets(snapshot_kernel_consumer_output, original_kernel_consumer_output); if (ret < 0) { @@ -4712,6 +4717,11 @@ enum lttng_error_code snapshot_record(struct ltt_session *session, consumer_copy_output(snapshot_output->consumer); strcpy(snapshot_ust_consumer_output->chunk_path, snapshot_chunk_name); + + /* Copy the original domain subdir. */ + strcpy(snapshot_ust_consumer_output->domain_subdir, + original_ust_consumer_output->domain_subdir); + ret = consumer_copy_sockets(snapshot_ust_consumer_output, original_ust_consumer_output); if (ret < 0) { diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 1c584738a..00de9006b 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -1556,7 +1556,7 @@ enum lttng_error_code kernel_snapshot_record( } trace_path = setup_channel_trace_path(ksess->consumer, - DEFAULT_KERNEL_TRACE_DIR, &consumer_path_offset); + "", &consumer_path_offset); if (!trace_path) { status = LTTNG_ERR_INVALID; goto error; diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 35e4e3bce..e094ce36c 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -5889,7 +5889,7 @@ enum lttng_error_code ust_app_snapshot_record( memset(pathname, 0, sizeof(pathname)); ret = snprintf(pathname, sizeof(pathname), - DEFAULT_UST_TRACE_DIR "/" DEFAULT_UST_TRACE_UID_PATH, + DEFAULT_UST_TRACE_UID_PATH, reg->uid, reg->bits_per_long); if (ret < 0) { PERROR("snprintf snapshot path"); @@ -5953,7 +5953,7 @@ enum lttng_error_code ust_app_snapshot_record( /* Add the UST default trace dir to path. */ memset(pathname, 0, sizeof(pathname)); - ret = snprintf(pathname, sizeof(pathname), DEFAULT_UST_TRACE_DIR "/%s", + ret = snprintf(pathname, sizeof(pathname), "%s", ua_sess->path); if (ret < 0) { status = LTTNG_ERR_INVALID; diff --git a/tests/regression/kernel/test_event_basic b/tests/regression/kernel/test_event_basic index b0ed0ea90..f3a393eb8 100755 --- a/tests/regression/kernel/test_event_basic +++ b/tests/regression/kernel/test_event_basic @@ -9,7 +9,7 @@ TEST_DESC="Kernel tracer - Basic event" CURDIR=$(dirname $0)/ TESTDIR=$CURDIR/../.. -NUM_TESTS=20 +NUM_TESTS=21 TESTCMD="/bin/true" @@ -33,6 +33,7 @@ function test_event_basic() eval ${TESTCMD} stop_lttng_tracing_ok + validate_trace_path_kernel "$TRACE_PATH" "" validate_trace "sched_switch" $TRACE_PATH validate_trace "sched_process_exit" $TRACE_PATH validate_trace "sched_process_fork" $TRACE_PATH diff --git a/tests/regression/tools/base-path/test_ust b/tests/regression/tools/base-path/test_ust index 26996b4ae..51c954a88 100755 --- a/tests/regression/tools/base-path/test_ust +++ b/tests/regression/tools/base-path/test_ust @@ -15,7 +15,7 @@ EVENT_NAME="tp:tptest" TRACE_PATH=$(mktemp -d) -NUM_TESTS=37 +NUM_TESTS=42 source "$TESTDIR/utils/utils.sh" @@ -40,6 +40,7 @@ function ust_app_stream_base_path () destroy_lttng_session_ok $session_name # validate test + validate_trace_path_ust_uid_network "$TRACE_PATH" "" "$base_path" if validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$base_path"; then # only delete if successful rm -rf "$TRACE_PATH" @@ -67,6 +68,7 @@ function ust_app_snapshot_create_base_path () destroy_lttng_session_ok $session_name # validate test + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "" "snapshot-1" 0 "$base_path" if validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$base_path"; then # only delete if successful rm -rf "$TRACE_PATH" @@ -93,6 +95,7 @@ function ust_app_snapshot_base_path () destroy_lttng_session_ok $session_name # validate test + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "" "snapshot-0" 0 "$base_path" if validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$base_path"; then # only delete if successful rm -rf "$TRACE_PATH" @@ -120,6 +123,7 @@ function ust_app_snapshot_add_output_base_path () destroy_lttng_session_ok $session_name # validate test + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "" "snapshot-1" 0 "$base_path" if validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$base_path"; then # only delete if successful rm -rf "$TRACE_PATH" @@ -141,6 +145,7 @@ function ust_app_stream_base_path_via_load () destroy_lttng_session_ok $session_name # validate test + validate_trace_path_ust_uid_network "$TRACE_PATH" "" "$base_path" if validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$base_path"; then # only delete if successful rm -rf "$TRACE_PATH" diff --git a/tests/regression/tools/live/test_lttng_kernel b/tests/regression/tools/live/test_lttng_kernel index ea2a1e4e4..010ff855a 100755 --- a/tests/regression/tools/live/test_lttng_kernel +++ b/tests/regression/tools/live/test_lttng_kernel @@ -18,7 +18,7 @@ TRACE_PATH=$(mktemp -d) DIR=$(readlink -f $TESTDIR) -NUM_TESTS=10 +NUM_TESTS=11 source $TESTDIR/utils/utils.sh @@ -64,6 +64,7 @@ skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || clean_live_tracing + validate_trace_path_kernel_network "$TRACE_PATH" "$SESSION_NAME" validate_trace $EVENT_NAME $TRACE_PATH rm -rf $TRACE_PATH diff --git a/tests/regression/tools/snapshots/test_kernel b/tests/regression/tools/snapshots/test_kernel index 15b7ec176..75de4ed45 100755 --- a/tests/regression/tools/snapshots/test_kernel +++ b/tests/regression/tools/snapshots/test_kernel @@ -14,7 +14,7 @@ CHANNEL_NAME="snapchan" TRACE_PATH=$(mktemp -d) -NUM_TESTS=2060 +NUM_TESTS=2061 source $TESTDIR/utils/utils.sh @@ -31,12 +31,11 @@ function test_kernel_local_snapshot () destroy_lttng_session_ok $SESSION_NAME # Validate test + validate_trace_path_kernel_snapshot "$TRACE_PATH" "" "snapshot-1" 0 "" validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful rm -rf $TRACE_PATH - else - break fi } diff --git a/tests/regression/tools/snapshots/test_kernel_streaming b/tests/regression/tools/snapshots/test_kernel_streaming index 0a9fcd5c3..132e639ea 100755 --- a/tests/regression/tools/snapshots/test_kernel_streaming +++ b/tests/regression/tools/snapshots/test_kernel_streaming @@ -14,7 +14,7 @@ CHANNEL_NAME="chan1" TRACE_PATH=$(mktemp -d) -NUM_TESTS=61 +NUM_TESTS=66 source $TESTDIR/utils/utils.sh @@ -127,6 +127,7 @@ function test_kernel_n_snapshot() start_lttng_tracing_ok $SESSION_NAME lttng_snapshot_record $SESSION_NAME stop_lttng_tracing_ok $SESSION_NAME + validate_trace_path_kernel_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" $(( i - 1 )) "" validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* if [ $? -ne 0 ]; then return 1 diff --git a/tests/regression/tools/snapshots/test_ust_streaming b/tests/regression/tools/snapshots/test_ust_streaming index 38bbc71ff..2b20ccaf0 100755 --- a/tests/regression/tools/snapshots/test_ust_streaming +++ b/tests/regression/tools/snapshots/test_ust_streaming @@ -21,7 +21,7 @@ APPS_PID= TRACE_PATH=$(mktemp -d) -NUM_TESTS=75 +NUM_TESTS=85 source $TESTDIR/utils/utils.sh @@ -89,6 +89,7 @@ function test_ust_default_name_with_del() lttng_snapshot_record $SESSION_NAME # Validate test + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* if [ $? -ne 0 ]; then stop_test_apps @@ -100,6 +101,7 @@ function test_ust_default_name_with_del() lttng_snapshot_record $SESSION_NAME # Validate test with the next ID since a del output was done prior. + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-2" 1 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2* if [ $? -ne 0 ]; then stop_test_apps @@ -130,6 +132,7 @@ function test_ust_default_name() stop_lttng_tracing_ok $SESSION_NAME destroy_lttng_session_ok $SESSION_NAME # Validate test + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* out=$? @@ -153,6 +156,7 @@ function test_ust_default_name_custom_uri() stop_lttng_tracing_ok $SESSION_NAME destroy_lttng_session_ok $SESSION_NAME # Validate test + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* out=$? @@ -183,6 +187,7 @@ function test_ust_custom_name() if ls $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name* &> /dev/null; then ok 0 "Custom name snapshot exists" # Validate test + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "$name" 0 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-* out=$? else @@ -201,13 +206,14 @@ function test_ust_n_snapshot() create_lttng_session_no_output $SESSION_NAME enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - snapshot_add_output $SESSION_NAME "net://localhost" $name + snapshot_add_output $SESSION_NAME "net://localhost" start_test_app - for i in {1..5}; + for i in {0..4}; do start_lttng_tracing_ok $SESSION_NAME lttng_snapshot_record $SESSION_NAME stop_lttng_tracing_ok $SESSION_NAME + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" $i validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* if [ $? -ne 0 ]; then return 1 diff --git a/tests/regression/tools/snapshots/ust_test b/tests/regression/tools/snapshots/ust_test index c2563afd8..7eff6df5e 100755 --- a/tests/regression/tools/snapshots/ust_test +++ b/tests/regression/tools/snapshots/ust_test @@ -16,7 +16,7 @@ TESTAPP_NAME="gen-ust-events" TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" APPS_PID= -NUM_TESTS=100 +NUM_TESTS=105 TRACE_PATH=$(mktemp -d) @@ -32,7 +32,7 @@ if [ -z $1 ]; then fi NR_SNAPSHOT=$1 -NUM_TESTS=$(($NUM_TESTS + ($NR_SNAPSHOT * 2))) +NUM_TESTS=$(($NUM_TESTS + ($NR_SNAPSHOT * 3))) function start_test_app() { @@ -193,6 +193,7 @@ function test_ust_local_snapshot () destroy_lttng_session_ok $SESSION_NAME # Validate test + validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0 validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful @@ -335,6 +336,7 @@ function test_ust_local_snapshot_max_size () destroy_lttng_session_ok $SESSION_NAME # Validate test + validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0 validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then @@ -365,6 +367,7 @@ function test_ust_local_snapshot_large_metadata () destroy_lttng_session_ok $SESSION_NAME # Validate test + validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0 validate_trace $LM_EVENT $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful @@ -400,6 +403,7 @@ function test_ust_per_uid_local_snapshot () destroy_lttng_session_ok $SESSION_NAME # Validate test + validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0 validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful @@ -430,6 +434,7 @@ function test_ust_per_uid_local_snapshot_post_mortem () destroy_lttng_session_ok $SESSION_NAME # Validate test + validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0 validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful @@ -457,6 +462,7 @@ function test_ust_local_snapshots () rm -rf $TRACE_PATH/snapshot/* 2>/dev/null lttng_snapshot_record $SESSION_NAME # Validate test + validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" $((i - 1)) validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful diff --git a/tests/regression/tools/streaming/test_kernel b/tests/regression/tools/streaming/test_kernel index 9ab43882c..a7069ccb8 100755 --- a/tests/regression/tools/streaming/test_kernel +++ b/tests/regression/tools/streaming/test_kernel @@ -13,7 +13,7 @@ SESSION_NAME="" TRACE_PATH=$(mktemp -d) -NUM_TESTS=10 +NUM_TESTS=11 source $TESTDIR/utils/utils.sh @@ -68,6 +68,7 @@ skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_ ${fct_test} # Validate test + validate_trace_path_kernel_network "$TRACE_PATH" "$SESSION_NAME" validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME* if [ $? -eq 0 ]; then # Only delete if successful diff --git a/tests/regression/tools/streaming/test_ust b/tests/regression/tools/streaming/test_ust index e3fd9af42..d030f1658 100755 --- a/tests/regression/tools/streaming/test_ust +++ b/tests/regression/tools/streaming/test_ust @@ -18,7 +18,7 @@ EVENT_NAME="tp:tptest" TRACE_PATH=$(mktemp -d) -NUM_TESTS=16 +NUM_TESTS=18 source $TESTDIR/utils/utils.sh @@ -91,6 +91,7 @@ do ${fct_test} # Validate test + validate_trace_path_ust_uid_network "$TRACE_PATH" "$SESSION_NAME" validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME* if [ $? -eq 0 ]; then # Only delete if successful diff --git a/tests/regression/tools/tracefile-limits/test_tracefile_size b/tests/regression/tools/tracefile-limits/test_tracefile_size index 5d4b03550..481abc92b 100755 --- a/tests/regression/tools/tracefile-limits/test_tracefile_size +++ b/tests/regression/tools/tracefile-limits/test_tracefile_size @@ -17,7 +17,7 @@ TESTAPP_PATH="$TESTDIR/utils/testapp" TESTAPP_NAME="gen-ust-events" TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" -NUM_TESTS=66 +NUM_TESTS=74 source $TESTDIR/utils/utils.sh @@ -115,6 +115,7 @@ function test_tracefile_size_limit () # Validate tracing data, we should at least have some events + validate_trace_path_ust_pid "$trace_path" "" "gen-ust-events" validate_trace $event_name $trace_path rm -rf $trace_path @@ -153,6 +154,7 @@ function test_tracefile_size_limit_pagesize () # Validate tracing data, we should at least have some events + validate_trace_path_ust_pid "$trace_path" "" "gen-ust-events" validate_trace $event_name $trace_path rm -rf $trace_path diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 3ad9abe33..10d914f36 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -16,6 +16,11 @@ BABELTRACE_BIN="babeltrace" OUTPUT_DEST=/dev/null ERROR_OUTPUT_DEST=/dev/null +# To match 20201127-175802 +date_time_pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]" +# The size of a long on this system +system_long_bit_size=$(getconf LONG_BIT) + # Minimal kernel version supported for session daemon tests KERNEL_MAJOR_VERSION=2 KERNEL_MINOR_VERSION=6 @@ -2067,3 +2072,223 @@ function lttng_clear_all () $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST ok $? "Clear all lttng sessions" } + +function validate_path_pattern () +{ + local message=$1 + local pattern=$2 + # Base path is only used in error case and is used to list the content + # of the base path. + local base_path=$3 + + + [ -f $pattern ] + ret=$? + ok $ret "$message" + + if [ "$ret" -ne "0" ]; then + diag "Path pattern expected: $pattern" + # List the tracepath for more info. We use find as a recursive + # directory lister. + diag "The base path content:" + find "$base_path" -print + fi +} + +function validate_trace_path_ust_uid () +{ + local trace_path=$1 + local session_name=$2 + local uid=$UID + local pattern="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata" + + validate_path_pattern "UST per-uid trace path is valid" "$pattern" "$trace_path" +} + +function validate_trace_path_ust_uid_network () +{ + local trace_path=$1 + local session_name=$2 + local base_path=$3 + local uid=$UID + local hostname=$HOSTNAME + local pattern + local ret + + # If the session was given a network base path (e.g + # 127.0.0.1/my/custom/path on creation, there is no session name + # component to the path on the relayd side. Caller can simply not pass a + # session name for this scenario. + if [ -n "$session_name" ]; then + session_name="$session_name-$date_time_pattern" + if [ -n "$base_path" ]; then + fail "Session name and base path are mutually exclusive" + return + fi + fi + + pattern="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata" + + validate_path_pattern "UST per-uid network trace path is valid" "$pattern" "$trace_path" +} + +function validate_trace_path_ust_uid_snapshot_network () +{ + local trace_path=$1 + local session_name=$2 + local snapshot_name=$3 + local snapshot_number=$4 + local base_path=$5 + local hostname=$HOSTNAME + local uid=$UID + local pattern + local ret + + # If the session/output was given a network base path (e.g + # 127.0.0.1/my/custom/path on creation, there is no session name + # component to the path on the relayd side. Caller can simply not pass a + # session name for this scenario. + if [ -n "$session_name" ]; then + session_name="$session_name-$date_time_pattern" + if [ -n "$base_path" ]; then + fail "Session name and base path are mutually exclusive" + return + fi + fi + + pattern="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata" + + validate_path_pattern "UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path" +} + +function validate_trace_path_ust_uid_snapshot () +{ + local trace_path=$1 + local session_name=$2 + local snapshot_name=$3 + local snapshot_number=$4 + local base_path=$5 + local uid=$UID + local pattern + local ret + + # If the session/output was given a network base path (e.g + # 127.0.0.1/my/custom/path) on creation, there is no session name + # component to the path on the relayd side. Caller can simply not pass a + # session name for this scenario. + if [ -n "$session_name" ]; then + session_name="$session_name-$date_time_pattern" + if [ -n "$base_path" ]; then + fail "Session name and base path are mutually exclusive" + return + fi + fi + + pattern="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata" + + validate_path_pattern "UST per-uid snapshot trace path is valid" "$pattern" "$trace_path" +} + +function validate_trace_path_ust_pid () +{ + local trace_path=$1 + local session_name=$2 + local app_string=$3 + local pid=$4 + local pattern + local ret + + # If the session was given a trace path on creation, there is no session + # name component to the path. Caller can simply not pass a session name + # for this scenario. + if [ -n "$session_name" ]; then + session_name="$session_name-$date_time_pattern" + fi + + pattern="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata" + + validate_path_pattern "UST per-pid trace path is valid" "$pattern" "$trace_path" +} + +function validate_trace_path_kernel () +{ + local trace_path=$1 + local session_name=$2 + local pattern + + # If the session was given a trace path on creation, there is no session + # name component to the path. Caller can simply not pass a session name + # for this scenario. + if [ -n "$session_name" ]; then + session_name="$session_name-$date_time_pattern" + fi + + pattern="$trace_path/$session_name/kernel/metadata" + + validate_path_pattern "Kernel trace path is valid" "$pattern" "$trace_path" +} + +function validate_trace_path_kernel_network () +{ + local trace_path=$1 + local session_name=$2 + local hostname=$HOSTNAME + local pattern="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata" + + validate_path_pattern "Kernel network trace path is valid" "$pattern" "$trace_path" +} + +function validate_trace_path_kernel_snapshot () +{ + local trace_path=$1 + local session_name=$2 + local snapshot_name=$3 + local snapshot_number=$4 + local base_path=$5 + local pattern + local ret + + # If the session/output was given a network base path (e.g + # 127.0.0.1/my/custom/path on creation, there is no session name + # component to the path on the relayd side. Caller can simply not pass a + # session name for this scenario. + if [ -n "$session_name" ]; then + session_name="$session_name-$date_time_pattern" + if [ -n "$base_path" ]; then + fail "Session name and base path are mutually exclusive" + return + fi + fi + + pattern="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata" + + validate_path_pattern "Kernel snapshot trace path is valid" "$pattern" "$trace_path" +} + +function validate_trace_path_kernel_snapshot_network () +{ + local trace_path=$1 + local session_name=$2 + local snapshot_name=$3 + local snapshot_number=$4 + local base_path=$5 + local hostname=$HOSTNAME + local pattern + local ret + + # If the session/output was given a network base path (e.g + # 127.0.0.1/my/custom/path on creation, there is no session name + # component to the path on the relayd side. Caller can simply not pass a + # session name for this scenario. + if [ -n "$session_name" ]; then + session_name="$session_name-$date_time_pattern" + if [ -n "$base_path" ]; then + fail "Session name and base path are mutually exclusive" + return + fi + fi + + pattern="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata" + + validate_path_pattern "Kernel network snapshot trace path is valid" "$pattern" "$trace_path" +} -- 2.34.1