move ramfs' pure dcache manipulations into libfs.c
The simple_link(), simple_unlink(), simple_rename(), simple_sync_file(), simple_rmdir(), and simple_empty() functions are easy to duplicate. Basically, I duplicated them in an fs patch of mine, and Linus told me to put them in libfs.c
Pat Mochel has acked the changes for driverfs (in that he'll convert the stuff over when they're available from libfs), and my hugetlbfs implementation was the thing that spurred the whole incident.
Here it is,
Bill
fs/libfs.c +70 -0
@@ -208,3 +208,73 @@deactivate_super (s);return ERR_PTR (-ENOMEM ); } + +int simple_link (struct dentry *old_dentry,struct inode *dir,struct dentry *dentry) +{ +struct inode *inode = old_dentry->d_inode; + + inode->i_nlink++; +atomic_inc (&inode->i_count); +dget (dentry); +d_instantiate (dentry, inode); +return 0 ; +} + +static inline int simple_positive (struct dentry *dentry) +{ +return dentry->d_inode && !d_unhashed (dentry); +} + +int simple_empty (struct dentry *dentry) +{ +struct dentry *child; +int ret =0 ; + +spin_lock (&dcache_lock); +list_for_each_entry (child, &dentry->d_subdirs, d_child) +if (simple_positive (child)) + goto out; + ret =1 ; +out: +spin_unlock (&dcache_lock); +return ret; +} + +int simple_unlink (struct inode *dir,struct dentry *dentry) +{ +struct inode *inode = dentry->d_inode; + + inode->i_nlink--; +dput (dentry); +return 0 ; +} + +int simple_rmdir (struct inode *dir,struct dentry *dentry) +{ +if (!simple_empty (dentry)) +return -ENOTEMPTY ; + + dentry->d_inode->i_nlink--; +simple_unlink (dir, dentry); + dir->i_nlink--; +return 0 ; +} + +int simple_rename (struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry) +{ +struct inode *inode; + +if (!simple_empty (new_dentry)) +return -ENOTEMPTY ; + + inode = new_dentry->d_inode; +if (inode) { + inode->i_nlink--; +dput (new_dentry); + } +if (S_ISDIR (old_dentry->d_inode->i_mode)) { + old_dir->i_nlink--; + new_dir->i_nlink++; + } +return 0 ; +}
fs/ramfs/inode.c +5 -106
138 lines not on this page · raw message
include/linux/fs.h +6 -0
@@ -1290,6 +1290,12 @@extern loff_t dcache_dir_lseek (struct file *,loff_t ,int );extern int dcache_readdir (struct file *,void *,filldir_t );extern int simple_statfs (struct super_block *,struct statfs *); +extern int simple_link (struct dentry *,struct inode *,struct dentry *); +extern int simple_unlink (struct inode *,struct dentry *); +extern int simple_rmdir (struct inode *,struct dentry *); +extern int simple_rename (struct inode *,struct dentry *,struct inode *,struct dentry *); +extern int simple_sync_file (struct file *,struct dentry *,int ); +extern int simple_empty (struct dentry *);extern struct dentry *simple_lookup (struct inode *,struct dentry *);extern ssize_t generic_read_dir (struct file *,char *,size_t ,loff_t *);extern struct file_operations simple_dir_operations;
kernel/ksyms.c +6 -0
@@ -302,6 +302,12 @@EXPORT_SYMBOL (simple_lookup);EXPORT_SYMBOL (simple_dir_operations);EXPORT_SYMBOL (simple_dir_inode_operations); +EXPORT_SYMBOL (simple_link); +EXPORT_SYMBOL (simple_unlink); +EXPORT_SYMBOL (simple_rmdir); +EXPORT_SYMBOL (simple_rename); +EXPORT_SYMBOL (simple_sync_file); +EXPORT_SYMBOL (simple_empty);EXPORT_SYMBOL (fd_install);EXPORT_SYMBOL (put_unused_fd);EXPORT_SYMBOL (get_sb_bdev);