Commit 35551cf5 authored by Patrick Mochel's avatar Patrick Mochel

sysfs: fix file deletion again.

After looking into again, I realize that I was again getting file and 
directory deletion a little wrong. This patch should go back to mimmicking
the VFS again. 

- The extra dget() in sysfs_mknod() and sysfs_symlink() has been readded. 
This is identical to the way ramfs does creation. 

- We do d_delete() after simple_unlink() and simple_rmdir(), instead of 
d_invalidate() before it. This is how vfs_rmdir() and vfs_unlink() do it, 
and the way we used to.
parent 24fbb994
...@@ -96,9 +96,10 @@ static int sysfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t ...@@ -96,9 +96,10 @@ static int sysfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t
if (!dentry->d_inode) { if (!dentry->d_inode) {
inode = sysfs_get_inode(dir->i_sb, mode, dev); inode = sysfs_get_inode(dir->i_sb, mode, dev);
if (inode) if (inode) {
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
else dget(dentry);
} else
error = -ENOSPC; error = -ENOSPC;
} else } else
error = -EEXIST; error = -EEXIST;
...@@ -135,9 +136,10 @@ static int sysfs_symlink(struct inode * dir, struct dentry *dentry, const char * ...@@ -135,9 +136,10 @@ static int sysfs_symlink(struct inode * dir, struct dentry *dentry, const char *
if (inode) { if (inode) {
int l = strlen(symname)+1; int l = strlen(symname)+1;
error = page_symlink(inode, symname, l); error = page_symlink(inode, symname, l);
if (!error) if (!error) {
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
else dget(dentry);
} else
iput(inode); iput(inode);
} }
return error; return error;
...@@ -571,8 +573,8 @@ static void hash_and_remove(struct dentry * dir, const char * name) ...@@ -571,8 +573,8 @@ static void hash_and_remove(struct dentry * dir, const char * name)
/* make sure dentry is really there */ /* make sure dentry is really there */
if (victim->d_inode && if (victim->d_inode &&
(victim->d_parent->d_inode == dir->d_inode)) { (victim->d_parent->d_inode == dir->d_inode)) {
d_invalidate(victim);
simple_unlink(dir->d_inode,victim); simple_unlink(dir->d_inode,victim);
d_delete(victim);
} }
} }
up(&dir->d_inode->i_sem); up(&dir->d_inode->i_sem);
...@@ -631,15 +633,15 @@ void sysfs_remove_dir(struct kobject * kobj) ...@@ -631,15 +633,15 @@ void sysfs_remove_dir(struct kobject * kobj)
struct dentry * d = list_entry(node,struct dentry,d_child); struct dentry * d = list_entry(node,struct dentry,d_child);
/* make sure dentry is still there */ /* make sure dentry is still there */
if (d->d_inode) { if (d->d_inode) {
d_invalidate(d);
simple_unlink(dentry->d_inode,d); simple_unlink(dentry->d_inode,d);
d_delete(dentry);
} }
} }
up(&dentry->d_inode->i_sem); up(&dentry->d_inode->i_sem);
d_invalidate(dentry); d_invalidate(dentry);
simple_rmdir(parent->d_inode,dentry); simple_rmdir(parent->d_inode,dentry);
d_delete(dentry);
up(&parent->d_inode->i_sem); up(&parent->d_inode->i_sem);
dput(parent); dput(parent);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment