From fae7ff46beb2445153ba500c134dba606b81ea20 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 31 Oct 2017 17:24:26 +0100 Subject: [PATCH] btrfs: compression: add helper for type to string conversion commit e128f9c3f7242318e1c76d204c7ae32bc878b8c7 upstream. There are several places opencoding this conversion, add a helper now that we have 3 compression algorithms. Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/compression.c | 15 +++++++++++++++ fs/btrfs/compression.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 280384bf34f1..d7aa96e1fc36 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -43,6 +43,21 @@ #include "extent_io.h" #include "extent_map.h" +static const char* const btrfs_compress_types[] = { "", "zlib", "lzo", "zstd" }; + +const char* btrfs_compress_type2str(enum btrfs_compression_type type) +{ + switch (type) { + case BTRFS_COMPRESS_ZLIB: + case BTRFS_COMPRESS_LZO: + case BTRFS_COMPRESS_ZSTD: + case BTRFS_COMPRESS_NONE: + return btrfs_compress_types[type]; + } + + return NULL; +} + static int btrfs_decompress_bio(struct compressed_bio *cb); static inline int compressed_bio_size(struct btrfs_fs_info *fs_info, diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index d2781ff8f994..adb704757955 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -130,6 +130,8 @@ extern const struct btrfs_compress_op btrfs_zlib_compress; extern const struct btrfs_compress_op btrfs_lzo_compress; extern const struct btrfs_compress_op btrfs_zstd_compress; +const char* btrfs_compress_type2str(enum btrfs_compression_type type); + int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end); #endif -- 2.20.1