]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/compress.c
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / libbcachefs / compress.c
index 560214c15da3c99d98be131299e6f5c632abf166..1410365a889156450c78da9165bdb146872370ed 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>
@@ -240,7 +239,8 @@ int bch2_bio_uncompress_inplace(struct bch_fs *c, struct bio *bio,
        data = __bounce_alloc(c, dst_len, WRITE);
 
        if (__bio_uncompress(c, bio, data.b, *crc)) {
-               bch_err(c, "error rewriting existing data: decompression error");
+               if (!c->opts.no_data_io)
+                       bch_err(c, "error rewriting existing data: decompression error");
                bio_unmap_or_unbounce(c, data);
                return -EIO;
        }
@@ -354,8 +354,7 @@ static int attempt_compress(struct bch_fs *c,
                 */
                unsigned level = min((compression.level * 3) / 2, zstd_max_clevel());
                ZSTD_parameters params = zstd_get_params(level, c->opts.encoded_extent_max);
-               ZSTD_CCtx *ctx = zstd_init_cctx(workspace,
-                       zstd_cctx_workspace_bound(&params.cParams));
+               ZSTD_CCtx *ctx = zstd_init_cctx(workspace, c->zstd_workspace_size);
 
                /*
                 * ZSTD requires that when we decompress we pass in the exact
@@ -371,7 +370,7 @@ static int attempt_compress(struct bch_fs *c,
                size_t len = zstd_compress_cctx(ctx,
                                dst + 4,        dst_len - 4 - 7,
                                src,            src_len,
-                               &c->zstd_params);
+                               &params);
                if (zstd_is_error(len))
                        return 0;
 
@@ -570,9 +569,11 @@ 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);
+
+       c->zstd_workspace_size = zstd_cctx_workspace_bound(&params.cParams);
+
        struct {
                unsigned                        feature;
                enum bch_compression_type       type;
@@ -580,18 +581,17 @@ 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(), },
                { BCH_FEATURE_zstd, BCH_COMPRESSION_TYPE_zstd,
-                       zstd_cctx_workspace_bound(&params.cParams),
+                       c->zstd_workspace_size,
                        zstd_dctx_workspace_bound() },
        }, *i;
        bool have_compressed = false;
 
-       c->zstd_params = params;
-
        for (i = compression_types;
             i < compression_types + ARRAY_SIZE(compression_types);
             i++)
@@ -601,13 +601,13 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
                return 0;
 
        if (!mempool_initialized(&c->compression_bounce[READ]) &&
-           mempool_init_kvpmalloc_pool(&c->compression_bounce[READ],
-                                       1, c->opts.encoded_extent_max))
+           mempool_init_kvmalloc_pool(&c->compression_bounce[READ],
+                                      1, c->opts.encoded_extent_max))
                return -BCH_ERR_ENOMEM_compression_bounce_read_init;
 
        if (!mempool_initialized(&c->compression_bounce[WRITE]) &&
-           mempool_init_kvpmalloc_pool(&c->compression_bounce[WRITE],
-                                       1, c->opts.encoded_extent_max))
+           mempool_init_kvmalloc_pool(&c->compression_bounce[WRITE],
+                                      1, c->opts.encoded_extent_max))
                return -BCH_ERR_ENOMEM_compression_bounce_write_init;
 
        for (i = compression_types;
@@ -619,21 +619,18 @@ 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;
 
-               if (mempool_init_kvpmalloc_pool(
+               if (mempool_init_kvmalloc_pool(
                                &c->compress_workspace[i->type],
                                1, i->compress_workspace))
                        return -BCH_ERR_ENOMEM_compression_workspace_init;
        }
 
        if (!mempool_initialized(&c->decompress_workspace) &&
-           mempool_init_kvpmalloc_pool(&c->decompress_workspace,
-                                       1, decompress_workspace_size))
+           mempool_init_kvmalloc_pool(&c->decompress_workspace,
+                                      1, decompress_workspace_size))
                return -BCH_ERR_ENOMEM_decompression_workspace_init;
 
        return 0;
@@ -642,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)
@@ -699,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;
 }