Move headers under include/
[lttng-modules.git] / lttng-context-ipc-ns.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
a6cf40a4
MJ
2 *
3 * lttng-context-ipc-ns.c
4 *
5 * LTTng ipc 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/ipc_namespace.h>
b5304713
MD
16#include <lttng/lttng-events.h>
17#include <ringbuffer/frontend_types.h>
18#include <lttng/lttng-tracer.h>
a6cf40a4 19
9f920259 20#if defined(CONFIG_IPC_NS)
a6cf40a4
MJ
21
22static
23size_t ipc_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
32static
33void ipc_ns_record(struct lttng_ctx_field *field,
34 struct lib_ring_buffer_ctx *ctx,
35 struct lttng_channel *chan)
36{
37 unsigned int ipc_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)
6388029c 47 ipc_ns_inum = current->nsproxy->ipc_ns->ns.inum;
a6cf40a4
MJ
48
49 lib_ring_buffer_align_ctx(ctx, lttng_alignof(ipc_ns_inum));
50 chan->ops->event_write(ctx, &ipc_ns_inum, sizeof(ipc_ns_inum));
51}
52
53static
54void ipc_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 ipc_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)
6388029c 68 ipc_ns_inum = current->nsproxy->ipc_ns->ns.inum;
a6cf40a4
MJ
69
70 value->s64 = ipc_ns_inum;
71}
72
73int lttng_add_ipc_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, "ipc_ns")) {
81 lttng_remove_context_field(ctx, field);
82 return -EEXIST;
83 }
84 field->event_field.name = "ipc_ns";
85 field->event_field.type.atype = atype_integer;
ceabb767
MD
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;
a6cf40a4
MJ
92 field->get_size = ipc_ns_get_size;
93 field->record = ipc_ns_record;
94 field->get_value = ipc_ns_get_value;
95 lttng_context_update(*ctx);
a6cf40a4
MJ
96 return 0;
97}
98EXPORT_SYMBOL_GPL(lttng_add_ipc_ns_to_ctx);
99
100#endif
This page took 0.027062 seconds and 4 git commands to generate.