Commit dfe7468d authored by Vladimír Čunát's avatar Vladimír Čunát

rename module 'cache_lmdb' -> 'cache'

The name was weird.  There's no other implementation ATM and the module
will always be only really suitable for *local* caches, but otherwise
it's not neccessarily bound to LMDB.
parent f7de1275
......@@ -212,14 +212,14 @@ the modules use as the :ref:`input configuration <mod-properties>`.
.. warning:: Modules specified including their configuration may not load exactly in the same order as specified.
Modules are inherently ordered by their declaration. Some modules are built-in, so it would be normally impossible to place for example *hints* before *cache_lmdb*. You can enforce specific order by precedence operators **>** and **<**.
Modules are inherently ordered by their declaration. Some modules are built-in, so it would be normally impossible to place for example *hints* before *cache*. You can enforce specific order by precedence operators **>** and **<**.
.. code-block:: lua
modules = {
'hints > iterate', -- Hints AFTER iterate
'policy > hints', -- Policy AFTER hints
'view < cache_lmdb' -- View BEFORE cache_lmdb
'view < cache' -- View BEFORE cache
}
modules.list() -- Check module call order
......
......@@ -604,7 +604,7 @@ static int init_resolver(struct engine *engine)
/* Load basic modules */
engine_register(engine, "iterate", NULL, NULL);
engine_register(engine, "validate", NULL, NULL);
engine_register(engine, "cache_lmdb", NULL, NULL);
engine_register(engine, "cache", NULL, NULL);
return array_push(engine->backends, kr_cdb_lmdb());
}
......@@ -693,8 +693,8 @@ static void engine_unload(struct engine *engine, struct kr_module *module)
/* Unregister module */
auto_free char *name = strdup(module->name);
kr_module_unload(module);
/* Clear in Lua world */
if (name) {
/* Clear in Lua world, but not for embedded modules ('cache' in particular). */
if (name && !kr_module_embedded(name)) {
lua_pushnil(engine->L);
lua_setglobal(engine->L, name);
}
......
......@@ -498,7 +498,7 @@ static int answer_simple_hit(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
const struct entry_h *eh, const void *eh_bound, uint32_t new_ttl);
/** function for .produce phase */
int cache_lmdb_peek(kr_layer_t *ctx, knot_pkt_t *pkt)
int cache_peek(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *req = ctx->req;
struct kr_query *qry = req->current_query;
......@@ -893,7 +893,7 @@ int cache_lmdb_peek(kr_layer_t *ctx, knot_pkt_t *pkt)
static int stash_rrset(const ranked_rr_array_t *arr, int arr_i, uint32_t min_ttl,
const struct kr_query *qry, struct kr_cache *cache);
int cache_lmdb_stash(kr_layer_t *ctx, knot_pkt_t *pkt)
int cache_stash(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *req = ctx->req;
struct kr_query *qry = req->current_query;
......
......@@ -27,9 +27,9 @@ static const size_t PKT_SIZE_NOWIRE = -1;
#include "lib/module.h"
/* Prototypes for the cache_lmdb module implementation. */
int cache_lmdb_peek(kr_layer_t *ctx, knot_pkt_t *pkt);
int cache_lmdb_stash(kr_layer_t *ctx, knot_pkt_t *pkt);
/* Prototypes for the 'cache' module implementation. */
int cache_peek(kr_layer_t *ctx, knot_pkt_t *pkt);
int cache_stash(kr_layer_t *ctx, knot_pkt_t *pkt);
/**
......
......@@ -18,14 +18,14 @@
#include "lib/cache.h"
/** Module implementation. */
const kr_layer_api_t *cache_lmdb_layer(struct kr_module *module)
const kr_layer_api_t *cache_layer(struct kr_module *module)
{
static const kr_layer_api_t _layer = {
.produce = &cache_lmdb_peek,
.consume = &cache_lmdb_stash,
.produce = &cache_peek,
.consume = &cache_stash,
};
return &_layer;
}
KR_MODULE_EXPORT(cache_lmdb)
KR_MODULE_EXPORT(cache)
......@@ -3,7 +3,7 @@ libkres_SOURCES := \
lib/generic/map.c \
lib/layer/iterate.c \
lib/layer/validate.c \
lib/layer/cache_lmdb.c \
lib/layer/cache.c \
lib/dnssec/nsec.c \
lib/dnssec/nsec3.c \
lib/dnssec/signature.c \
......
......@@ -26,11 +26,11 @@
/* List of embedded modules */
const kr_layer_api_t *iterate_layer(struct kr_module *module);
const kr_layer_api_t *validate_layer(struct kr_module *module);
const kr_layer_api_t *cache_lmdb_layer(struct kr_module *module);
const kr_layer_api_t *cache_layer(struct kr_module *module);
static const struct kr_module embedded_modules[] = {
{ "iterate", NULL, NULL, NULL, iterate_layer, NULL, NULL, NULL },
{ "iterate", NULL, NULL, NULL, iterate_layer, NULL, NULL, NULL },
{ "validate", NULL, NULL, NULL, validate_layer, NULL, NULL, NULL },
{ "cache_lmdb", NULL, NULL, NULL, cache_lmdb_layer, NULL, NULL, NULL },
{ "cache", NULL, NULL, NULL, cache_layer, NULL, NULL, NULL },
};
/** Library extension. */
......@@ -69,20 +69,27 @@ static int load_library(struct kr_module *module, const char *name, const char *
return kr_error(ENOENT);
}
const struct kr_module * kr_module_embedded(const char *name)
{
for (unsigned i = 0; i < sizeof(embedded_modules)/sizeof(embedded_modules[0]); ++i) {
if (strcmp(name, embedded_modules[i].name) == 0)
return embedded_modules + i;
}
return NULL;
}
/** Load C module symbols. */
static int load_sym_c(struct kr_module *module, uint32_t api_required)
{
/* Check if it's embedded first */
for (unsigned i = 0; i < sizeof(embedded_modules)/sizeof(embedded_modules[0]); ++i) {
const struct kr_module *embedded = &embedded_modules[i];
if (strcmp(module->name, embedded->name) == 0) {
module->init = embedded->init;
module->deinit = embedded->deinit;
module->config = embedded->config;
module->layer = embedded->layer;
module->props = embedded->props;
return kr_ok();
}
const struct kr_module *embedded = kr_module_embedded(module->name);
if (embedded) {
module->init = embedded->init;
module->deinit = embedded->deinit;
module->config = embedded->config;
module->layer = embedded->layer;
module->props = embedded->props;
return kr_ok();
}
/* Load dynamic library module */
auto_free char *m_prefix = kr_strcatdup(2, module->name, "_");
......
......@@ -102,3 +102,9 @@ int kr_module_load(struct kr_module *module, const char *name, const char *path)
KR_EXPORT
void kr_module_unload(struct kr_module *module);
/**
* Get embedded module prototype by name (or NULL).
*/
KR_EXPORT
const struct kr_module * kr_module_embedded(const char *name);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment