From 6834100251307f036a3972b88e57fdd0211a7580 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Fri, 25 Mar 2016 11:08:20 -0700 Subject: [PATCH] scoutfs: free our dentry info Stop leaking dentry_info allocations by adding a dentry_op with a d_release that frees our dentry info allocation. rmmod tests no longer fail when dmesg screams that we have slab caches that still have allocated objects. Signed-off-by: Zach Brown s --- kmod/src/dir.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/kmod/src/dir.c b/kmod/src/dir.c index 5a2902f5..cec7d878 100644 --- a/kmod/src/dir.c +++ b/kmod/src/dir.c @@ -128,6 +128,20 @@ struct dentry_info { static struct kmem_cache *scoutfs_dentry_cachep; +static void scoutfs_d_release(struct dentry *dentry) +{ + struct dentry_info *di = dentry->d_fsdata; + + if (di) { + kmem_cache_free(scoutfs_dentry_cachep, di); + dentry->d_fsdata = NULL; + } +} + +static const struct dentry_operations scoutfs_dentry_ops = { + .d_release = scoutfs_d_release, +}; + static struct dentry_info *alloc_dentry_info(struct dentry *dentry) { struct dentry_info *di; @@ -141,8 +155,11 @@ static struct dentry_info *alloc_dentry_info(struct dentry *dentry) return ERR_PTR(-ENOMEM); spin_lock(&dentry->d_lock); - if (!dentry->d_fsdata) + if (!dentry->d_fsdata) { dentry->d_fsdata = di; + d_set_d_op(dentry, &scoutfs_dentry_ops); + } + spin_unlock(&dentry->d_lock); if (di != dentry->d_fsdata)