Btrfs: don't add a NULL extended attribute
authorLiu Bo <bo.li.liu@oracle.com>
Wed, 28 Nov 2012 10:43:12 +0000 (10:43 +0000)
committerChris Mason <chris.mason@fusionio.com>
Mon, 17 Dec 2012 01:46:15 +0000 (20:46 -0500)
Passing a null extended attribute value means to remove the attribute,
but we don't have to add a new NULL extended attribute.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
fs/btrfs/xattr.c

index e9d384055494a6f17ddf9ee99f31766926a8c4dd..aef6bb3c5f5c82a77a1d5eeaef0d65a6661d7367 100644 (file)
@@ -122,6 +122,16 @@ static int do_setxattr(struct btrfs_trans_handle *trans,
                 */
                if (!value)
                        goto out;
+       } else {
+               di = btrfs_lookup_xattr(NULL, root, path, btrfs_ino(inode),
+                                       name, name_len, 0);
+               if (IS_ERR(di)) {
+                       ret = PTR_ERR(di);
+                       goto out;
+               }
+               if (!di && !value)
+                       goto out;
+               btrfs_release_path(path);
        }
 
 again: