Cleanup: Move patches.i to include/generated/
[lttng-modules.git] / lttng-context-hostname.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
975da2c0
JD
3 * lttng-context-hostname.c
4 *
5 * LTTng hostname context.
6 *
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
975da2c0
JD
8 */
9
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/sched.h>
13#include <linux/utsname.h>
2df37e95 14#include <lttng/events.h>
24591303 15#include <ringbuffer/frontend_types.h>
241ae9a8 16#include <wrapper/vmalloc.h>
2df37e95 17#include <lttng/tracer.h>
975da2c0
JD
18
19#define LTTNG_HOSTNAME_CTX_LEN (__NEW_UTS_LEN + 1)
20
21static
22size_t hostname_get_size(size_t offset)
23{
24 size_t size = 0;
25
26 size += LTTNG_HOSTNAME_CTX_LEN;
27 return size;
28}
29
30static
31void hostname_record(struct lttng_ctx_field *field,
32 struct lib_ring_buffer_ctx *ctx,
33 struct lttng_channel *chan)
34{
35 struct nsproxy *nsproxy;
36 struct uts_namespace *ns;
37 char *hostname;
38
3d0d43db
MD
39 /*
40 * No need to take the RCU read-side lock to read current
41 * nsproxy. (documented in nsproxy.h)
42 */
43 nsproxy = current->nsproxy;
975da2c0
JD
44 if (nsproxy) {
45 ns = nsproxy->uts_ns;
46 hostname = ns->name.nodename;
47 chan->ops->event_write(ctx, hostname,
48 LTTNG_HOSTNAME_CTX_LEN);
49 } else {
50 chan->ops->event_memset(ctx, 0,
51 LTTNG_HOSTNAME_CTX_LEN);
52 }
975da2c0
JD
53}
54
f127e61e
MD
55static
56void hostname_get_value(struct lttng_ctx_field *field,
79150a49 57 struct lttng_probe_ctx *lttng_probe_ctx,
f127e61e
MD
58 union lttng_ctx_value *value)
59{
60 struct nsproxy *nsproxy;
61 struct uts_namespace *ns;
62 char *hostname;
63
64 /*
65 * No need to take the RCU read-side lock to read current
66 * nsproxy. (documented in nsproxy.h)
67 */
68 nsproxy = current->nsproxy;
69 if (nsproxy) {
70 ns = nsproxy->uts_ns;
71 hostname = ns->name.nodename;
72 } else {
73 hostname = "";
74 }
75 value->str = hostname;
76}
77
ceabb767
MD
78static const struct lttng_type hostname_array_elem_type =
79 __type_integer(char, 0, 0, -1, __BYTE_ORDER, 10, UTF8);
80
975da2c0
JD
81int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx)
82{
83 struct lttng_ctx_field *field;
84
85 field = lttng_append_context(ctx);
86 if (!field)
87 return -ENOMEM;
88 if (lttng_find_context(*ctx, "hostname")) {
89 lttng_remove_context_field(ctx, field);
90 return -EEXIST;
91 }
92 field->event_field.name = "hostname";
ceabb767
MD
93 field->event_field.type.atype = atype_array_nestable;
94 field->event_field.type.u.array_nestable.elem_type =
95 &hostname_array_elem_type;
96 field->event_field.type.u.array_nestable.length = LTTNG_HOSTNAME_CTX_LEN;
97 field->event_field.type.u.array_nestable.alignment = 0;
975da2c0
JD
98
99 field->get_size = hostname_get_size;
100 field->record = hostname_record;
f127e61e 101 field->get_value = hostname_get_value;
a9dd15da 102 lttng_context_update(*ctx);
263b6c88 103 wrapper_vmalloc_sync_mappings();
975da2c0
JD
104 return 0;
105}
106EXPORT_SYMBOL_GPL(lttng_add_hostname_to_ctx);
This page took 0.036384 seconds and 4 git commands to generate.