]> git.hungrycats.org Git - linux/commitdiff
btrfs: support inheritance for per-inode compression levels
authorkoraynilay <koray.fra@gmail.com>
Tue, 3 Nov 2026 19:47:32 +0000 (20:47 +0100)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 3 Nov 2026 23:39:28 +0000 (18:39 -0500)
Change prop_handler's extract() signature to take an output buffer and
its length. This allows for the algo:level string to be generated
dynamically, but now the caller is in charge of managing that buffer
memory. Before this patch prop_compression_extract() would return only
the address of statically compiled string without being able to add the
level, now it concatenates the level to that statically compiled string.

This signature change is fine because the only currently supported prop
is compression, so there is only 1 extract() function.

Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.5
Signed-off-by: koraynilay <koray.fra@gmail.com>
Link: https://lore.kernel.org/r/20261103194734.598182-5-koray.fra@gmail.com
fs/btrfs/props.c

index effc2daa2e3dfdaa3652845255a01ea44473cfbd..9427be2f28e0286a76d19322cba9f977ca59d916 100644 (file)
@@ -36,7 +36,7 @@ struct prop_handler {
        int (*validate)(const struct btrfs_inode *inode, const char *value,
                        size_t len);
        int (*apply)(struct btrfs_inode *inode, const char *value, size_t len);
-       const char *(*extract)(const struct btrfs_inode *inode);
+       const char *(*extract)(const struct btrfs_inode *inode, char *buf, size_t len);
        bool (*ignore)(const struct btrfs_inode *inode);
        int inheritable;
 };
@@ -411,12 +411,19 @@ static bool prop_compression_ignore(const struct btrfs_inode *inode)
        return false;
 }
 
-static const char *prop_compression_extract(const struct btrfs_inode *inode)
+static const char *prop_compression_extract(const struct btrfs_inode *inode,
+                                           char *buf, size_t len)
 {
        switch (inode->prop_compress) {
        case BTRFS_COMPRESS_ZLIB:
        case BTRFS_COMPRESS_LZO:
        case BTRFS_COMPRESS_ZSTD:
+               if (inode->prop_compress_level) {
+                       snprintf(buf, len, "%s:%d",
+                                btrfs_compress_type2str(inode->prop_compress),
+                                inode->prop_compress_level);
+                       return buf;
+               }
                return btrfs_compress_type2str(inode->prop_compress);
        default:
                break;
@@ -453,6 +460,7 @@ int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans,
                const struct prop_handler *h = &prop_handlers[i];
                const char *value;
                u64 num_bytes = 0;
+               char buf[BTRFS_COMPRESS_PROP_MAX_LEN];
 
                if (!h->inheritable)
                        continue;
@@ -460,7 +468,7 @@ int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans,
                if (h->ignore(inode))
                        continue;
 
-               value = h->extract(parent);
+               value = h->extract(parent, buf, sizeof(buf));
                if (!value)
                        continue;