1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/* -*- linux-c -*-
* relayfs.c - relayfs transport functions
*
* Copyright (C) IBM Corporation, 2005, 2006
* Copyright (C) 2005-2008 Red Hat Inc.
*
* This file is part of systemtap, and is free software. You can
* redistribute it and/or modify it under the terms of the GNU General
* Public License (GPL); either version 2, or (at your option) any
* later version.
*/
/* This file is only for older kernels that have no debugfs. */
/* relayfs is required! */
#if !defined (CONFIG_RELAYFS_FS) && !defined (CONFIG_RELAYFS_FS_MODULE)
#error "RelayFS does not appear to be in this kernel!"
#endif
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/percpu.h>
#include <linux/init.h>
#include <linux/relayfs_fs.h>
#include <linux/namei.h>
struct _stp_relay_data_type {
enum _stp_transport_state transport_state;
struct rchan *rchan;
int flushing;
};
struct _stp_relay_data_type _stp_relay_data;
/* We need to include procfs.c here so that it can see the
* _stp_relay_data_type definition. */
#include "procfs.c"
/**
* __stp_relay_subbuf_start_callback - subbuf_start() relayfs
* callback implementation
*/
static int
__stp_relay_subbuf_start_callback(struct rchan_buf *buf,
void *subbuf,
unsigned prev_subbuf_idx,
void *prev_subbuf)
{
unsigned padding = buf->padding[prev_subbuf_idx];
if (prev_subbuf)
*((unsigned *)prev_subbuf) = padding;
return sizeof(padding); /* reserve space for padding */
}
/**
* __stp_relay_buf_full_callback - buf_full() relayfs callback
* implementation
*/
static void __stp_relay_buf_full_callback(struct rchan_buf *buf,
unsigned subbuf_idx,
void *subbuf)
{
unsigned padding = buf->padding[subbuf_idx];
*((unsigned *)subbuf) = padding;
}
static struct rchan_callbacks stp_rchan_callbacks =
{
.subbuf_start = __stp_relay_subbuf_start_callback,
.buf_full = __stp_relay_buf_full_callback,
};
static void _stp_transport_data_fs_start(void)
{
if (_stp_relay_data.transport_state == STP_TRANSPORT_INITIALIZED)
_stp_relay_data.transport_state = STP_TRANSPORT_RUNNING;
}
static void _stp_transport_data_fs_stop(void)
{
if (_stp_relay_data.transport_state == STP_TRANSPORT_RUNNING) {
_stp_relay_data.transport_state = STP_TRANSPORT_STOPPED;
_stp_relay_data.flushing = 1;
if (_stp_relay_data.rchan)
relay_flush(_stp_relay_data.rchan);
}
}
static void _stp_transport_data_fs_close(void)
{
_stp_transport_data_fs_stop();
if (_stp_relay_data.rchan) {
relay_close(_stp_relay_data.rchan);
_stp_relay_data.rchan = NULL;
}
}
static int _stp_transport_data_fs_init(void)
{
int rc = 0;
int i;
dbug_trans(1, "relay_open %d %d\n", _stp_subbuf_size, _stp_nsubbufs);
_stp_relay_data.transport_state = STP_TRANSPORT_STOPPED;
_stp_relay_data.flushing = 0;
/* Create "trace" file. */
_stp_relay_data.rchan = relay_open("trace", _stp_get_module_dir(),
_stp_subbuf_size, _stp_nsubbufs,
0, &stp_rchan_callbacks);
if (!_stp_relay_data.rchan) {
rc = -ENOENT;
goto err;
}
/* now set ownership */
for_each_online_cpu(i) {
_stp_relay_data.rchan->buf[i]->dentry->d_inode->i_uid
= _stp_uid;
_stp_relay_data.rchan->buf[i]->dentry->d_inode->i_gid
= _stp_gid;
}
/* We're initialized. */
_stp_relay_data.transport_state = STP_TRANSPORT_INITIALIZED;
return rc;
err:
errk("couldn't create relay channel.\n");
_stp_transport_data_fs_close();
return rc;
}
static enum _stp_transport_state _stp_transport_get_state(void)
{
return _stp_relay_data.transport_state;
}
static void _stp_transport_data_fs_overwrite(int overwrite)
{
_stp_relay_data.rchan->overwrite = overwrite;
}
/**
* _stp_data_write_reserve - try to reserve size_request bytes
* @size_request: number of bytes to attempt to reserve
* @entry: entry is returned here
*
* Returns number of bytes reserved, 0 if full. On return, entry
* will point to allocated opaque pointer. Use
* _stp_data_entry_data() to get pointer to copy data into.
*
* (For this code's purposes, entry is filled in with the actual
* data pointer, but the caller doesn't know that.)
*/
static size_t
_stp_data_write_reserve(size_t size_request, void **entry)
{
if (entry == NULL)
return -EINVAL;
*entry = relay_reserve(_stp_relay_data.rchan, size_request);
if (*entry == NULL)
return 0;
return size_request;
}
static unsigned char *_stp_data_entry_data(void *entry)
{
/* Nothing to do here. */
return entry;
}
static int _stp_data_write_commit(void *entry)
{
/* Nothing to do here. */
return 0;
}
|