Merge tag 'rdma-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[firefly-linux-kernel-4.4.55.git] / fs / f2fs / xattr.c
index 8038c049650473bd260d50006ca75175ec90fa62..0b02dce313565d5f287b96f464efca6cad0ea2cd 100644 (file)
@@ -307,27 +307,30 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name,
        int error, found, free, newsize;
        size_t name_len;
        char *pval;
+       int ilock;
 
        if (name == NULL)
                return -EINVAL;
-       name_len = strlen(name);
 
        if (value == NULL)
                value_len = 0;
 
-       if (name_len > 255 || value_len > MAX_VALUE_LEN)
+       name_len = strlen(name);
+
+       if (name_len > F2FS_NAME_LEN || value_len > MAX_VALUE_LEN)
                return -ERANGE;
 
        f2fs_balance_fs(sbi);
 
-       mutex_lock_op(sbi, NODE_NEW);
+       ilock = mutex_lock_op(sbi);
+
        if (!fi->i_xattr_nid) {
                /* Allocate new attribute block */
                struct dnode_of_data dn;
 
                if (!alloc_nid(sbi, &fi->i_xattr_nid)) {
-                       mutex_unlock_op(sbi, NODE_NEW);
-                       return -ENOSPC;
+                       error = -ENOSPC;
+                       goto exit;
                }
                set_new_dnode(&dn, inode, NULL, NULL, fi->i_xattr_nid);
                mark_inode_dirty(inode);
@@ -336,8 +339,8 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name,
                if (IS_ERR(page)) {
                        alloc_nid_failed(sbi, fi->i_xattr_nid);
                        fi->i_xattr_nid = 0;
-                       mutex_unlock_op(sbi, NODE_NEW);
-                       return PTR_ERR(page);
+                       error = PTR_ERR(page);
+                       goto exit;
                }
 
                alloc_nid_done(sbi, fi->i_xattr_nid);
@@ -349,8 +352,8 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name,
                /* The inode already has an extended attribute block. */
                page = get_node_page(sbi, fi->i_xattr_nid);
                if (IS_ERR(page)) {
-                       mutex_unlock_op(sbi, NODE_NEW);
-                       return PTR_ERR(page);
+                       error = PTR_ERR(page);
+                       goto exit;
                }
 
                base_addr = page_address(page);
@@ -432,12 +435,13 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name,
                inode->i_ctime = CURRENT_TIME;
                clear_inode_flag(fi, FI_ACL_MODE);
        }
-       f2fs_write_inode(inode, NULL);
-       mutex_unlock_op(sbi, NODE_NEW);
+       update_inode_page(inode);
+       mutex_unlock_op(sbi, ilock);
 
        return 0;
 cleanup:
        f2fs_put_page(page, 1);
-       mutex_unlock_op(sbi, NODE_NEW);
+exit:
+       mutex_unlock_op(sbi, ilock);
        return error;
 }