]> git.hungrycats.org Git - linux/commitdiff
btrfs: add btrfs_compress_typelevel2str() helper
authorkoraynilay <koray.fra@gmail.com>
Tue, 3 Nov 2026 19:47:33 +0000 (20:47 +0100)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 3 Nov 2026 23:39:29 +0000 (18:39 -0500)
Add the type:level equivalent of btrfs_compress_type2str() and use it
in prop_compression_extract() .

Signed-off-by: koraynilay <koray.fra@gmail.com>
Link: https://lore.kernel.org/r/20261103194734.598182-6-koray.fra@gmail.com
fs/btrfs/compression.c
fs/btrfs/compression.h
fs/btrfs/props.c

index b1f8323fffe7d00ec10017dbb0fa388b7e7f7a33..068c24576b71ec5d810aebd953f01db834690cbd 100644 (file)
@@ -53,6 +53,26 @@ const char* btrfs_compress_type2str(enum btrfs_compression_type type)
        return NULL;
 }
 
+const char* btrfs_compress_typelevel2str(enum btrfs_compression_type type,
+                                        int level, char *buf, size_t len)
+{
+       switch (type) {
+       case BTRFS_COMPRESS_ZLIB:
+       case BTRFS_COMPRESS_LZO:
+       case BTRFS_COMPRESS_ZSTD:
+               if (level) {
+                       snprintf(buf, len, "%s:%d",
+                                btrfs_compress_type2str(type), level);
+                       return buf;
+               }
+               return btrfs_compress_type2str(type);
+       default:
+               break;
+       }
+
+       return NULL;
+}
+
 static inline struct compressed_bio *to_compressed_bio(struct btrfs_bio *bbio)
 {
        return container_of(bbio, struct compressed_bio, bbio);
index c63bed9f4152ed673fd218b76c0efa2ee897fb82..b9cc1bdd3ccbf47e317a40516601cf0eab335764 100644 (file)
@@ -132,6 +132,8 @@ extern const struct btrfs_compress_levels btrfs_lzo_compress;
 extern const struct btrfs_compress_levels btrfs_zstd_compress;
 
 const char* btrfs_compress_type2str(enum btrfs_compression_type type);
+const char* btrfs_compress_typelevel2str(enum btrfs_compression_type type,
+                                        int level, char *buf, size_t len);
 bool btrfs_compress_is_valid_type(const char *str);
 
 int btrfs_compress_heuristic(struct btrfs_inode *inode, u64 start, u64 end);
index 9427be2f28e0286a76d19322cba9f977ca59d916..3edda1f11a741a6f2e58773486107662a98f2e76 100644 (file)
@@ -414,22 +414,9 @@ static bool prop_compression_ignore(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;
-       }
-
-       return NULL;
+       return btrfs_compress_typelevel2str(inode->prop_compress,
+                                           inode->prop_compress_level,
+                                           buf, len);
 }
 
 static struct prop_handler prop_handlers[] = {