1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
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 <wrapper/ringbuffer/frontend_types.h>
16 #include <wrapper/vmalloc.h>
17 #include <lttng-tracer.h>
19 #define LTTNG_HOSTNAME_CTX_LEN (__NEW_UTS_LEN + 1)
22 size_t hostname_get_size(size_t offset
)
26 size
+= LTTNG_HOSTNAME_CTX_LEN
;
31 void hostname_record(struct lttng_ctx_field
*field
,
32 struct lib_ring_buffer_ctx
*ctx
,
33 struct lttng_channel
*chan
)
35 struct nsproxy
*nsproxy
;
36 struct uts_namespace
*ns
;
40 * No need to take the RCU read-side lock to read current
41 * nsproxy. (documented in nsproxy.h)
43 nsproxy
= current
->nsproxy
;
46 hostname
= ns
->name
.nodename
;
47 chan
->ops
->event_write(ctx
, hostname
,
48 LTTNG_HOSTNAME_CTX_LEN
);
50 chan
->ops
->event_memset(ctx
, 0,
51 LTTNG_HOSTNAME_CTX_LEN
);
56 void hostname_get_value(struct lttng_ctx_field
*field
,
57 struct lttng_probe_ctx
*lttng_probe_ctx
,
58 union lttng_ctx_value
*value
)
60 struct nsproxy
*nsproxy
;
61 struct uts_namespace
*ns
;
65 * No need to take the RCU read-side lock to read current
66 * nsproxy. (documented in nsproxy.h)
68 nsproxy
= current
->nsproxy
;
71 hostname
= ns
->name
.nodename
;
75 value
->str
= hostname
;
78 int lttng_add_hostname_to_ctx(struct lttng_ctx
**ctx
)
80 struct lttng_ctx_field
*field
;
82 field
= lttng_append_context(ctx
);
85 if (lttng_find_context(*ctx
, "hostname")) {
86 lttng_remove_context_field(ctx
, field
);
89 field
->event_field
.name
= "hostname";
90 field
->event_field
.type
.atype
= atype_array
;
91 field
->event_field
.type
.u
.array
.elem_type
.atype
= atype_integer
;
92 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.size
= sizeof(char) * CHAR_BIT
;
93 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.alignment
= lttng_alignof(char) * CHAR_BIT
;
94 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.signedness
= lttng_is_signed_type(char);
95 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.reverse_byte_order
= 0;
96 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.base
= 10;
97 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.encoding
= lttng_encode_UTF8
;
98 field
->event_field
.type
.u
.array
.length
= LTTNG_HOSTNAME_CTX_LEN
;
100 field
->get_size
= hostname_get_size
;
101 field
->record
= hostname_record
;
102 field
->get_value
= hostname_get_value
;
103 lttng_context_update(*ctx
);
104 wrapper_vmalloc_sync_mappings();
107 EXPORT_SYMBOL_GPL(lttng_add_hostname_to_ctx
);