Commit 83360269 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'i_nlink' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6

* 'i_nlink' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
  hfs: fix rename() over non-empty directory
  udf: fix i_nlink limit
  fix reiserfs mkdir() breakage
  exofs: i_nlink races in rename()
  nilfs2: i_nlink races in rename()
  minix: i_nlink races in rename()
  ufs: i_nlink races in rename()
  sysv: i_nlink races in rename()
parents 4c7fd114 69102e9b
...@@ -272,7 +272,6 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -272,7 +272,6 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry,
new_de = exofs_find_entry(new_dir, new_dentry, &new_page); new_de = exofs_find_entry(new_dir, new_dentry, &new_page);
if (!new_de) if (!new_de)
goto out_dir; goto out_dir;
inode_inc_link_count(old_inode);
err = exofs_set_link(new_dir, new_de, new_page, old_inode); err = exofs_set_link(new_dir, new_de, new_page, old_inode);
new_inode->i_ctime = CURRENT_TIME; new_inode->i_ctime = CURRENT_TIME;
if (dir_de) if (dir_de)
...@@ -286,12 +285,9 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -286,12 +285,9 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry,
if (new_dir->i_nlink >= EXOFS_LINK_MAX) if (new_dir->i_nlink >= EXOFS_LINK_MAX)
goto out_dir; goto out_dir;
} }
inode_inc_link_count(old_inode);
err = exofs_add_link(new_dentry, old_inode); err = exofs_add_link(new_dentry, old_inode);
if (err) { if (err)
inode_dec_link_count(old_inode);
goto out_dir; goto out_dir;
}
if (dir_de) if (dir_de)
inode_inc_link_count(new_dir); inode_inc_link_count(new_dir);
} }
...@@ -299,7 +295,7 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -299,7 +295,7 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry,
old_inode->i_ctime = CURRENT_TIME; old_inode->i_ctime = CURRENT_TIME;
exofs_delete_entry(old_de, old_page); exofs_delete_entry(old_de, old_page);
inode_dec_link_count(old_inode); mark_inode_dirty(old_inode);
if (dir_de) { if (dir_de) {
err = exofs_set_link(old_inode, dir_de, dir_page, new_dir); err = exofs_set_link(old_inode, dir_de, dir_page, new_dir);
......
...@@ -238,46 +238,22 @@ static int hfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -238,46 +238,22 @@ static int hfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
} }
/* /*
* hfs_unlink() * hfs_remove()
* *
* This is the unlink() entry in the inode_operations structure for * This serves as both unlink() and rmdir() in the inode_operations
* regular HFS directories. The purpose is to delete an existing * structure for regular HFS directories. The purpose is to delete
* file, given the inode for the parent directory and the name * an existing child, given the inode for the parent directory and
* (and its length) of the existing file. * the name (and its length) of the existing directory.
*/
static int hfs_unlink(struct inode *dir, struct dentry *dentry)
{
struct inode *inode;
int res;
inode = dentry->d_inode;
res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name);
if (res)
return res;
drop_nlink(inode);
hfs_delete_inode(inode);
inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(inode);
return res;
}
/*
* hfs_rmdir()
* *
* This is the rmdir() entry in the inode_operations structure for * HFS does not have hardlinks, so both rmdir and unlink set the
* regular HFS directories. The purpose is to delete an existing * link count to 0. The only difference is the emptiness check.
* directory, given the inode for the parent directory and the name
* (and its length) of the existing directory.
*/ */
static int hfs_rmdir(struct inode *dir, struct dentry *dentry) static int hfs_remove(struct inode *dir, struct dentry *dentry)
{ {
struct inode *inode; struct inode *inode = dentry->d_inode;
int res; int res;
inode = dentry->d_inode; if (S_ISDIR(inode->i_mode) && inode->i_size != 2)
if (inode->i_size != 2)
return -ENOTEMPTY; return -ENOTEMPTY;
res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name); res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name);
if (res) if (res)
...@@ -307,7 +283,7 @@ static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -307,7 +283,7 @@ static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry,
/* Unlink destination if it already exists */ /* Unlink destination if it already exists */
if (new_dentry->d_inode) { if (new_dentry->d_inode) {
res = hfs_unlink(new_dir, new_dentry); res = hfs_remove(new_dir, new_dentry);
if (res) if (res)
return res; return res;
} }
...@@ -332,9 +308,9 @@ const struct file_operations hfs_dir_operations = { ...@@ -332,9 +308,9 @@ const struct file_operations hfs_dir_operations = {
const struct inode_operations hfs_dir_inode_operations = { const struct inode_operations hfs_dir_inode_operations = {
.create = hfs_create, .create = hfs_create,
.lookup = hfs_lookup, .lookup = hfs_lookup,
.unlink = hfs_unlink, .unlink = hfs_remove,
.mkdir = hfs_mkdir, .mkdir = hfs_mkdir,
.rmdir = hfs_rmdir, .rmdir = hfs_remove,
.rename = hfs_rename, .rename = hfs_rename,
.setattr = hfs_inode_setattr, .setattr = hfs_inode_setattr,
}; };
...@@ -213,7 +213,6 @@ static int minix_rename(struct inode * old_dir, struct dentry *old_dentry, ...@@ -213,7 +213,6 @@ static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
new_de = minix_find_entry(new_dentry, &new_page); new_de = minix_find_entry(new_dentry, &new_page);
if (!new_de) if (!new_de)
goto out_dir; goto out_dir;
inode_inc_link_count(old_inode);
minix_set_link(new_de, new_page, old_inode); minix_set_link(new_de, new_page, old_inode);
new_inode->i_ctime = CURRENT_TIME_SEC; new_inode->i_ctime = CURRENT_TIME_SEC;
if (dir_de) if (dir_de)
...@@ -225,18 +224,15 @@ static int minix_rename(struct inode * old_dir, struct dentry *old_dentry, ...@@ -225,18 +224,15 @@ static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
if (new_dir->i_nlink >= info->s_link_max) if (new_dir->i_nlink >= info->s_link_max)
goto out_dir; goto out_dir;
} }
inode_inc_link_count(old_inode);
err = minix_add_link(new_dentry, old_inode); err = minix_add_link(new_dentry, old_inode);
if (err) { if (err)
inode_dec_link_count(old_inode);
goto out_dir; goto out_dir;
}
if (dir_de) if (dir_de)
inode_inc_link_count(new_dir); inode_inc_link_count(new_dir);
} }
minix_delete_entry(old_de, old_page); minix_delete_entry(old_de, old_page);
inode_dec_link_count(old_inode); mark_inode_dirty(old_inode);
if (dir_de) { if (dir_de) {
minix_set_link(dir_de, dir_page, new_dir); minix_set_link(dir_de, dir_page, new_dir);
......
...@@ -397,7 +397,6 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -397,7 +397,6 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
new_de = nilfs_find_entry(new_dir, &new_dentry->d_name, &new_page); new_de = nilfs_find_entry(new_dir, &new_dentry->d_name, &new_page);
if (!new_de) if (!new_de)
goto out_dir; goto out_dir;
inc_nlink(old_inode);
nilfs_set_link(new_dir, new_de, new_page, old_inode); nilfs_set_link(new_dir, new_de, new_page, old_inode);
nilfs_mark_inode_dirty(new_dir); nilfs_mark_inode_dirty(new_dir);
new_inode->i_ctime = CURRENT_TIME; new_inode->i_ctime = CURRENT_TIME;
...@@ -411,13 +410,9 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -411,13 +410,9 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
if (new_dir->i_nlink >= NILFS_LINK_MAX) if (new_dir->i_nlink >= NILFS_LINK_MAX)
goto out_dir; goto out_dir;
} }
inc_nlink(old_inode);
err = nilfs_add_link(new_dentry, old_inode); err = nilfs_add_link(new_dentry, old_inode);
if (err) { if (err)
drop_nlink(old_inode);
nilfs_mark_inode_dirty(old_inode);
goto out_dir; goto out_dir;
}
if (dir_de) { if (dir_de) {
inc_nlink(new_dir); inc_nlink(new_dir);
nilfs_mark_inode_dirty(new_dir); nilfs_mark_inode_dirty(new_dir);
...@@ -431,7 +426,6 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -431,7 +426,6 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
old_inode->i_ctime = CURRENT_TIME; old_inode->i_ctime = CURRENT_TIME;
nilfs_delete_entry(old_de, old_page); nilfs_delete_entry(old_de, old_page);
drop_nlink(old_inode);
if (dir_de) { if (dir_de) {
nilfs_set_link(old_inode, dir_de, dir_page, new_dir); nilfs_set_link(old_inode, dir_de, dir_page, new_dir);
......
...@@ -771,7 +771,7 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -771,7 +771,7 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE, EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
dentry, inode, &security); dentry, inode, &security);
if (retval) { if (retval) {
dir->i_nlink--; DEC_DIR_INODE_NLINK(dir)
goto out_failed; goto out_failed;
} }
......
...@@ -245,7 +245,6 @@ static int sysv_rename(struct inode * old_dir, struct dentry * old_dentry, ...@@ -245,7 +245,6 @@ static int sysv_rename(struct inode * old_dir, struct dentry * old_dentry,
new_de = sysv_find_entry(new_dentry, &new_page); new_de = sysv_find_entry(new_dentry, &new_page);
if (!new_de) if (!new_de)
goto out_dir; goto out_dir;
inode_inc_link_count(old_inode);
sysv_set_link(new_de, new_page, old_inode); sysv_set_link(new_de, new_page, old_inode);
new_inode->i_ctime = CURRENT_TIME_SEC; new_inode->i_ctime = CURRENT_TIME_SEC;
if (dir_de) if (dir_de)
...@@ -257,18 +256,15 @@ static int sysv_rename(struct inode * old_dir, struct dentry * old_dentry, ...@@ -257,18 +256,15 @@ static int sysv_rename(struct inode * old_dir, struct dentry * old_dentry,
if (new_dir->i_nlink >= SYSV_SB(new_dir->i_sb)->s_link_max) if (new_dir->i_nlink >= SYSV_SB(new_dir->i_sb)->s_link_max)
goto out_dir; goto out_dir;
} }
inode_inc_link_count(old_inode);
err = sysv_add_link(new_dentry, old_inode); err = sysv_add_link(new_dentry, old_inode);
if (err) { if (err)
inode_dec_link_count(old_inode);
goto out_dir; goto out_dir;
}
if (dir_de) if (dir_de)
inode_inc_link_count(new_dir); inode_inc_link_count(new_dir);
} }
sysv_delete_entry(old_de, old_page); sysv_delete_entry(old_de, old_page);
inode_dec_link_count(old_inode); mark_inode_dirty(old_inode);
if (dir_de) { if (dir_de) {
sysv_set_link(dir_de, dir_page, new_dir); sysv_set_link(dir_de, dir_page, new_dir);
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <linux/crc-itu-t.h> #include <linux/crc-itu-t.h>
#include <linux/exportfs.h> #include <linux/exportfs.h>
enum { UDF_MAX_LINKS = 0xffff };
static inline int udf_match(int len1, const unsigned char *name1, int len2, static inline int udf_match(int len1, const unsigned char *name1, int len2,
const unsigned char *name2) const unsigned char *name2)
{ {
...@@ -650,7 +652,7 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -650,7 +652,7 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
struct udf_inode_info *iinfo; struct udf_inode_info *iinfo;
err = -EMLINK; err = -EMLINK;
if (dir->i_nlink >= (256 << sizeof(dir->i_nlink)) - 1) if (dir->i_nlink >= UDF_MAX_LINKS)
goto out; goto out;
err = -EIO; err = -EIO;
...@@ -1034,9 +1036,8 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir, ...@@ -1034,9 +1036,8 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
struct fileIdentDesc cfi, *fi; struct fileIdentDesc cfi, *fi;
int err; int err;
if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) { if (inode->i_nlink >= UDF_MAX_LINKS)
return -EMLINK; return -EMLINK;
}
fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi) { if (!fi) {
...@@ -1131,9 +1132,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -1131,9 +1132,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
goto end_rename; goto end_rename;
retval = -EMLINK; retval = -EMLINK;
if (!new_inode && if (!new_inode && new_dir->i_nlink >= UDF_MAX_LINKS)
new_dir->i_nlink >=
(256 << sizeof(new_dir->i_nlink)) - 1)
goto end_rename; goto end_rename;
} }
if (!nfi) { if (!nfi) {
......
...@@ -306,7 +306,6 @@ static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -306,7 +306,6 @@ static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry,
new_de = ufs_find_entry(new_dir, &new_dentry->d_name, &new_page); new_de = ufs_find_entry(new_dir, &new_dentry->d_name, &new_page);
if (!new_de) if (!new_de)
goto out_dir; goto out_dir;
inode_inc_link_count(old_inode);
ufs_set_link(new_dir, new_de, new_page, old_inode); ufs_set_link(new_dir, new_de, new_page, old_inode);
new_inode->i_ctime = CURRENT_TIME_SEC; new_inode->i_ctime = CURRENT_TIME_SEC;
if (dir_de) if (dir_de)
...@@ -318,12 +317,9 @@ static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -318,12 +317,9 @@ static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry,
if (new_dir->i_nlink >= UFS_LINK_MAX) if (new_dir->i_nlink >= UFS_LINK_MAX)
goto out_dir; goto out_dir;
} }
inode_inc_link_count(old_inode);
err = ufs_add_link(new_dentry, old_inode); err = ufs_add_link(new_dentry, old_inode);
if (err) { if (err)
inode_dec_link_count(old_inode);
goto out_dir; goto out_dir;
}
if (dir_de) if (dir_de)
inode_inc_link_count(new_dir); inode_inc_link_count(new_dir);
} }
...@@ -331,12 +327,11 @@ static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -331,12 +327,11 @@ static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry,
/* /*
* Like most other Unix systems, set the ctime for inodes on a * Like most other Unix systems, set the ctime for inodes on a
* rename. * rename.
* inode_dec_link_count() will mark the inode dirty.
*/ */
old_inode->i_ctime = CURRENT_TIME_SEC; old_inode->i_ctime = CURRENT_TIME_SEC;
ufs_delete_entry(old_dir, old_de, old_page); ufs_delete_entry(old_dir, old_de, old_page);
inode_dec_link_count(old_inode); mark_inode_dirty(old_inode);
if (dir_de) { if (dir_de) {
ufs_set_link(old_inode, dir_de, dir_page, new_dir); ufs_set_link(old_inode, dir_de, dir_page, new_dir);
......
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