From: Hengyu Liang <hengyul@cs.unc.edu>
To: David Sterba <dsterba@suse.com>
Cc: Chris Mason <mason@kernel.org>, Filipe Manana <fdmanana@suse.com>,
Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH] btrfs: fix chattr failing on nodatasum files that have the compress flag
Date: Sat, 10 Oct 2026 06:54:25 -0400 [thread overview]
Message-ID: <20261010105425.165104-1-hengyul@cs.unc.edu> (raw)
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.
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.
+ */
+ if (comp && btrfs_inode_can_compress(inode)) {
ret = btrfs_set_prop(trans, inode, "btrfs.compression",
comp, strlen(comp), 0);
if (ret)
--
2.53.0
next reply other threads:[~2026-10-10 10:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 10:54 Hengyu Liang [this message]
2026-10-10 21:17 ` Qu Wenruo
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=20261010105425.165104-1-hengyul@cs.unc.edu \
--to=hengyul@cs.unc.edu \
--cc=dsterba@suse.com \
--cc=fdmanana@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=stable@vger.kernel.org \
--cc=wqu@suse.com \
/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®