提交 978f3a45 编写于 作者: S Steven Rostedt 提交者: Ingo Molnar

ftrace: use struct pid

Impact: clean up, extend PID filtering to PID namespaces

Eric Biederman suggested using the struct pid for filtering on
pids in the kernel. This patch is based off of a demonstration
of an implementation that Eric sent me in an email.
Signed-off-by: NSteven Rostedt <srostedt@redhat.com>
Signed-off-by: NIngo Molnar <mingo@elte.hu>
上级 5ef64761
...@@ -48,7 +48,7 @@ int ftrace_enabled __read_mostly; ...@@ -48,7 +48,7 @@ int ftrace_enabled __read_mostly;
static int last_ftrace_enabled; static int last_ftrace_enabled;
/* set when tracing only a pid */ /* set when tracing only a pid */
int ftrace_pid_trace = -1; struct pid *ftrace_pid_trace;
/* Quick disabling of function tracer. */ /* Quick disabling of function tracer. */
int function_trace_stop; int function_trace_stop;
...@@ -153,7 +153,7 @@ static int __register_ftrace_function(struct ftrace_ops *ops) ...@@ -153,7 +153,7 @@ static int __register_ftrace_function(struct ftrace_ops *ops)
else else
func = ftrace_list_func; func = ftrace_list_func;
if (ftrace_pid_trace >= 0) { if (ftrace_pid_trace) {
set_ftrace_pid_function(func); set_ftrace_pid_function(func);
func = ftrace_pid_func; func = ftrace_pid_func;
} }
...@@ -209,7 +209,7 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops) ...@@ -209,7 +209,7 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops)
if (ftrace_list->next == &ftrace_list_end) { if (ftrace_list->next == &ftrace_list_end) {
ftrace_func_t func = ftrace_list->func; ftrace_func_t func = ftrace_list->func;
if (ftrace_pid_trace >= 0) { if (ftrace_pid_trace) {
set_ftrace_pid_function(func); set_ftrace_pid_function(func);
func = ftrace_pid_func; func = ftrace_pid_func;
} }
...@@ -239,7 +239,7 @@ static void ftrace_update_pid_func(void) ...@@ -239,7 +239,7 @@ static void ftrace_update_pid_func(void)
func = ftrace_trace_function; func = ftrace_trace_function;
if (ftrace_pid_trace >= 0) { if (ftrace_pid_trace) {
set_ftrace_pid_function(func); set_ftrace_pid_function(func);
func = ftrace_pid_func; func = ftrace_pid_func;
} else { } else {
...@@ -1678,18 +1678,40 @@ ftrace_pid_read(struct file *file, char __user *ubuf, ...@@ -1678,18 +1678,40 @@ ftrace_pid_read(struct file *file, char __user *ubuf,
char buf[64]; char buf[64];
int r; int r;
if (ftrace_pid_trace >= 0) if (ftrace_pid_trace)
r = sprintf(buf, "%u\n", ftrace_pid_trace); r = sprintf(buf, "%u\n", pid_nr(ftrace_pid_trace));
else else
r = sprintf(buf, "no pid\n"); r = sprintf(buf, "no pid\n");
return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
} }
static void clear_ftrace_pid_task(struct pid **pid)
{
struct task_struct *p;
do_each_pid_task(*pid, PIDTYPE_PID, p) {
clear_tsk_trace_trace(p);
} while_each_pid_task(*pid, PIDTYPE_PID, p);
put_pid(*pid);
*pid = NULL;
}
static void set_ftrace_pid_task(struct pid *pid)
{
struct task_struct *p;
do_each_pid_task(pid, PIDTYPE_PID, p) {
set_tsk_trace_trace(p);
} while_each_pid_task(pid, PIDTYPE_PID, p);
}
static ssize_t static ssize_t
ftrace_pid_write(struct file *filp, const char __user *ubuf, ftrace_pid_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos) size_t cnt, loff_t *ppos)
{ {
struct pid *pid;
char buf[64]; char buf[64];
long val; long val;
int ret; int ret;
...@@ -1707,40 +1729,30 @@ ftrace_pid_write(struct file *filp, const char __user *ubuf, ...@@ -1707,40 +1729,30 @@ ftrace_pid_write(struct file *filp, const char __user *ubuf,
return ret; return ret;
mutex_lock(&ftrace_start_lock); mutex_lock(&ftrace_start_lock);
if (ret < 0) { if (val < 0) {
/* disable pid tracing */ /* disable pid tracing */
if (ftrace_pid_trace < 0) if (!ftrace_pid_trace)
goto out; goto out;
ftrace_pid_trace = -1;
clear_ftrace_pid_task(&ftrace_pid_trace);
} else { } else {
struct task_struct *p; pid = find_get_pid(val);
int found = 0;
if (ftrace_pid_trace == val) if (pid == ftrace_pid_trace) {
put_pid(pid);
goto out; goto out;
/*
* Find the task that matches this pid.
* TODO: use pid namespaces instead.
*/
rcu_read_lock();
for_each_process(p) {
if (p->pid == val) {
found = 1;
set_tsk_trace_trace(p);
} else if (test_tsk_trace_trace(p))
clear_tsk_trace_trace(p);
} }
rcu_read_unlock();
if (found) if (ftrace_pid_trace)
ftrace_pid_trace = val; clear_ftrace_pid_task(&ftrace_pid_trace);
else {
if (ftrace_pid_trace < 0) if (!pid)
goto out; goto out;
ftrace_pid_trace = -1;
} ftrace_pid_trace = pid;
set_ftrace_pid_task(ftrace_pid_trace);
} }
/* update the function call */ /* update the function call */
......
...@@ -541,11 +541,11 @@ print_graph_function(struct trace_iterator *iter) ...@@ -541,11 +541,11 @@ print_graph_function(struct trace_iterator *iter)
} }
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
extern int ftrace_pid_trace; extern struct pid *ftrace_pid_trace;
static inline int ftrace_trace_task(struct task_struct *task) static inline int ftrace_trace_task(struct task_struct *task)
{ {
if (ftrace_pid_trace < 0) if (ftrace_pid_trace)
return 1; return 1;
return test_tsk_trace_trace(task); return test_tsk_trace_trace(task);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册