Move headers under include/
[lttng-modules.git] / lttng-context-cgroup-ns.c
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng-context-cgroup-ns.c
4 *
5 * LTTng cgroup namespace context.
6 *
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * 2019 Michael Jeanson <mjeanson@efficios.com>
9 *
10 */
11
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/sched.h>
15 #include <linux/cgroup.h>
16 #include <lttng/lttng-events.h>
17 #include <ringbuffer/frontend_types.h>
18 #include <lttng/lttng-tracer.h>
19
20 #if defined(CONFIG_CGROUPS)
21
22 static
23 size_t cgroup_ns_get_size(size_t offset)
24 {
25 size_t size = 0;
26
27 size += lib_ring_buffer_align(offset, lttng_alignof(unsigned int));
28 size += sizeof(unsigned int);
29 return size;
30 }
31
32 static
33 void cgroup_ns_record(struct lttng_ctx_field *field,
34 struct lib_ring_buffer_ctx *ctx,
35 struct lttng_channel *chan)
36 {
37 unsigned int cgroup_ns_inum = 0;
38
39 /*
40 * nsproxy can be NULL when scheduled out of exit.
41 *
42 * As documented in 'linux/nsproxy.h' namespaces access rules, no
43 * precautions should be taken when accessing the current task's
44 * namespaces, just dereference the pointers.
45 */
46 if (current->nsproxy)
47 cgroup_ns_inum = current->nsproxy->cgroup_ns->ns.inum;
48
49 lib_ring_buffer_align_ctx(ctx, lttng_alignof(cgroup_ns_inum));
50 chan->ops->event_write(ctx, &cgroup_ns_inum, sizeof(cgroup_ns_inum));
51 }
52
53 static
54 void cgroup_ns_get_value(struct lttng_ctx_field *field,
55 struct lttng_probe_ctx *lttng_probe_ctx,
56 union lttng_ctx_value *value)
57 {
58 unsigned int cgroup_ns_inum = 0;
59
60 /*
61 * nsproxy can be NULL when scheduled out of exit.
62 *
63 * As documented in 'linux/nsproxy.h' namespaces access rules, no
64 * precautions should be taken when accessing the current task's
65 * namespaces, just dereference the pointers.
66 */
67 if (current->nsproxy)
68 cgroup_ns_inum = current->nsproxy->cgroup_ns->ns.inum;
69
70 value->s64 = cgroup_ns_inum;
71 }
72
73 int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx)
74 {
75 struct lttng_ctx_field *field;
76
77 field = lttng_append_context(ctx);
78 if (!field)
79 return -ENOMEM;
80 if (lttng_find_context(*ctx, "cgroup_ns")) {
81 lttng_remove_context_field(ctx, field);
82 return -EEXIST;
83 }
84 field->event_field.name = "cgroup_ns";
85 field->event_field.type.atype = atype_integer;
86 field->event_field.type.u.integer.size = sizeof(unsigned int) * CHAR_BIT;
87 field->event_field.type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT;
88 field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned int);
89 field->event_field.type.u.integer.reverse_byte_order = 0;
90 field->event_field.type.u.integer.base = 10;
91 field->event_field.type.u.integer.encoding = lttng_encode_none;
92 field->get_size = cgroup_ns_get_size;
93 field->record = cgroup_ns_record;
94 field->get_value = cgroup_ns_get_value;
95 lttng_context_update(*ctx);
96 return 0;
97 }
98 EXPORT_SYMBOL_GPL(lttng_add_cgroup_ns_to_ctx);
99
100 #endif
This page took 0.030652 seconds and 4 git commands to generate.