]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
nicer code, in function.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 17 Jul 2018 15:07:09 +0000 (15:07 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 17 Jul 2018 15:07:09 +0000 (15:07 +0000)
git-svn-id: file:///svn/unbound/trunk@4790 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/daemon.c
libunbound/context.c
services/cache/infra.c
services/cache/rrset.c
util/storage/slabhash.c
util/storage/slabhash.h

index b98f18c0cd8367c3b7c0d8446382dd22ba394b87..e02719f073fd32e158b1d8f295bd38c42f1e9d43 100644 (file)
@@ -803,9 +803,8 @@ void daemon_apply_cfg(struct daemon* daemon, struct config_file* cfg)
 {
         daemon->cfg = cfg;
        config_apply(cfg);
-       if(!daemon->env->msg_cache ||
-          cfg->msg_cache_slabs != daemon->env->msg_cache->size ||
-          (cfg->msg_cache_size/cfg->msg_cache_slabs)*cfg->msg_cache_slabs != slabhash_get_size(daemon->env->msg_cache)) {
+       if(!slabhash_is_size(daemon->env->msg_cache, cfg->msg_cache_size,
+               cfg->msg_cache_slabs)) {
                slabhash_delete(daemon->env->msg_cache);
                daemon->env->msg_cache = slabhash_create(cfg->msg_cache_slabs,
                        HASH_DEFAULT_STARTARRAY, cfg->msg_cache_size,
index dbe1cfcb097126a7069a4dbc126f0840fa60935d..20b463f7c74d2d6cd0bb15790756c24351d5493a 100644 (file)
@@ -71,9 +71,8 @@ context_finalize(struct ub_ctx* ctx)
                return UB_INITFAIL;
        if(!auth_zones_apply_cfg(ctx->env->auth_zones, cfg, 1))
                return UB_INITFAIL;
-       if(!ctx->env->msg_cache ||
-          cfg->msg_cache_slabs != ctx->env->msg_cache->size ||
-          (cfg->msg_cache_size/cfg->msg_cache_slabs)*cfg->msg_cache_slabs != slabhash_get_size(ctx->env->msg_cache)) {
+       if(!slabhash_is_size(ctx->env->msg_cache, cfg->msg_cache_size,
+               cfg->msg_cache_slabs)) {
                slabhash_delete(ctx->env->msg_cache);
                ctx->env->msg_cache = slabhash_create(cfg->msg_cache_slabs,
                        HASH_DEFAULT_STARTARRAY, cfg->msg_cache_size,
index 2b9b96e873eab0e4ee27278a455e75cfce432bc2..6f8fea6ad826e35a21af77dd82f1d1d40a90c18b 100644 (file)
@@ -302,12 +302,11 @@ infra_adjust(struct infra_cache* infra, struct config_file* cfg)
        /* divide cachesize by slabs and multiply by slabs, because if the
         * cachesize is not an even multiple of slabs, that is the resulting
         * size of the slabhash */
-       if((maxmem/cfg->infra_cache_slabs)*cfg->infra_cache_slabs != slabhash_get_size(infra->hosts) ||
-               cfg->infra_cache_slabs != infra->hosts->size ||
-               cfg->ratelimit_slabs != infra->domain_rates->size ||
-               (cfg->ratelimit_size/cfg->ratelimit_slabs)*cfg->ratelimit_slabs != slabhash_get_size(infra->domain_rates) ||
-               cfg->ip_ratelimit_slabs != infra->client_ip_rates->size ||
-               (cfg->ip_ratelimit_size/cfg->ip_ratelimit_slabs)*cfg->ip_ratelimit_slabs != slabhash_get_size(infra->client_ip_rates)) {
+       if(!slabhash_is_size(infra->hosts, maxmem, cfg->infra_cache_slabs) ||
+          !slabhash_is_size(infra->domain_rates, cfg->ratelimit_size,
+               cfg->ratelimit_slabs) ||
+          !slabhash_is_size(infra->client_ip_rates, cfg->ip_ratelimit_size,
+               cfg->ip_ratelimit_slabs)) {
                infra_delete(infra);
                infra = infra_create(cfg);
        } else {
index 26c1aeb91c62cc4d258353e0e81c0795c2d9e1a2..8c0251bcb9390513afac770e64ee3179e588dd74 100644 (file)
@@ -81,8 +81,8 @@ void rrset_cache_delete(struct rrset_cache* r)
 struct rrset_cache* rrset_cache_adjust(struct rrset_cache *r, 
        struct config_file* cfg, struct alloc_cache* alloc)
 {
-       if(!r || !cfg || cfg->rrset_cache_slabs != r->table.size ||
-               cfg->rrset_cache_size != slabhash_get_size(&r->table))
+       if(!r || !cfg || !slabhash_is_size(&r->table, cfg->rrset_cache_size,
+               cfg->rrset_cache_slabs))
        {
                rrset_cache_delete(r);
                r = rrset_cache_create(cfg, alloc);
index ae63b97727ee7609aad3daf9f724469d220da44b..a6c3d0fa649097fac8ad8ba66ac080bf61c77bdc 100644 (file)
@@ -153,6 +153,19 @@ size_t slabhash_get_size(struct slabhash* sl)
        return total;
 }
 
+int slabhash_is_size(struct slabhash* sl, size_t size, size_t slabs)
+{
+       /* divide by slabs and then multiply by the number of slabs,
+        * because if the size is not an even multiple of slabs, the
+        * uneven amount needs to be removed for comparison */
+       if(!sl) return 0;
+       if(sl->size != slabs) return 0;
+       if(slabs == 0) return 0;
+       if( (size/slabs)*slabs == slabhash_get_size(sl))
+               return 1;
+       return 0;
+}
+
 size_t slabhash_get_mem(struct slabhash* sl)
 {      
        size_t i, total = sizeof(*sl);
index 2ecf6fe719a732e441d77a7aa9685d5a108206a3..4ecb604216783f2e8f35ff21e820889fe888b1cb 100644 (file)
@@ -152,6 +152,15 @@ void slabhash_status(struct slabhash* table, const char* id, int extended);
  */
 size_t slabhash_get_size(struct slabhash* table);
 
+/**
+ * See if slabhash is of given (size, slabs) configuration.
+ * @param table: hash table
+ * @param size: max size to test for
+ * @param slabs: slab count to test for.
+ * @return true if equal
+ */
+int slabhash_is_size(struct slabhash* table, size_t size, size_t slabs);
+
 /**
  * Retrieve slab hash current memory use.
  * @param table: hash table.