Commit d728900c authored by Jan Harkes's avatar Jan Harkes Committed by Linus Torvalds

coda: fix nlink updates for directories

The Coda client sets the directory link count to 1 when it isn't sure how many
subdirectories we have.  In this case we shouldn't change the link count in
the kernel when a subdirectory is created or removed.
Signed-off-by: default avatarJan Harkes <jaharkes@cs.cmu.edu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 56ee3547
...@@ -173,12 +173,11 @@ int coda_permission(struct inode *inode, int mask, struct nameidata *nd) ...@@ -173,12 +173,11 @@ int coda_permission(struct inode *inode, int mask, struct nameidata *nd)
out: out:
unlock_kernel(); unlock_kernel();
return error; return error;
} }
static inline void coda_dir_changed(struct inode *dir, int link) static inline void coda_dir_update_mtime(struct inode *dir)
{ {
#ifdef REQUERY_VENUS_FOR_MTIME #ifdef REQUERY_VENUS_FOR_MTIME
/* invalidate the directory cnode's attributes so we refetch the /* invalidate the directory cnode's attributes so we refetch the
...@@ -190,8 +189,23 @@ static inline void coda_dir_changed(struct inode *dir, int link) ...@@ -190,8 +189,23 @@ static inline void coda_dir_changed(struct inode *dir, int link)
* right most of the time. Note: we only do this for directories. */ * right most of the time. Note: we only do this for directories. */
dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
#endif #endif
if (link) }
dir->i_nlink += link;
/* we have to wrap inc_nlink/drop_nlink because sometimes userspace uses a
* trick to fool GNU find's optimizations. If we can't be sure of the link
* (because of volume mount points) we set i_nlink to 1 which forces find
* to consider every child as a possible directory. We should also never
* see an increment or decrement for deleted directories where i_nlink == 0 */
static inline void coda_dir_inc_nlink(struct inode *dir)
{
if (dir->i_nlink >= 2)
inc_nlink(dir);
}
static inline void coda_dir_drop_nlink(struct inode *dir)
{
if (dir->i_nlink > 2)
drop_nlink(dir);
} }
/* creation routines: create, mknod, mkdir, link, symlink */ /* creation routines: create, mknod, mkdir, link, symlink */
...@@ -229,7 +243,7 @@ static int coda_create(struct inode *dir, struct dentry *de, int mode, struct na ...@@ -229,7 +243,7 @@ static int coda_create(struct inode *dir, struct dentry *de, int mode, struct na
} }
/* invalidate the directory cnode's attributes */ /* invalidate the directory cnode's attributes */
coda_dir_changed(dir, 0); coda_dir_update_mtime(dir);
unlock_kernel(); unlock_kernel();
d_instantiate(de, inode); d_instantiate(de, inode);
return 0; return 0;
...@@ -270,7 +284,8 @@ static int coda_mkdir(struct inode *dir, struct dentry *de, int mode) ...@@ -270,7 +284,8 @@ static int coda_mkdir(struct inode *dir, struct dentry *de, int mode)
} }
/* invalidate the directory cnode's attributes */ /* invalidate the directory cnode's attributes */
coda_dir_changed(dir, 1); coda_dir_inc_nlink(dir);
coda_dir_update_mtime(dir);
unlock_kernel(); unlock_kernel();
d_instantiate(de, inode); d_instantiate(de, inode);
return 0; return 0;
...@@ -301,7 +316,7 @@ static int coda_link(struct dentry *source_de, struct inode *dir_inode, ...@@ -301,7 +316,7 @@ static int coda_link(struct dentry *source_de, struct inode *dir_inode,
goto out; goto out;
} }
coda_dir_changed(dir_inode, 0); coda_dir_update_mtime(dir_inode);
atomic_inc(&inode->i_count); atomic_inc(&inode->i_count);
d_instantiate(de, inode); d_instantiate(de, inode);
inc_nlink(inode); inc_nlink(inode);
...@@ -344,7 +359,7 @@ static int coda_symlink(struct inode *dir_inode, struct dentry *de, ...@@ -344,7 +359,7 @@ static int coda_symlink(struct inode *dir_inode, struct dentry *de,
/* mtime is no good anymore */ /* mtime is no good anymore */
if ( !error ) if ( !error )
coda_dir_changed(dir_inode, 0); coda_dir_update_mtime(dir_inode);
unlock_kernel(); unlock_kernel();
return error; return error;
...@@ -366,10 +381,9 @@ int coda_unlink(struct inode *dir, struct dentry *de) ...@@ -366,10 +381,9 @@ int coda_unlink(struct inode *dir, struct dentry *de)
return error; return error;
} }
coda_dir_changed(dir, 0); coda_dir_update_mtime(dir);
drop_nlink(de->d_inode); drop_nlink(de->d_inode);
unlock_kernel(); unlock_kernel();
return 0; return 0;
} }
...@@ -393,11 +407,11 @@ int coda_rmdir(struct inode *dir, struct dentry *de) ...@@ -393,11 +407,11 @@ int coda_rmdir(struct inode *dir, struct dentry *de)
return error; return error;
} }
coda_dir_changed(dir, -1); coda_dir_drop_nlink(dir);
coda_dir_update_mtime(dir);
drop_nlink(de->d_inode); drop_nlink(de->d_inode);
d_delete(de); d_delete(de);
unlock_kernel(); unlock_kernel();
return 0; return 0;
} }
...@@ -409,7 +423,6 @@ static int coda_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -409,7 +423,6 @@ static int coda_rename(struct inode *old_dir, struct dentry *old_dentry,
const char *new_name = new_dentry->d_name.name; const char *new_name = new_dentry->d_name.name;
int old_length = old_dentry->d_name.len; int old_length = old_dentry->d_name.len;
int new_length = new_dentry->d_name.len; int new_length = new_dentry->d_name.len;
int link_adjust = 0;
int error; int error;
lock_kernel(); lock_kernel();
...@@ -421,11 +434,12 @@ static int coda_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -421,11 +434,12 @@ static int coda_rename(struct inode *old_dir, struct dentry *old_dentry,
if ( !error ) { if ( !error ) {
if ( new_dentry->d_inode ) { if ( new_dentry->d_inode ) {
if ( S_ISDIR(new_dentry->d_inode->i_mode) ) if ( S_ISDIR(new_dentry->d_inode->i_mode) ) {
link_adjust = 1; coda_dir_drop_nlink(old_dir);
coda_dir_inc_nlink(new_dir);
coda_dir_changed(old_dir, -link_adjust); }
coda_dir_changed(new_dir, link_adjust); coda_dir_update_mtime(old_dir);
coda_dir_update_mtime(new_dir);
coda_flag_inode(new_dentry->d_inode, C_VATTR); coda_flag_inode(new_dentry->d_inode, C_VATTR);
} else { } else {
coda_flag_inode(old_dir, C_VATTR); coda_flag_inode(old_dir, C_VATTR);
......
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