From: Qu Wenruo <wqu@suse.com>
To: Hengyu Liang <hengyul@cs.unc.edu>, David Sterba <dsterba@suse.com>
Cc: Chris Mason <mason@kernel.org>, Filipe Manana <fdmanana@suse.com>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] btrfs: fix chattr failing on nodatasum files that have the compress flag
Date: Sun, 11 Oct 2026 07:47:39 +1030 [thread overview]
Message-ID: <41987a33-f2dd-4ffe-b35f-d669d36dbcfe@suse.com> (raw)
In-Reply-To: <20261010105425.165104-1-hengyul@cs.unc.edu>
在 2026/10/10 21:24, Hengyu Liang 写道:
> 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, a file created on a filesystem mounted with nodatasum has
> NODATASUM and still inherits the compress flag from its directory, and
> btrfs_fileattr_set() sets the compression property whenever the new
> flags include FS_COMPR_FL. As of now, chattr fails on such a file, even
> when it only changes another 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.
Explain the reason why it fails.
>
> This patch will make btrfs_fileattr_set() set the compression property
> only when the inode can be compressed.
>
> Fixes: cf1afec09e9f ("btrfs: validate properties before setting them")
> Cc: stable@vger.kernel.org # 7.2+
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
> ---
> fs/btrfs/ioctl.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 52aab510aea0..347509043f2e 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -421,7 +421,12 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
> if (IS_ERR(trans))
> return PTR_ERR(trans);
>
> - if (comp) {
> + /*
> + * An inode with NODATASUM can not be compressed but can still have the
> + * compress flag, inherited from its parent directory. Setting the
> + * property fails validation for such an inode, so leave it unset.
> + */
This is very LLM-like, and very LLM's objective-oriented behavior.
Disclose it first.
Secondly it just slightly do nothing, which is not the expected behavior.
Furthermore, this introduced another layer of exceptions.
For regular mount options, -o nodatasum,compress, the later compress
will override the nodatasum.
So when setting compress in the first place, the NODATASUM/NODATACOW
flag should be cleared.
> + if (comp && btrfs_inode_can_compress(inode)) {
> ret = btrfs_set_prop(trans, inode, "btrfs.compression",
> comp, strlen(comp), 0);
> if (ret)
next prev parent reply other threads:[~2026-10-10 21:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 10:54 Hengyu Liang
2026-10-10 21:17 ` Qu Wenruo [this message]
2026-10-10 21:20 ` Qu Wenruo
2026-10-11 3:47 ` Hengyu Liang
2026-10-11 5:53 ` Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=41987a33-f2dd-4ffe-b35f-d669d36dbcfe@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.com \
--cc=fdmanana@suse.com \
--cc=hengyul@cs.unc.edu \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®