1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
3 * lttng-context-hostname.c
5 * LTTng hostname context.
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <linux/sched.h>
13 #include <linux/utsname.h>
14 #include <lttng/events.h>
15 #include <lttng/events-internal.h>
16 #include <ringbuffer/frontend_types.h>
17 #include <wrapper/vmalloc.h>
18 #include <lttng/tracer.h>
20 #define LTTNG_HOSTNAME_CTX_LEN (__NEW_UTS_LEN + 1)
23 size_t hostname_get_size(void *priv
, struct lttng_kernel_probe_ctx
*probe_ctx
, size_t offset
)
27 size
+= LTTNG_HOSTNAME_CTX_LEN
;
32 void hostname_record(void *priv
, struct lttng_kernel_probe_ctx
*probe_ctx
,
33 struct lttng_kernel_ring_buffer_ctx
*ctx
,
34 struct lttng_kernel_channel_buffer
*chan
)
36 struct nsproxy
*nsproxy
;
37 struct uts_namespace
*ns
;
41 * No need to take the RCU read-side lock to read current
42 * nsproxy. (documented in nsproxy.h)
44 nsproxy
= current
->nsproxy
;
47 hostname
= ns
->name
.nodename
;
48 chan
->ops
->event_write(ctx
, hostname
,
49 LTTNG_HOSTNAME_CTX_LEN
, 1);
51 chan
->ops
->event_memset(ctx
, 0,
52 LTTNG_HOSTNAME_CTX_LEN
);
57 void hostname_get_value(void *priv
,
58 struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
59 struct lttng_ctx_value
*value
)
61 struct nsproxy
*nsproxy
;
62 struct uts_namespace
*ns
;
66 * No need to take the RCU read-side lock to read current
67 * nsproxy. (documented in nsproxy.h)
69 nsproxy
= current
->nsproxy
;
72 hostname
= ns
->name
.nodename
;
76 value
->u
.str
= hostname
;
79 static const struct lttng_kernel_ctx_field
*ctx_field
= lttng_kernel_static_ctx_field(
80 lttng_kernel_static_event_field("hostname",
81 lttng_kernel_static_type_array_text(LTTNG_HOSTNAME_CTX_LEN
),
88 int lttng_add_hostname_to_ctx(struct lttng_kernel_ctx
**ctx
)
92 if (lttng_kernel_find_context(*ctx
, ctx_field
->event_field
->name
))
94 ret
= lttng_kernel_context_append(ctx
, ctx_field
);
95 wrapper_vmalloc_sync_mappings();
98 EXPORT_SYMBOL_GPL(lttng_add_hostname_to_ctx
);