Add kernel and UST time namespace context
authorMichael Jeanson <mjeanson@efficios.com>
Mon, 6 Jul 2020 16:18:01 +0000 (12:18 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 21 Jul 2020 18:55:06 +0000 (14:55 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I37a67cd61d55e1b94a9f54712143daeabfb47e84

17 files changed:
include/lttng/event.h
src/bin/lttng-sessiond/context.c
src/bin/lttng-sessiond/save.c
src/bin/lttng-sessiond/trace-ust.c
src/bin/lttng-sessiond/ust-abi-internal.h
src/bin/lttng/commands/add_context.c
src/common/config/config-session-abi.h
src/common/config/session-config.c
src/common/lttng-kernel.h
src/common/mi-lttng-4.0.xsd
src/common/mi-lttng.c
tests/regression/kernel/test_ns_contexts
tests/regression/kernel/test_ns_contexts_change
tests/regression/ust/namespaces/test_ns_contexts
tests/regression/ust/namespaces/test_ns_contexts_change
tests/utils/testapp/gen-ns-events/gen-ns-events.c
tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c

index 2bd44d686e9334ca55f820182522eea669b90914..bcde9a49e8d0e61a5478610caca1e5d663aeea1c 100644 (file)
@@ -155,6 +155,7 @@ enum lttng_event_context_type {
        LTTNG_EVENT_CONTEXT_VGID                = 38,
        LTTNG_EVENT_CONTEXT_VEGID               = 39,
        LTTNG_EVENT_CONTEXT_VSGID               = 40,
+       LTTNG_EVENT_CONTEXT_TIME_NS             = 41,
 };
 
 enum lttng_event_field_type {
index 0575ab91d5e12c50ed154d5cd74a2e314a66a39e..621c0b9fb53cfa88a56abc5b6737b52aee8eaa56 100644 (file)
@@ -272,6 +272,9 @@ int context_kernel_add(struct ltt_kernel_session *ksession,
        case LTTNG_EVENT_CONTEXT_PID_NS:
                kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_PID_NS;
                break;
+       case LTTNG_EVENT_CONTEXT_TIME_NS:
+               kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_TIME_NS;
+               break;
        case LTTNG_EVENT_CONTEXT_USER_NS:
                kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_USER_NS;
                break;
index c5ea4c873d9df4981e8765068cf0e699173556a1..09194008a834ae2fc0111bee26bf7b89cf3b54ee 100644 (file)
@@ -322,6 +322,9 @@ const char *get_kernel_context_type_string(
        case LTTNG_KERNEL_CONTEXT_PID_NS:
                context_type_string = config_event_context_pid_ns;
                break;
+       case LTTNG_KERNEL_CONTEXT_TIME_NS:
+               context_type_string = config_event_context_time_ns;
+               break;
        case LTTNG_KERNEL_CONTEXT_USER_NS:
                context_type_string = config_event_context_user_ns;
                break;
@@ -408,6 +411,9 @@ const char *get_ust_context_type_string(
        case LTTNG_UST_CONTEXT_NET_NS:
                context_type_string = config_event_context_net_ns;
                break;
+       case LTTNG_UST_CONTEXT_TIME_NS:
+               context_type_string = config_event_context_time_ns;
+               break;
        case LTTNG_UST_CONTEXT_PID_NS:
                context_type_string = config_event_context_pid_ns;
                break;
index 80dd8dc54839bd51a5e643cf1a9f828a4a08c546..7ee379ef898a0890becd9b90e413d10687719a0f 100644 (file)
@@ -585,6 +585,9 @@ int trace_ust_context_type_event_to_ust(
        case LTTNG_EVENT_CONTEXT_PID_NS:
                utype = LTTNG_UST_CONTEXT_PID_NS;
                break;
+       case LTTNG_EVENT_CONTEXT_TIME_NS:
+               utype = LTTNG_UST_CONTEXT_TIME_NS;
+               break;
        case LTTNG_EVENT_CONTEXT_USER_NS:
                utype = LTTNG_UST_CONTEXT_USER_NS;
                break;
index 99da583d59d7398c2e3b31cbcde0795d8b84cbc9..14f214f67b3a9476beecd8e0f600f6250e120d94 100644 (file)
@@ -143,6 +143,7 @@ enum lttng_ust_context_type {
        LTTNG_UST_CONTEXT_VGID                  = 18,
        LTTNG_UST_CONTEXT_VEGID                 = 19,
        LTTNG_UST_CONTEXT_VSGID                 = 20,
+       LTTNG_UST_CONTEXT_TIME_NS               = 21,
 };
 
 struct lttng_ust_perf_counter_ctx {
index de54721cb5a2c3571a02cf93163d6c99b8e83490..b33eb1d14ef22545b73baeceed6d6a19424b9e8c 100644 (file)
@@ -95,6 +95,7 @@ enum context_type {
        CONTEXT_VGID         = 38,
        CONTEXT_VEGID        = 39,
        CONTEXT_VSGID        = 40,
+       CONTEXT_TIME_NS      = 41,
 };
 
 /*
@@ -264,6 +265,7 @@ const struct ctx_opts {
        { (char *) "mnt_ns", CONTEXT_MNT_NS },
        { (char *) "net_ns", CONTEXT_NET_NS },
        { (char *) "pid_ns", CONTEXT_PID_NS },
+       { (char *) "time_ns", CONTEXT_TIME_NS },
        { (char *) "user_ns", CONTEXT_USER_NS },
        { (char *) "uts_ns", CONTEXT_UTS_NS },
        { (char *) "uid", CONTEXT_UID },
index 41f675041536aba6216412ac929c4253a9266d38..75ff303d49a818dbf34f0b489bee520d97cb3255 100644 (file)
@@ -161,6 +161,7 @@ extern const char * const config_event_context_ipc_ns;
 extern const char * const config_event_context_mnt_ns;
 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_time_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;
index e893c129863fe5a2d593226f85922f349c2f985c..37c5ce383962e1b278e150a9dfac0a063998fd4e 100644 (file)
@@ -223,6 +223,7 @@ LTTNG_HIDDEN const char * const config_event_context_ipc_ns = "IPC_NS";
 LTTNG_HIDDEN const char * const config_event_context_mnt_ns = "MNT_NS";
 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_time_ns = "TIME_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";
@@ -1094,6 +1095,9 @@ int get_context_type(xmlChar *context_type)
        } else if (!strcmp((char *) context_type,
                config_event_context_pid_ns)) {
                ret = LTTNG_EVENT_CONTEXT_PID_NS;
+       } else if (!strcmp((char *) context_type,
+               config_event_context_time_ns)) {
+               ret = LTTNG_EVENT_CONTEXT_TIME_NS;
        } else if (!strcmp((char *) context_type,
                config_event_context_user_ns)) {
                ret = LTTNG_EVENT_CONTEXT_USER_NS;
index d5904e79f5f5c3b8582496c2297ce5bc4b49f900..fc2a1e25944f26cd8273353d5dd6ce49dce92e9e 100644 (file)
@@ -75,6 +75,7 @@ enum lttng_kernel_context_type {
        LTTNG_KERNEL_CONTEXT_VGID           = 34,
        LTTNG_KERNEL_CONTEXT_VEGID          = 35,
        LTTNG_KERNEL_CONTEXT_VSGID          = 36,
+       LTTNG_KERNEL_CONTEXT_TIME_NS        = 37,
 };
 
 /* Perf counter attributes */
index fef65509677c5ce17cfd685ab7e8235ff3ae4188..9b656ece4d60bf43be0fc1581ea4f6a37912d3f1 100644 (file)
@@ -109,6 +109,7 @@ SPDX-License-Identifier: MIT
                        <xs:enumeration value="MNT_NS" />
                        <xs:enumeration value="NET_NS" />
                        <xs:enumeration value="PID_NS" />
+                       <xs:enumeration value="TIME_NS" />
                        <xs:enumeration value="USER_NS" />
                        <xs:enumeration value="UTS_NS" />
                        <xs:enumeration value="UID" />
index 71253fcd270f4669be031af6457f95315bff7a47..1088ba29c357cda558078d0bc0ffd7fb7ae19c7c 100644 (file)
@@ -431,6 +431,8 @@ const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val)
                return config_event_context_net_ns;
        case LTTNG_EVENT_CONTEXT_PID_NS:
                return config_event_context_pid_ns;
+       case LTTNG_EVENT_CONTEXT_TIME_NS:
+               return config_event_context_time_ns;
        case LTTNG_EVENT_CONTEXT_USER_NS:
                return config_event_context_user_ns;
        case LTTNG_EVENT_CONTEXT_UTS_NS:
index 0ab31c3a31dd651318dbeebf903fa7f84967c80b..1a25d8666801d7d7d3fc250e738758da502e2fd5 100755 (executable)
@@ -11,7 +11,7 @@ TESTDIR=$CURDIR/../..
 
 TESTS_PER_NS=11
 
-NUM_TESTS=$((TESTS_PER_NS * 7))
+NUM_TESTS=$((TESTS_PER_NS * 8))
 
 source "$TESTDIR/utils/utils.sh"
 
@@ -131,5 +131,6 @@ test_ns ipc
 test_ns mnt
 test_ns net
 test_ns pid
+test_ns time
 test_ns user
 test_ns uts
index 1c5d15f02e113c8283393bcf62bdf8e7a7873d58..118d120a61942e479b80d513cb4d925201ecaca6 100755 (executable)
@@ -172,5 +172,6 @@ test_ns ipc
 test_ns mnt
 test_ns net
 #test_ns pid # pid_ns is special, can't be changed that way
+#test_ns time # time_ns is special, can't be changed that way
 test_ns user
 test_ns uts
index 6f0e504722eed673b490150fcf1234d923693c85..c1c6a2ae6c0ef1b575431b43fba406d783e07acb 100755 (executable)
@@ -17,7 +17,7 @@ EVENT_NAME="tp:tptest"
 
 TESTS_PER_NS=13
 
-NUM_TESTS=$((TESTS_PER_NS * 7))
+NUM_TESTS=$((TESTS_PER_NS * 8))
 
 source "$TESTDIR/utils/utils.sh"
 
@@ -89,5 +89,6 @@ test_ns ipc
 test_ns mnt
 test_ns net
 test_ns pid
+test_ns time
 test_ns user
 test_ns uts
index fb1e936cd3e785d905f16b84863bb0b9dd54e2b0..6ce614aba905468e8443407c57d251688092f888 100755 (executable)
@@ -118,5 +118,6 @@ test_ns ipc
 test_ns mnt
 test_ns net
 #test_ns pid # pid_ns is special, can't be changed that way
+#test_ns time # time_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
index 22398c314ea07c8ef568fb48528b34fb2ad05e5a..7c2b6478c4520f526a9dbca17c7d4d12d1bb650f 100644 (file)
@@ -53,6 +53,9 @@
 #ifndef CLONE_NEWNET
 #define CLONE_NEWNET    0x40000000
 #endif
+#ifndef CLONE_NEWTIME
+#define CLONE_NEWTIME   0x00000080
+#endif
 
 static int debug = 0;
 static char *ns_opt = NULL;
@@ -217,7 +220,7 @@ int main(int argc, const char **argv)
                goto end;
        }
 
-       if (strncmp(ns_opt, "cgroup", 3) == 0) {
+       if (strncmp(ns_opt, "cgroup", 6) == 0) {
                ret = do_the_needful(CLONE_NEWCGROUP, "cgroup");
        } else if (strncmp(ns_opt, "ipc", 3) == 0) {
                ret = do_the_needful(CLONE_NEWIPC, "ipc");
@@ -227,7 +230,9 @@ int main(int argc, const char **argv)
                ret = do_the_needful(CLONE_NEWNET, "net");
        } else if (strncmp(ns_opt, "pid", 3) == 0) {
                ret = do_the_needful(CLONE_NEWPID, "pid");
-       } else if (strncmp(ns_opt, "user", 3) == 0) {
+       } else if (strncmp(ns_opt, "time", 4) == 0) {
+               ret = do_the_needful(CLONE_NEWTIME, "time");
+       } else if (strncmp(ns_opt, "user", 4) == 0) {
                /*
                 * Will always fail, requires a single threaded application,
                 * which can't happen with UST.
index c5f25dd7bb1308cc17f34492052e0d2ed339a7dd..907651d7c4b5d8b49d2a312d8a9f7fe16147047d 100644 (file)
@@ -55,6 +55,9 @@
 #ifndef CLONE_NEWNET
 #define CLONE_NEWNET    0x40000000
 #endif
+#ifndef CLONE_NEWTIME
+#define CLONE_NEWTIME   0x00000080
+#endif
 
 static int nr_iter = 100;
 static int debug = 0;
@@ -233,7 +236,7 @@ int main(int argc, const char **argv)
                goto end;
        }
 
-       if (strncmp(ns_opt, "cgroup", 3) == 0) {
+       if (strncmp(ns_opt, "cgroup", 6) == 0) {
                ret = do_the_needful(CLONE_NEWCGROUP, "cgroup");
        } else if (strncmp(ns_opt, "ipc", 3) == 0) {
                ret = do_the_needful(CLONE_NEWIPC, "ipc");
@@ -243,7 +246,9 @@ int main(int argc, const char **argv)
                ret = do_the_needful(CLONE_NEWNET, "net");
        } else if (strncmp(ns_opt, "pid", 3) == 0) {
                ret = do_the_needful(CLONE_NEWPID, "pid");
-       } else if (strncmp(ns_opt, "user", 3) == 0) {
+       } else if (strncmp(ns_opt, "time", 4) == 0) {
+               ret = do_the_needful(CLONE_NEWTIME, "time");
+       } else if (strncmp(ns_opt, "user", 4) == 0) {
                /*
                 * Will always fail, requires a single threaded application,
                 * which can't happen with UST.
This page took 0.047468 seconds and 4 git commands to generate.