dedup

data deduplication program
git clone git://git.2f30.org/dedup.git
Log | Files | Refs | README | LICENSE

commit 36f8eba403de0699cb89e68a40116aa0789ca5dc
parent 96025603520557acbba2313f76e5f436449ff68a
Author: sin <sin@2f30.org>
Date:   Sun,  7 Apr 2019 13:33:32 +0100

Add a compr_final() hook

This may be needed in the future to deallocate resources.

Diffstat:
Mcompress.c | 23+++++++++++++++++++++++
Mdedup.c | 5+++++
Mdedup.h | 1+
3 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/compress.c b/compress.c @@ -16,6 +16,7 @@ static size_t none_compr(struct compr_ctx *ctx, const void *in, void *out, size_t insize, size_t outsize); static size_t none_decompr(struct compr_ctx *ctx, const void *in, void *out, size_t insize, size_t outsize); +static int none_final(struct compr_ctx *ctx); static int lz4_init(struct compr_ctx *ctx); static size_t lz4_size(struct compr_ctx *ctx, size_t n); @@ -23,6 +24,7 @@ static size_t lz4_compr(struct compr_ctx *ctx, const void *in, void *out, size_t insize, size_t outsize); static size_t lz4_decompr(struct compr_ctx *ctx, const void *in, void *out, size_t insize, size_t outsize); +static int lz4_final(struct compr_ctx *ctx); static struct compr_ops { int (*init)(struct compr_ctx *ctx); @@ -31,18 +33,21 @@ static struct compr_ops { size_t insize, size_t outsize); size_t (*decompr)(struct compr_ctx *ctx, const void *in, void *out, size_t insize, size_t outsize); + int (*final)(struct compr_ctx *ctx); } comprs[NR_COMPRS] = { { .init = none_init, .size = none_size, .compr = none_compr, .decompr = none_decompr, + .final = none_final, }, { .init = lz4_init, .size = lz4_size, .compr = lz4_compr, .decompr = lz4_decompr, + .final = lz4_final, }, }; @@ -92,6 +97,12 @@ none_decompr(struct compr_ctx *ctx, const void *in, void *out, } static int +none_final(struct compr_ctx *ctx) +{ + return 0; +} + +static int lz4_init(struct compr_ctx *ctx) { return 0; @@ -129,6 +140,12 @@ lz4_decompr(struct compr_ctx *ctx, const void *in, void *out, return n; } +static int +lz4_final(struct compr_ctx *ctx) +{ + return 0; +} + int compr_init(struct compr_ctx *ctx, int type) { @@ -160,6 +177,12 @@ decompr(struct compr_ctx *ctx, const void *in, void *out, } int +compr_final(struct compr_ctx *ctx) +{ + return (*ctx->ops->final)(ctx); +} + +int compr_name2type(char *name) { struct algomap *algo; diff --git a/dedup.c b/dedup.c @@ -254,6 +254,7 @@ dedup_chunk(struct snap *snap, uint8_t *chunkp, size_t chunk_size) } free(compr_buf); + compr_final(&ctx); } static void @@ -319,6 +320,7 @@ extract(struct snap *snap, void *arg) } free_buf(buf[1]); free_buf(buf[0]); + compr_final(&ctx); args->ret = 0; return WALK_STOP; } @@ -369,6 +371,7 @@ check_snap(struct snap *snap, void *arg) *ret = -1; } free_buf(buf); + compr_final(&ctx); return WALK_CONTINUE; } @@ -388,6 +391,7 @@ build_icache(struct snap *snap, void *arg) insert_icache(icache, blk_desc); } free(buf); + compr_final(&ctx); return WALK_CONTINUE; } @@ -481,6 +485,7 @@ init_snap_hdr(void) snap_hdr.flags = (VER_MAJ << VER_MAJ_SHIFT) | VER_MIN; snap_hdr.size = SNAP_HDR_SIZE; snap_hdr.st.min_blk_size = compr_size(&ctx, BLKSIZE_MAX); + compr_final(&ctx); } static void diff --git a/dedup.h b/dedup.h @@ -108,6 +108,7 @@ size_t compr(struct compr_ctx *ctx, const void *in, void *out, size_t insize, size_t outsize); size_t decompr(struct compr_ctx *ctx, const void *in, void *out, size_t insize, size_t outsize); +int compr_final(struct compr_ctx *ctx); int compr_name2type(char *name); /* hash.c */