]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/compress.c
New upstream release
[bcachefs-tools-debian] / libbcachefs / compress.c
index c9ca7cce55f870b0a32921ce767cf4521aab5943..a8b148ec2a2b6b8ed1f33d10ad195b72afa112e0 100644 (file)
@@ -3,7 +3,6 @@
 #include "checksum.h"
 #include "compress.h"
 #include "extents.h"
-#include "io.h"
 #include "super-io.h"
 
 #include <linux/lz4.h>
@@ -571,7 +570,6 @@ void bch2_fs_compress_exit(struct bch_fs *c)
 static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
 {
        size_t decompress_workspace_size = 0;
-       bool decompress_workspace_needed;
        ZSTD_parameters params = zstd_get_params(zstd_max_clevel(),
                                                 c->opts.encoded_extent_max);
        struct {
@@ -581,7 +579,8 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
                size_t                          decompress_workspace;
        } compression_types[] = {
                { BCH_FEATURE_lz4, BCH_COMPRESSION_TYPE_lz4,
-                       max_t(size_t, LZ4_MEM_COMPRESS, LZ4HC_MEM_COMPRESS) },
+                       max_t(size_t, LZ4_MEM_COMPRESS, LZ4HC_MEM_COMPRESS),
+                       0 },
                { BCH_FEATURE_gzip, BCH_COMPRESSION_TYPE_gzip,
                        zlib_deflate_workspacesize(MAX_WBITS, DEF_MEM_LEVEL),
                        zlib_inflate_workspacesize(), },
@@ -620,9 +619,6 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
                if (!(features & (1 << i->feature)))
                        continue;
 
-               if (i->decompress_workspace)
-                       decompress_workspace_needed = true;
-
                if (mempool_initialized(&c->compress_workspace[i->type]))
                        continue;
 
@@ -643,7 +639,8 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
 static u64 compression_opt_to_feature(unsigned v)
 {
        unsigned type = bch2_compression_decode(v).type;
-       return 1ULL << bch2_compression_opt_to_feature[type];
+
+       return BIT_ULL(bch2_compression_opt_to_feature[type]);
 }
 
 int bch2_fs_compress_init(struct bch_fs *c)
@@ -700,14 +697,32 @@ err:
        return ret;
 }
 
+void bch2_compression_opt_to_text(struct printbuf *out, u64 v)
+{
+       struct bch_compression_opt opt = bch2_compression_decode(v);
+
+       if (opt.type < BCH_COMPRESSION_OPT_NR)
+               prt_str(out, bch2_compression_opts[opt.type]);
+       else
+               prt_printf(out, "(unknown compression opt %u)", opt.type);
+       if (opt.level)
+               prt_printf(out, ":%u", opt.level);
+}
+
 void bch2_opt_compression_to_text(struct printbuf *out,
                                  struct bch_fs *c,
                                  struct bch_sb *sb,
                                  u64 v)
 {
-       struct bch_compression_opt opt = bch2_compression_decode(v);
+       return bch2_compression_opt_to_text(out, v);
+}
 
-       prt_str(out, bch2_compression_opts[opt.type]);
-       if (opt.level)
-               prt_printf(out, ":%u", opt.level);
+int bch2_opt_compression_validate(u64 v, struct printbuf *err)
+{
+       if (!bch2_compression_opt_valid(v)) {
+               prt_printf(err, "invalid compression opt %llu", v);
+               return -BCH_ERR_invalid_sb_opt_compression;
+       }
+
+       return 0;
 }