From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx> Add the function tracefs_kprobe_clear_probe() that will remove a single kprobe. If the @force parameter is set, it will disable that probe in all instances (including the top level instance) before removing it. Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> --- include/tracefs.h | 1 + src/tracefs-kprobes.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/tracefs.h b/include/tracefs.h index 54c461e85a2b..447821e65ce2 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -213,4 +213,5 @@ void tracefs_trace_pipe_stop(struct tracefs_instance *instance); int tracefs_kprobe_raw(const char *system, const char *event, const char *addr, const char *format); int tracefs_kprobe_clear(bool force); +int tracefs_kprobe_clear_probe(const char *system, const char *event, bool force); #endif /* _TRACE_FS_H */ diff --git a/src/tracefs-kprobes.c b/src/tracefs-kprobes.c index 48a4f090f041..27d4c2181404 100644 --- a/src/tracefs-kprobes.c +++ b/src/tracefs-kprobes.c @@ -204,3 +204,39 @@ int tracefs_kprobe_clear(bool force) free_instance_list(list); return ret; } + +int tracefs_kprobe_clear_probe(const char *system, const char *event, bool force) +{ + struct instance_list *list = NULL; + struct instance_list **plist = &list; + char *content; + int ret; + + if (!system) + system = "kprobes"; + + ret = asprintf(&content, "-:%s/%s", system, event); + if (ret < 0) + return -1; + + /* + * Since we know we are disabling a specific event, try + * to disable it first before clearing it. + */ + if (force) { + ret = tracefs_instances_walk(build_instances, &plist); + if (ret < 0) + goto out; + + ret = disable_events(system, event, list); + if (ret < 0) + goto out; + } + + ret = tracefs_instance_file_append(NULL, KPROBE_EVENTS, content); + out: + free(content); + free_instance_list(list); + + return ret < 0 ? -1 : 0; +} -- 2.30.2