[ltt-dev] [PATCH] lttng: remove ltt root directory if it's no needed
Gui Jianfeng
guijianfeng at cn.fujitsu.com
Wed Feb 18 03:16:33 EST 2009
We have to cleanup the lttng's root directory of debugfs if
there is nobody uses it any more.
This patch is based on 2.6.29-rc3-lttng-0.92.
Signed-off-by: Gui Jianfeng <guijianfeng at cn.fujitsu.com>
---
include/linux/ltt-core.h | 1 +
ltt/ltt-core.c | 7 +++++++
ltt/ltt-trace-control.c | 11 +++++++++++
ltt/ltt-userspace-event.c | 10 ++++++++++
4 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/include/linux/ltt-core.h b/include/linux/ltt-core.h
index bc244c6..e43fc52 100644
--- a/include/linux/ltt-core.h
+++ b/include/linux/ltt-core.h
@@ -30,6 +30,7 @@ extern struct ltt_traces ltt_traces;
/*
* get dentry of ltt's root dir
*/
+void reset_ltt_root(void);
struct dentry *get_ltt_root(void);
/* Keep track of trap nesting inside LTT */
diff --git a/ltt/ltt-core.c b/ltt/ltt-core.c
index 18db91d..26c04b5 100644
--- a/ltt/ltt-core.c
+++ b/ltt/ltt-core.c
@@ -23,6 +23,13 @@ static DEFINE_MUTEX(ltt_traces_mutex);
/* dentry of ltt's root dir */
static struct dentry *ltt_root_dentry;
+
+void reset_ltt_root(void)
+{
+ ltt_root_dentry = NULL;
+}
+EXPORT_SYMBOL_GPL(reset_ltt_root);
+
struct dentry *get_ltt_root(void)
{
if (!ltt_root_dentry) {
diff --git a/ltt/ltt-trace-control.c b/ltt/ltt-trace-control.c
index 16502a2..21416b1 100644
--- a/ltt/ltt-trace-control.c
+++ b/ltt/ltt-trace-control.c
@@ -740,6 +740,10 @@ err_create_destroy_trace_file:
err_create_setup_trace_file:
debugfs_remove(ltt_control_dir);
err_create_control_dir:
+ if (list_empty(<t_root_dentry->d_subdirs)) {
+ debugfs_remove(ltt_root_dentry);
+ reset_ltt_root();
+ }
err_no_root:
return err;
}
@@ -747,6 +751,9 @@ err_no_root:
static void __exit ltt_trace_control_exit(void)
{
struct dentry *trace_dir;
+ struct dentry *ltt_root_dentry;
+
+ ltt_root_dentry = get_ltt_root();
/* destory all traces */
list_for_each_entry(trace_dir, <t_control_dir->d_subdirs,
@@ -759,6 +766,10 @@ static void __exit ltt_trace_control_exit(void)
debugfs_remove(ltt_setup_trace_file);
debugfs_remove(ltt_destroy_trace_file);
debugfs_remove_recursive(ltt_control_dir);
+ if (list_empty(<t_root_dentry->d_subdirs)) {
+ debugfs_remove(ltt_root_dentry);
+ reset_ltt_root();
+ }
}
module_init(ltt_trace_control_init);
diff --git a/ltt/ltt-userspace-event.c b/ltt/ltt-userspace-event.c
index 385bd3b..ef4fbb2 100644
--- a/ltt/ltt-userspace-event.c
+++ b/ltt/ltt-userspace-event.c
@@ -117,7 +117,17 @@ err_no_root:
static void __exit ltt_userspace_exit(void)
{
+ struct dentry *ltt_root_dentry;
+
+ ltt_root_dentry = get_ltt_root();
+
debugfs_remove(ltt_event_file);
+ if (ltt_root_dentry) {
+ if (list_empty(<t_root_dentry->d_subdirs)) {
+ debugfs_remove(ltt_root_dentry);
+ reset_ltt_root();
+ }
+ }
}
module_init(ltt_userspace_init);
--
1.5.4.rc3
More information about the lttng-dev
mailing list