2 * lttng-context-hostname.c
4 * LTTng hostname context.
6 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/sched.h>
26 #include <linux/utsname.h>
27 #include "lttng-events.h"
28 #include "wrapper/ringbuffer/frontend_types.h"
29 #include "wrapper/vmalloc.h"
30 #include "lttng-tracer.h"
32 #define LTTNG_HOSTNAME_CTX_LEN (__NEW_UTS_LEN + 1)
35 size_t hostname_get_size(size_t offset
)
39 size
+= LTTNG_HOSTNAME_CTX_LEN
;
44 void hostname_record(struct lttng_ctx_field
*field
,
45 struct lib_ring_buffer_ctx
*ctx
,
46 struct lttng_channel
*chan
)
48 struct nsproxy
*nsproxy
;
49 struct uts_namespace
*ns
;
53 * No need to take the RCU read-side lock to read current
54 * nsproxy. (documented in nsproxy.h)
56 nsproxy
= current
->nsproxy
;
59 hostname
= ns
->name
.nodename
;
60 chan
->ops
->event_write(ctx
, hostname
,
61 LTTNG_HOSTNAME_CTX_LEN
);
63 chan
->ops
->event_memset(ctx
, 0,
64 LTTNG_HOSTNAME_CTX_LEN
);
69 void hostname_get_value(struct lttng_ctx_field
*field
,
70 union lttng_ctx_value
*value
)
72 struct nsproxy
*nsproxy
;
73 struct uts_namespace
*ns
;
77 * No need to take the RCU read-side lock to read current
78 * nsproxy. (documented in nsproxy.h)
80 nsproxy
= current
->nsproxy
;
83 hostname
= ns
->name
.nodename
;
87 value
->str
= hostname
;
90 int lttng_add_hostname_to_ctx(struct lttng_ctx
**ctx
)
92 struct lttng_ctx_field
*field
;
94 field
= lttng_append_context(ctx
);
97 if (lttng_find_context(*ctx
, "hostname")) {
98 lttng_remove_context_field(ctx
, field
);
101 field
->event_field
.name
= "hostname";
102 field
->event_field
.type
.atype
= atype_array
;
103 field
->event_field
.type
.u
.array
.elem_type
.atype
= atype_integer
;
104 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.size
= sizeof(char) * CHAR_BIT
;
105 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.alignment
= lttng_alignof(char) * CHAR_BIT
;
106 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.signedness
= lttng_is_signed_type(char);
107 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.reverse_byte_order
= 0;
108 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.base
= 10;
109 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.encoding
= lttng_encode_UTF8
;
110 field
->event_field
.type
.u
.array
.length
= LTTNG_HOSTNAME_CTX_LEN
;
112 field
->get_size
= hostname_get_size
;
113 field
->record
= hostname_record
;
114 field
->get_value
= hostname_get_value
;
115 lttng_context_update(*ctx
);
116 wrapper_vmalloc_sync_all();
119 EXPORT_SYMBOL_GPL(lttng_add_hostname_to_ctx
);
121 MODULE_LICENSE("GPL and additional rights");
122 MODULE_AUTHOR("Mathieu Desnoyers");
123 MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support");
124 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION
) "."
125 __stringify(LTTNG_MODULES_MINOR_VERSION
) "."
126 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
)
127 LTTNG_MODULES_EXTRAVERSION
);