f2fs: clean up f2fs_balance_fs
[linux-2.6-block.git] / fs / f2fs / namei.c
index 2c32110f9fc082408b318cac2142602ab7888a9e..53d6227f5581f4434dc2b14b707e7234adb74bbe 100644 (file)
@@ -60,7 +60,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
        if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode))
                f2fs_set_encrypted_inode(inode);
 
-       if (f2fs_may_inline_data(inode))
+       if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode))
                set_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
        if (f2fs_may_inline_dentry(inode))
                set_inode_flag(F2FS_I(inode), FI_INLINE_DENTRY);
@@ -128,8 +128,6 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
        nid_t ino = 0;
        int err;
 
-       f2fs_balance_fs(sbi);
-
        inode = f2fs_new_inode(dir, mode);
        if (IS_ERR(inode))
                return PTR_ERR(inode);
@@ -142,6 +140,8 @@ 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;
 
+       f2fs_balance_fs(sbi, true);
+
        f2fs_lock_op(sbi);
        err = f2fs_add_link(dentry, inode);
        if (err)
@@ -172,7 +172,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
                !f2fs_is_child_context_consistent_with_parent(dir, inode))
                return -EPERM;
 
-       f2fs_balance_fs(sbi);
+       f2fs_balance_fs(sbi, true);
 
        inode->i_ctime = CURRENT_TIME;
        ihold(inode);
@@ -214,6 +214,15 @@ static int __recover_dot_dentries(struct inode *dir, nid_t pino)
        struct page *page;
        int err = 0;
 
+       if (f2fs_readonly(sbi->sb)) {
+               f2fs_msg(sbi->sb, KERN_INFO,
+                       "skip recovering inline_dots inode (ino:%lu, pino:%u) "
+                       "in readonly mountpoint", dir->i_ino, pino);
+               return 0;
+       }
+
+       f2fs_balance_fs(sbi, true);
+
        f2fs_lock_op(sbi);
 
        de = f2fs_find_entry(dir, &dot, &page);
@@ -288,12 +297,13 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
        int err = -ENOENT;
 
        trace_f2fs_unlink_enter(dir, dentry);
-       f2fs_balance_fs(sbi);
 
        de = f2fs_find_entry(dir, &dentry->d_name, &page);
        if (!de)
                goto fail;
 
+       f2fs_balance_fs(sbi, true);
+
        f2fs_lock_op(sbi);
        err = acquire_orphan_inode(sbi);
        if (err) {
@@ -341,8 +351,6 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
        if (len > dir->i_sb->s_blocksize)
                return -ENAMETOOLONG;
 
-       f2fs_balance_fs(sbi);
-
        inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
        if (IS_ERR(inode))
                return PTR_ERR(inode);
@@ -353,6 +361,8 @@ 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;
 
+       f2fs_balance_fs(sbi, true);
+
        f2fs_lock_op(sbi);
        err = f2fs_add_link(dentry, inode);
        if (err)
@@ -433,8 +443,6 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
        struct inode *inode;
        int err;
 
-       f2fs_balance_fs(sbi);
-
        inode = f2fs_new_inode(dir, S_IFDIR | mode);
        if (IS_ERR(inode))
                return PTR_ERR(inode);
@@ -444,6 +452,8 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
        inode->i_mapping->a_ops = &f2fs_dblock_aops;
        mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO);
 
+       f2fs_balance_fs(sbi, true);
+
        set_inode_flag(F2FS_I(inode), FI_INC_LINK);
        f2fs_lock_op(sbi);
        err = f2fs_add_link(dentry, inode);
@@ -481,8 +491,6 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
        struct inode *inode;
        int err = 0;
 
-       f2fs_balance_fs(sbi);
-
        inode = f2fs_new_inode(dir, mode);
        if (IS_ERR(inode))
                return PTR_ERR(inode);
@@ -490,6 +498,8 @@ 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;
 
+       f2fs_balance_fs(sbi, true);
+
        f2fs_lock_op(sbi);
        err = f2fs_add_link(dentry, inode);
        if (err)
@@ -516,9 +526,6 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
        struct inode *inode;
        int err;
 
-       if (!whiteout)
-               f2fs_balance_fs(sbi);
-
        inode = f2fs_new_inode(dir, mode);
        if (IS_ERR(inode))
                return PTR_ERR(inode);
@@ -532,6 +539,8 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
                inode->i_mapping->a_ops = &f2fs_dblock_aops;
        }
 
+       f2fs_balance_fs(sbi, true);
+
        f2fs_lock_op(sbi);
        err = acquire_orphan_inode(sbi);
        if (err)
@@ -604,8 +613,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
                goto out;
        }
 
-       f2fs_balance_fs(sbi);
-
        old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
        if (!old_entry)
                goto out;
@@ -635,6 +642,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
                if (!new_entry)
                        goto out_whiteout;
 
+               f2fs_balance_fs(sbi, true);
+
                f2fs_lock_op(sbi);
 
                err = acquire_orphan_inode(sbi);
@@ -666,6 +675,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
                update_inode_page(old_inode);
                update_inode_page(new_inode);
        } else {
+               f2fs_balance_fs(sbi, true);
+
                f2fs_lock_op(sbi);
 
                err = f2fs_add_link(new_dentry, old_inode);
@@ -763,8 +774,6 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
                                                                new_inode)))
                return -EPERM;
 
-       f2fs_balance_fs(sbi);
-
        old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
        if (!old_entry)
                goto out;
@@ -807,6 +816,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
                        goto out_new_dir;
        }
 
+       f2fs_balance_fs(sbi, true);
+
        f2fs_lock_op(sbi);
 
        err = update_dent_inode(old_inode, new_inode, &new_dentry->d_name);
@@ -927,7 +938,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
 {
        struct page *cpage = NULL;
        char *caddr, *paddr = NULL;
-       struct f2fs_str cstr;
+       struct f2fs_str cstr = FSTR_INIT(NULL, 0);
        struct f2fs_str pstr = FSTR_INIT(NULL, 0);
        struct inode *inode = d_inode(dentry);
        struct f2fs_encrypted_symlink_data *sd;
@@ -948,6 +959,12 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
        /* Symlink is encrypted */
        sd = (struct f2fs_encrypted_symlink_data *)caddr;
        cstr.len = le16_to_cpu(sd->len);
+
+       /* this is broken symlink case */
+       if (unlikely(cstr.len == 0)) {
+               res = -ENOENT;
+               goto errout;
+       }
        cstr.name = kmalloc(cstr.len, GFP_NOFS);
        if (!cstr.name) {
                res = -ENOMEM;
@@ -956,7 +973,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
        memcpy(cstr.name, sd->encrypted_path, cstr.len);
 
        /* this is broken symlink case */
-       if (cstr.name[0] == 0 && cstr.len == 0) {
+       if (unlikely(cstr.name[0] == 0)) {
                res = -ENOENT;
                goto errout;
        }
@@ -999,10 +1016,12 @@ const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
        .put_link       = kfree_put_link,
        .getattr        = f2fs_getattr,
        .setattr        = f2fs_setattr,
+#ifdef CONFIG_F2FS_FS_XATTR
        .setxattr       = generic_setxattr,
        .getxattr       = generic_getxattr,
        .listxattr      = f2fs_listxattr,
        .removexattr    = generic_removexattr,
+#endif
 };
 #endif