[PATCH 4/5] DebugFS : file/directory creation error handling, 2.6.18

Mathieu Desnoyers
2006-11-23T08:12:39Z

Correct dentry count to handle creation errors.

This patch puts a dput at the file creation instead of the file removal :
lookup_one_len already returns a dentry with reference count of 1. Then,
the dget() in simple_mknod increments it when the dentry is associated with a
file. In a scenario where simple_create or simple_mkdir returns an error, this
would lead to an unwanted increment of the reference counter, therefore making
file removal impossible.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>

--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -153,10 +153,10 @@
error = debugfs_mkdir(parent->d_inode, *dentry, mode);
else
error = debugfs_create(parent->d_inode, *dentry, mode);
+ dput(*dentry);
} else
error = PTR_ERR(dentry);
mutex_unlock(&parent->d_inode->i_mutex);
-
return error;
}

@@ -265,6 +265,7 @@
void debugfs_remove(struct dentry *dentry)
{
struct dentry *parent;
+ int ret = 0;

if (!dentry)
return;
@@ -276,11 +277,15 @@
mutex_lock(&parent->d_inode->i_mutex);
if (debugfs_positive(dentry)) {
if (dentry->d_inode) {
- if (S_ISDIR(dentry->d_inode->i_mode))
- simple_rmdir(parent->d_inode, dentry);
- else
+ if (S_ISDIR(dentry->d_inode->i_mode)) {
+ ret = simple_rmdir(parent->d_inode, dentry);
+ if (ret)
+ printk(KERN_ERR
+ "DebugFS rmdir on %s failed : "
+ "directory not empty.\n",
+ dentry->d_name.name);
+ } else
simple_unlink(parent->d_inode, dentry);
- dput(dentry);
}
}
mutex_unlock(&parent->d_inode->i_mutex);