Skip to content

Commit

Permalink
tracing/filter: Remove empty subsystem and its directory
Browse files Browse the repository at this point in the history
Remove empty subsystem and its directory when module unload.

Before patch:
 # rmmod trace-events-sample.ko
 # ls sample
 enable  filter

After patch:
 # rmmod trace-events-sample.ko
 # ls sample
 ls: cannot access sample: No such file or directory

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Acked-by: Tom Zanussi <tzanussi@gmail.com>
Reviewed-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <4A55A8BE.9010707@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Xiao Guangrong authored and Ingo Molnar committed Jul 10, 2009
1 parent c5cb183 commit dc82ec9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions kernel/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ struct event_subsystem {
const char *name;
struct dentry *entry;
void *filter;
int nr_events;
};

struct filter_pred;
Expand Down
32 changes: 31 additions & 1 deletion kernel/trace/trace_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,10 @@ event_subsystem_dir(const char *name, struct dentry *d_events)

/* First see if we did not already create this dir */
list_for_each_entry(system, &event_subsystems, list) {
if (strcmp(system->name, name) == 0)
if (strcmp(system->name, name) == 0) {
system->nr_events++;
return system->entry;
}
}

/* need to create new entry */
Expand All @@ -871,6 +873,7 @@ event_subsystem_dir(const char *name, struct dentry *d_events)
return d_events;
}

system->nr_events = 1;
system->name = kstrdup(name, GFP_KERNEL);
if (!system->name) {
debugfs_remove(system->entry);
Expand Down Expand Up @@ -905,6 +908,32 @@ event_subsystem_dir(const char *name, struct dentry *d_events)
return system->entry;
}

static void remove_subsystem_dir(const char *name)
{
struct event_subsystem *system;

if (strcmp(name, TRACE_SYSTEM) == 0)
return;

list_for_each_entry(system, &event_subsystems, list) {
if (strcmp(system->name, name) == 0) {
if (!--system->nr_events) {
struct event_filter *filter = system->filter;

debugfs_remove_recursive(system->entry);
list_del(&system->list);
if (filter) {
kfree(filter->filter_string);
kfree(filter);
}
kfree(system->name);
kfree(system);
}
break;
}
}
}

static int
event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
const struct file_operations *id,
Expand Down Expand Up @@ -1079,6 +1108,7 @@ static void trace_module_remove_events(struct module *mod)
list_del(&call->list);
trace_destroy_fields(call);
destroy_preds(call);
remove_subsystem_dir(call->system);
}
}

Expand Down

0 comments on commit dc82ec9

Please sign in to comment.