From: Marek VavruĊĦa Date: Thu, 4 Jan 2018 00:07:35 +0000 (-0800) Subject: allow access to cache object through context X-Git-Tag: v2.0.0~46^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82b1f643ad97ab2f1b2ea5acd8f90b59c5036aae;p=thirdparty%2Fknot-resolver.git allow access to cache object through context this surfaces the struct kr_cache through context variable, it doesn't implement any API or documented interface for it, so I just added a tests for the struct presence and introspection --- diff --git a/daemon/lua/kres-gen.lua b/daemon/lua/kres-gen.lua index ba31e5179..76eb97430 100644 --- a/daemon/lua/kres-gen.lua +++ b/daemon/lua/kres-gen.lua @@ -3,6 +3,8 @@ local ffi = require('ffi') typedef struct knot_dump_style knot_dump_style_t; extern const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT; +typedef void knot_db_t; +struct kr_cdb_api {}; typedef struct knot_mm { void *ctx, *alloc, *free; @@ -163,6 +165,21 @@ struct kr_request { knot_mm_t pool; }; enum kr_rank {KR_RANK_INITIAL, KR_RANK_OMIT, KR_RANK_TRY, KR_RANK_INDET = 4, KR_RANK_BOGUS, KR_RANK_MISMATCH, KR_RANK_MISSING, KR_RANK_INSECURE, KR_RANK_AUTH = 16, KR_RANK_SECURE = 32}; +struct kr_cache +{ + knot_db_t *db; + const struct kr_cdb_api *api; + struct { + uint32_t hit; + uint32_t miss; + uint32_t insert; + uint32_t delete; + } stats; + + uint32_t ttl_min, ttl_max; + struct timeval last_clear_walltime; + uint64_t last_clear_monotime; +}; struct knot_rrset { knot_dname_t *_owner; uint16_t type; @@ -203,6 +220,7 @@ struct kr_context { map_t trust_anchors; map_t negative_anchors; struct kr_zonecut root_hints; + struct kr_cache cache; char _stub[]; }; const char *knot_strerror(int code); diff --git a/daemon/lua/kres-gen.sh b/daemon/lua/kres-gen.sh index 432e49e8c..d1bf4d362 100755 --- a/daemon/lua/kres-gen.sh +++ b/daemon/lua/kres-gen.sh @@ -22,6 +22,8 @@ printf -- "--[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[\n" printf " typedef struct knot_dump_style knot_dump_style_t; extern const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT; +typedef void knot_db_t; +struct kr_cdb_api {}; " # The generator doesn't work well with typedefs of functions. @@ -58,6 +60,7 @@ typedef void (*map_free_f)(void *baton, void *ptr); struct kr_rplan struct kr_request enum kr_rank + struct kr_cache EOF genResType() { @@ -74,7 +77,7 @@ printf "\t/* beware: hidden stub */\n};\n" genResType "struct kr_query" -genResType "struct kr_context" | sed '/struct kr_cache/,$ d' +genResType "struct kr_context" | sed '/kr_nsrep_lru_t/,$ d' printf "\tchar _stub[];\n};\n" ## libknot API diff --git a/tests/config/cache_test.lua b/tests/config/cache_test.lua index 06f6f9210..6cbe8ad32 100644 --- a/tests/config/cache_test.lua +++ b/tests/config/cache_test.lua @@ -31,8 +31,17 @@ local function test_resize() is(cache.current_size, 50 * MB, 'cache was shrunk') end +-- test access to cache through context +local function test_context_cache() + local c = kres.context().cache + is(type(c), 'cdata', 'context has a cache object') + local s = c.stats + same({s.hit, s.miss, s.insert, s.delete}, {0, 0, 0, 0}, 'context cache stats works') +end + return { test_properties, test_stats, test_resize, + test_context_cache, } \ No newline at end of file