]> git.hungrycats.org Git - linux/commitdiff
btrfs: allow NODATACOW | NOCOMPRESS
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 17 Aug 2025 20:57:07 +0000 (16:57 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 3 Nov 2026 23:40:18 +0000 (18:40 -0500)
Commit f37c563bab42 ("btrfs: add missing check for nocow and compression
inode flags") added conflict checks for certain inode flag combinations,
and commit 0e852ab8974c ("btrfs: do not allow compression on nodatacow
files") extended the same logic to xattrs.

Both commits also forbade the combination of FS_NOCOW_FL (NODATACOW)
and FS_NOCOMP_FL (NOCOMPRESS).  This restriction is undocumented, has
no technical basis, and provides no benefit.  NODATACOW files cannot be
compressed in any case, so the NOCOMPRESS bit is a no-op:  behavior is
the same whether the flag is present or not.

Forcing an unnecessary conflict makes inode flags harder to use.
Portable applications may inherit COMPRESS, NOCOMPRESS, or NODATACOW bits
from parent directories and combine them with unrelated flags such as
IMMUTABLE or NOATIME.  Rejecting otherwise valid flag sets with EINVAL
creates surprises for applications that do not know about btrfs-specific
interactions and only touch the flags they care about.

Fix by permitting the combination of NODATACOW and NOCOMPRESS, both via
FS_IOC_SETFLAGS and by setting btrfs.compression to "no"/"none" through
xattrs.

Fixes: f37c563bab42 ("btrfs: add missing check for nocow and compression inode flags")
Fixes: 0e852ab8974c ("btrfs: do not allow compression on nodatacow files")
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/ioctl.c
fs/btrfs/props.c

index 5b597ec81db9d03ce1424c3834c8f4f5fb9100c4..5d35b2072886fe9de0fd45ca3160c0665692a1ad 100644 (file)
@@ -367,9 +367,9 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
                 * are not changed.
                 */
                if ((inode_flags & BTRFS_INODE_NODATACOW) &&
-                   (fsflags & (FS_COMPR_FL | FS_NOCOMP_FL))) {
-                       if ((old_fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)) !=
-                           (fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)))
+                   (fsflags & FS_COMPR_FL)) {
+                       if ((old_fsflags & (FS_NOCOW_FL | FS_COMPR_FL)) !=
+                           (fsflags & (FS_NOCOW_FL | FS_COMPR_FL)))
                                return -EINVAL;
                }
        } else {
index 05e594ce613b0562cbd6df944f45f66446849174..adc4dc540840ceb9f0f11a962b7d91384ef3ba96 100644 (file)
@@ -297,9 +297,6 @@ static int prop_compression_validate(const struct btrfs_inode *inode,
 {
        char value_str[BTRFS_COMPRESS_PROP_MAX_LEN];
 
-       if (!btrfs_inode_can_compress(inode))
-               return -EINVAL;
-
        if (!value)
                return 0;
 
@@ -308,8 +305,11 @@ static int prop_compression_validate(const struct btrfs_inode *inode,
 
        memcpy(value_str, value, len);
        value_str[len] = '\0';
-       if (btrfs_compress_is_valid_type(value_str))
+       if (btrfs_compress_is_valid_type(value_str)) {
+               if (!btrfs_inode_can_compress(inode))
+                       return -EINVAL;
                return 0;
+       }
 
        if ((len == 2 && strncmp("no", value, 2) == 0) ||
            (len == 4 && strncmp("none", value, 4) == 0))