]> git.hungrycats.org Git - linux/commit
btrfs: fix chattr failing on nodatasum files that have the compress flag 7.3/topics/stable-cherry-picks
authorHengyu Liang <hengyul@cs.unc.edu>
Sun, 11 Oct 2026 15:58:15 +0000 (11:58 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 10 Nov 2026 06:32:34 +0000 (01:32 -0500)
commit81f7a02e5cd6834427d9acd494f9b5bcf94fdb26
treebb1520694ef8e8846620d6e4eec2cf3f2b962c37
parentd50d994bffa3c7c6db2d8bc4c5f0c55e3f46b0cd
btrfs: fix chattr failing on nodatasum files that have the compress flag

Commit cf1afec09e9f ("btrfs: validate properties before setting them")
made btrfs_set_prop() validate a property before setting it. For the
compression property, the validation fails with -EINVAL when the inode
has NODATASUM.

However, chattr writes back all the flags it read from the file, and
btrfs_fileattr_set() sets the compression property whenever the new
flags include FS_COMPR_FL, even when the compression flags do not
change. A file created on a filesystem mounted with nodatasum has
NODATASUM and still inherits the compress flag from its directory. As
of now, chattr fails on such a file when it changes any other flag.

The issue can be reproduced with:

    mkfs.btrfs -f /dev/sdb
    mount -o nodatasum /dev/sdb /mnt
    mkdir /mnt/dir
    chattr +c /mnt/dir
    touch /mnt/dir/file
    chattr +A /mnt/dir/file

Before commit cf1afec09e9f ("btrfs: validate properties before setting
them"), the last command succeeds.

After that commit, it fails with EINVAL.

This patch will make btrfs_fileattr_set() leave the compression flags
and the compression property alone when the call changes neither
FS_COMPR_FL nor FS_NOCOMP_FL.

Fixes: cf1afec09e9f ("btrfs: validate properties before setting them")
CC: stable@vger.kernel.org # 7.2+
Suggested-by: Qu Wenruo <wqu@suse.com>
Assisted-by: LLM
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
(cherry picked from commit 16b8f07d1ed50d4a8da468b56484873784dd8f4a)
fs/btrfs/ioctl.c