Support the hostname context
[lttng-modules.git] / lttng-context-hostname.c
CommitLineData
975da2c0
JD
1/*
2 * lttng-context-hostname.c
3 *
4 * LTTng hostname context.
5 *
6 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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.
12 *
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.
17 *
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
21 */
22
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"
31
32#define LTTNG_HOSTNAME_CTX_LEN (__NEW_UTS_LEN + 1)
33
34static
35size_t hostname_get_size(size_t offset)
36{
37 size_t size = 0;
38
39 size += LTTNG_HOSTNAME_CTX_LEN;
40 return size;
41}
42
43static
44void hostname_record(struct lttng_ctx_field *field,
45 struct lib_ring_buffer_ctx *ctx,
46 struct lttng_channel *chan)
47{
48 struct nsproxy *nsproxy;
49 struct uts_namespace *ns;
50 char *hostname;
51
52 rcu_read_lock();
53 nsproxy = task_nsproxy(current);
54 if (nsproxy) {
55 ns = nsproxy->uts_ns;
56 hostname = ns->name.nodename;
57 chan->ops->event_write(ctx, hostname,
58 LTTNG_HOSTNAME_CTX_LEN);
59 } else {
60 chan->ops->event_memset(ctx, 0,
61 LTTNG_HOSTNAME_CTX_LEN);
62 }
63 rcu_read_unlock();
64}
65
66int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx)
67{
68 struct lttng_ctx_field *field;
69
70 field = lttng_append_context(ctx);
71 if (!field)
72 return -ENOMEM;
73 if (lttng_find_context(*ctx, "hostname")) {
74 lttng_remove_context_field(ctx, field);
75 return -EEXIST;
76 }
77 field->event_field.name = "hostname";
78 field->event_field.type.atype = atype_array;
79 field->event_field.type.u.array.elem_type.atype = atype_integer;
80 field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT;
81 field->event_field.type.u.array.elem_type.u.basic.integer.alignment = lttng_alignof(char) * CHAR_BIT;
82 field->event_field.type.u.array.elem_type.u.basic.integer.signedness = is_signed_type(char);
83 field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0;
84 field->event_field.type.u.array.elem_type.u.basic.integer.base = 10;
85 field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8;
86 field->event_field.type.u.array.length = LTTNG_HOSTNAME_CTX_LEN;
87
88 field->get_size = hostname_get_size;
89 field->record = hostname_record;
90 wrapper_vmalloc_sync_all();
91 return 0;
92}
93EXPORT_SYMBOL_GPL(lttng_add_hostname_to_ctx);
94
95MODULE_LICENSE("GPL and additional rights");
96MODULE_AUTHOR("Mathieu Desnoyers");
97MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support");
This page took 0.026956 seconds and 4 git commands to generate.