diff options
Diffstat (limited to 'fs/f2fs/namei.c')
| -rw-r--r-- | fs/f2fs/namei.c | 80 | 
1 files changed, 42 insertions, 38 deletions
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 2a5359c990f..a6bdddc33ce 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -27,32 +27,23 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)  	nid_t ino;  	struct inode *inode;  	bool nid_free = false; -	int err, ilock; +	int err;  	inode = new_inode(sb);  	if (!inode)  		return ERR_PTR(-ENOMEM); -	ilock = mutex_lock_op(sbi); +	f2fs_lock_op(sbi);  	if (!alloc_nid(sbi, &ino)) { -		mutex_unlock_op(sbi, ilock); +		f2fs_unlock_op(sbi);  		err = -ENOSPC;  		goto fail;  	} -	mutex_unlock_op(sbi, ilock); +	f2fs_unlock_op(sbi); -	inode->i_uid = current_fsuid(); - -	if (dir->i_mode & S_ISGID) { -		inode->i_gid = dir->i_gid; -		if (S_ISDIR(mode)) -			mode |= S_ISGID; -	} else { -		inode->i_gid = current_fsgid(); -	} +	inode_init_owner(inode, dir, mode);  	inode->i_ino = ino; -	inode->i_mode = mode;  	inode->i_blocks = 0;  	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;  	inode->i_generation = sbi->s_next_generation++; @@ -115,7 +106,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,  	struct f2fs_sb_info *sbi = F2FS_SB(sb);  	struct inode *inode;  	nid_t ino = 0; -	int err, ilock; +	int err;  	f2fs_balance_fs(sbi); @@ -131,9 +122,9 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,  	inode->i_mapping->a_ops = &f2fs_dblock_aops;  	ino = inode->i_ino; -	ilock = mutex_lock_op(sbi); +	f2fs_lock_op(sbi);  	err = f2fs_add_link(dentry, inode); -	mutex_unlock_op(sbi, ilock); +	f2fs_unlock_op(sbi);  	if (err)  		goto out; @@ -157,7 +148,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,  	struct inode *inode = old_dentry->d_inode;  	struct super_block *sb = dir->i_sb;  	struct f2fs_sb_info *sbi = F2FS_SB(sb); -	int err, ilock; +	int err;  	f2fs_balance_fs(sbi); @@ -165,9 +156,9 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,  	ihold(inode);  	set_inode_flag(F2FS_I(inode), FI_INC_LINK); -	ilock = mutex_lock_op(sbi); +	f2fs_lock_op(sbi);  	err = f2fs_add_link(dentry, inode); -	mutex_unlock_op(sbi, ilock); +	f2fs_unlock_op(sbi);  	if (err)  		goto out; @@ -207,6 +198,8 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,  		inode = f2fs_iget(dir->i_sb, ino);  		if (IS_ERR(inode))  			return ERR_CAST(inode); + +		stat_inc_inline_inode(inode);  	}  	return d_splice_alias(inode, dentry); @@ -220,7 +213,6 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)  	struct f2fs_dir_entry *de;  	struct page *page;  	int err = -ENOENT; -	int ilock;  	trace_f2fs_unlink_enter(dir, dentry);  	f2fs_balance_fs(sbi); @@ -229,16 +221,16 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)  	if (!de)  		goto fail; +	f2fs_lock_op(sbi);  	err = acquire_orphan_inode(sbi);  	if (err) { +		f2fs_unlock_op(sbi);  		kunmap(page);  		f2fs_put_page(page, 0);  		goto fail;  	} - -	ilock = mutex_lock_op(sbi);  	f2fs_delete_entry(de, page, inode); -	mutex_unlock_op(sbi, ilock); +	f2fs_unlock_op(sbi);  	/* In order to evict this inode,  we set it dirty */  	mark_inode_dirty(inode); @@ -254,7 +246,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,  	struct f2fs_sb_info *sbi = F2FS_SB(sb);  	struct inode *inode;  	size_t symlen = strlen(symname) + 1; -	int err, ilock; +	int err;  	f2fs_balance_fs(sbi); @@ -265,9 +257,9 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,  	inode->i_op = &f2fs_symlink_inode_operations;  	inode->i_mapping->a_ops = &f2fs_dblock_aops; -	ilock = mutex_lock_op(sbi); +	f2fs_lock_op(sbi);  	err = f2fs_add_link(dentry, inode); -	mutex_unlock_op(sbi, ilock); +	f2fs_unlock_op(sbi);  	if (err)  		goto out; @@ -290,7 +282,7 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)  {  	struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);  	struct inode *inode; -	int err, ilock; +	int err;  	f2fs_balance_fs(sbi); @@ -304,9 +296,9 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)  	mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_ZERO);  	set_inode_flag(F2FS_I(inode), FI_INC_LINK); -	ilock = mutex_lock_op(sbi); +	f2fs_lock_op(sbi);  	err = f2fs_add_link(dentry, inode); -	mutex_unlock_op(sbi, ilock); +	f2fs_unlock_op(sbi);  	if (err)  		goto out_fail; @@ -342,7 +334,6 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,  	struct f2fs_sb_info *sbi = F2FS_SB(sb);  	struct inode *inode;  	int err = 0; -	int ilock;  	if (!new_valid_dev(rdev))  		return -EINVAL; @@ -356,9 +347,9 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,  	init_special_inode(inode, inode->i_mode, rdev);  	inode->i_op = &f2fs_special_inode_operations; -	ilock = mutex_lock_op(sbi); +	f2fs_lock_op(sbi);  	err = f2fs_add_link(dentry, inode); -	mutex_unlock_op(sbi, ilock); +	f2fs_unlock_op(sbi);  	if (err)  		goto out; @@ -387,7 +378,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,  	struct f2fs_dir_entry *old_dir_entry = NULL;  	struct f2fs_dir_entry *old_entry;  	struct f2fs_dir_entry *new_entry; -	int err = -ENOENT, ilock = -1; +	int err = -ENOENT;  	f2fs_balance_fs(sbi); @@ -402,7 +393,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,  			goto out_old;  	} -	ilock = mutex_lock_op(sbi); +	f2fs_lock_op(sbi);  	if (new_inode) { @@ -428,9 +419,13 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,  		f2fs_set_link(new_dir, new_entry, new_page, old_inode);  		new_inode->i_ctime = CURRENT_TIME; +		down_write(&F2FS_I(new_inode)->i_sem);  		if (old_dir_entry)  			drop_nlink(new_inode);  		drop_nlink(new_inode); +		up_write(&F2FS_I(new_inode)->i_sem); + +		mark_inode_dirty(new_inode);  		if (!new_inode->i_nlink)  			add_orphan_inode(sbi, new_inode->i_ino); @@ -450,6 +445,10 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,  		}  	} +	down_write(&F2FS_I(old_inode)->i_sem); +	file_lost_pino(old_inode); +	up_write(&F2FS_I(old_inode)->i_sem); +  	old_inode->i_ctime = CURRENT_TIME;  	mark_inode_dirty(old_inode); @@ -459,25 +458,28 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,  		if (old_dir != new_dir) {  			f2fs_set_link(old_inode, old_dir_entry,  						old_dir_page, new_dir); +			update_inode_page(old_inode);  		} else {  			kunmap(old_dir_page);  			f2fs_put_page(old_dir_page, 0);  		}  		drop_nlink(old_dir); +		mark_inode_dirty(old_dir);  		update_inode_page(old_dir);  	} -	mutex_unlock_op(sbi, ilock); +	f2fs_unlock_op(sbi);  	return 0;  put_out_dir: -	f2fs_put_page(new_page, 1); +	kunmap(new_page); +	f2fs_put_page(new_page, 0);  out_dir:  	if (old_dir_entry) {  		kunmap(old_dir_page);  		f2fs_put_page(old_dir_page, 0);  	} -	mutex_unlock_op(sbi, ilock); +	f2fs_unlock_op(sbi);  out_old:  	kunmap(old_page);  	f2fs_put_page(old_page, 0); @@ -498,6 +500,7 @@ const struct inode_operations f2fs_dir_inode_operations = {  	.getattr	= f2fs_getattr,  	.setattr	= f2fs_setattr,  	.get_acl	= f2fs_get_acl, +	.set_acl	= f2fs_set_acl,  #ifdef CONFIG_F2FS_FS_XATTR  	.setxattr	= generic_setxattr,  	.getxattr	= generic_getxattr, @@ -524,6 +527,7 @@ const struct inode_operations f2fs_special_inode_operations = {  	.getattr	= f2fs_getattr,  	.setattr        = f2fs_setattr,  	.get_acl	= f2fs_get_acl, +	.set_acl	= f2fs_set_acl,  #ifdef CONFIG_F2FS_FS_XATTR  	.setxattr       = generic_setxattr,  	.getxattr       = generic_getxattr,  | 
