dedup

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

commit 46584d2ff6fd9566d99fc0298d1037e540afc77c
parent 2dcf94fae182f1cc856ef0a5984e636466da2009
Author: sin <sin@2f30.org>
Date:   Sat, 30 Mar 2019 16:06:04 +0000

Rename cache to icache (index cache)

Diffstat:
MMakefile | 4++--
Dcache.c | 100-------------------------------------------------------------------------------
Mdedup.c | 28++++++++++++++--------------
Mdedup.h | 12++++++------
Aicache.c | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 122 insertions(+), 122 deletions(-)

diff --git a/Makefile b/Makefile @@ -11,9 +11,9 @@ SRC = \ dedup.h \ tree.h \ blake2b-ref.c \ - cache.c \ chunker.c \ compress.c \ + icache.c \ pack.c \ types.c \ unpack.c \ @@ -22,9 +22,9 @@ SRC = \ OBJ = \ $(BIN).o \ blake2b-ref.o \ - cache.o \ chunker.o \ compress.o \ + icache.o \ pack.o \ types.o \ unpack.o \ diff --git a/cache.c b/cache.c @@ -1,100 +0,0 @@ -#include <sys/types.h> - -#include <err.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -#include "dedup.h" -#include "tree.h" - -struct node { - struct blk_desc desc; - RB_ENTRY(node) e; -}; -RB_HEAD(cache_head, node); - -struct cache { - struct cache_head nodes; -}; - -static int -node_cmp(struct node *e1, struct node *e2) -{ - int r; - - r = memcmp(e1->desc.md, e2->desc.md, sizeof(e1->desc.md)); - if (r > 0) - return 1; - else if (r < 0) - return -1; - return 0; -} -static RB_PROTOTYPE(cache_head, node, e, node_cmp); -static RB_GENERATE(cache_head, node, e, node_cmp); - -static struct node * -alloc_node(struct blk_desc *desc) -{ - struct node *node; - - node = calloc(1, sizeof(*node)); - if (node == NULL) - err(1, "calloc"); - node->desc = *desc; - return node; -} - -static void -free_node(struct node *node) -{ - free(node); -} - -struct cache * -alloc_cache(void) -{ - struct cache *cache; - - cache = calloc(1, sizeof(*cache)); - if (cache == NULL) - err(1, "calloc"); - RB_INIT(&cache->nodes); - return cache; -} - -void -free_cache(struct cache *cache) -{ - struct node *node, *tmp; - - RB_FOREACH_SAFE(node, cache_head, &cache->nodes, tmp) { - RB_REMOVE(cache_head, &cache->nodes, node); - free_node(node); - } - free(cache); -} - -void -add_cache_entry(struct cache *cache, struct blk_desc *desc) -{ - struct node *node; - - node = alloc_node(desc); - if (RB_INSERT(cache_head, &cache->nodes, node) != NULL) - free_node(node); -} - -int -lookup_cache_entry(struct cache *cache, struct blk_desc *desc) -{ - struct node *node, key; - - key.desc = *desc; - node = RB_FIND(cache_head, &cache->nodes, &key); - if (node != NULL) { - *desc = node->desc; - return 0; - } - return -1; -} diff --git a/dedup.c b/dedup.c @@ -30,11 +30,11 @@ struct extract_args { static struct snap_hdr snap_hdr; static struct blk_hdr blk_hdr; -static struct cache *cache; +static struct icache *icache; static int ifd; static int sfd; -static unsigned long long cache_hits; -static unsigned long long cache_misses; +static unsigned long long icache_hits; +static unsigned long long icache_misses; int verbose; char *argv0; @@ -68,8 +68,8 @@ print_stats(struct stats *st) (unsigned long long)st->max_blk_size); fprintf(stderr, "Number of unique blocks: %llu\n", (unsigned long long)st->nr_blks); - fprintf(stderr, "Cache hits: %llu\n", cache_hits); - fprintf(stderr, "Cache misses: %llu\n", cache_misses); + fprintf(stderr, "Index cache hits: %llu\n", icache_hits); + fprintf(stderr, "Index cache misses: %llu\n", icache_misses); } static struct snap * @@ -220,15 +220,15 @@ dedup_chunk(struct snap *snap, uint8_t *chunkp, size_t chunk_size) snap_hdr.st.compr_size += n; memcpy(blk_desc.md, md, sizeof(blk_desc.md)); - if (lookup_cache_entry(cache, &blk_desc) < 0) { + if (lookup_icache_entry(icache, &blk_desc) < 0) { blk_desc.offset = blk_hdr.size; blk_desc.size = n; snap->blk_desc[snap->nr_blk_descs++] = blk_desc; append_blk(compr_buf, &blk_desc); - add_cache_entry(cache, &blk_desc); - cache_misses++; + add_icache_entry(icache, &blk_desc); + icache_misses++; snap_hdr.st.dedup_size += blk_desc.size; snap_hdr.st.nr_blks++; @@ -239,7 +239,7 @@ dedup_chunk(struct snap *snap, uint8_t *chunkp, size_t chunk_size) snap_hdr.st.min_blk_size = blk_desc.size; } else { snap->blk_desc[snap->nr_blk_descs++] = blk_desc; - cache_hits++; + icache_hits++; } free(compr_buf); @@ -362,7 +362,7 @@ check_snap(struct snap *snap, void *arg) } static int -build_cache(struct snap *snap, void *arg) +build_icache(struct snap *snap, void *arg) { uint8_t *buf; uint64_t i; @@ -372,7 +372,7 @@ build_cache(struct snap *snap, void *arg) struct blk_desc *blk_desc; blk_desc = &snap->blk_desc[i]; - add_cache_entry(cache, blk_desc); + add_icache_entry(icache, blk_desc); } free(buf); return WALK_CONTINUE; @@ -506,8 +506,8 @@ init(int iflag) load_blk_hdr(); } - cache = alloc_cache(); - walk_snap(build_cache, NULL); + icache = alloc_icache(); + walk_snap(build_icache, NULL); } static void @@ -516,7 +516,7 @@ term(void) if (verbose > 0) print_stats(&snap_hdr.st); - free_cache(cache); + free_icache(icache); save_blk_hdr(); save_snap_hdr(); diff --git a/dedup.h b/dedup.h @@ -25,7 +25,7 @@ #define COMPR_ENABLED_SHIFT 16 #define COMPR_ENABLED_MASK 0x1 -struct cache; +struct icache; struct chunker; struct stats { @@ -70,11 +70,11 @@ extern int compr_enabled; /* dedup.c */ extern int verbose; -/* cache.c */ -struct cache *alloc_cache(void); -void free_cache(struct cache *cache); -void add_cache_entry(struct cache *cache, struct blk_desc *desc); -int lookup_cache_entry(struct cache *cache, struct blk_desc *desc); +/* icache.c */ +struct icache *alloc_icache(void); +void free_icache(struct icache *icache); +void add_icache_entry(struct icache *icache, struct blk_desc *desc); +int lookup_icache_entry(struct icache *icache, struct blk_desc *desc); /* chunker.c */ struct chunker *alloc_chunker(int fd, size_t min_size, size_t max_size, diff --git a/icache.c b/icache.c @@ -0,0 +1,100 @@ +#include <sys/types.h> + +#include <err.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "dedup.h" +#include "tree.h" + +struct node { + struct blk_desc desc; + RB_ENTRY(node) e; +}; +RB_HEAD(icache_head, node); + +struct icache { + struct icache_head nodes; +}; + +static int +node_cmp(struct node *e1, struct node *e2) +{ + int r; + + r = memcmp(e1->desc.md, e2->desc.md, sizeof(e1->desc.md)); + if (r > 0) + return 1; + else if (r < 0) + return -1; + return 0; +} +static RB_PROTOTYPE(icache_head, node, e, node_cmp); +static RB_GENERATE(icache_head, node, e, node_cmp); + +static struct node * +alloc_node(struct blk_desc *desc) +{ + struct node *node; + + node = calloc(1, sizeof(*node)); + if (node == NULL) + err(1, "calloc"); + node->desc = *desc; + return node; +} + +static void +free_node(struct node *node) +{ + free(node); +} + +struct icache * +alloc_icache(void) +{ + struct icache *icache; + + icache = calloc(1, sizeof(*icache)); + if (icache == NULL) + err(1, "calloc"); + RB_INIT(&icache->nodes); + return icache; +} + +void +free_icache(struct icache *icache) +{ + struct node *node, *tmp; + + RB_FOREACH_SAFE(node, icache_head, &icache->nodes, tmp) { + RB_REMOVE(icache_head, &icache->nodes, node); + free_node(node); + } + free(icache); +} + +void +add_icache_entry(struct icache *icache, struct blk_desc *desc) +{ + struct node *node; + + node = alloc_node(desc); + if (RB_INSERT(icache_head, &icache->nodes, node) != NULL) + free_node(node); +} + +int +lookup_icache_entry(struct icache *icache, struct blk_desc *desc) +{ + struct node *node, key; + + key.desc = *desc; + node = RB_FIND(icache_head, &icache->nodes, &key); + if (node != NULL) { + *desc = node->desc; + return 0; + } + return -1; +}