mirror of
https://gitlab.nic.cz/knot/knot-dns.git
synced 2026-05-28 04:02:31 -04:00
conf: remove useless mm_ctx
This commit is contained in:
parent
795f3088db
commit
ffc9b4eac7
7 changed files with 20 additions and 48 deletions
|
|
@ -27,7 +27,6 @@
|
|||
#include "libknot/yparser/ypformat.h"
|
||||
#include "libknot/yparser/yptrafo.h"
|
||||
#include "contrib/files.h"
|
||||
#include "contrib/mempattern.h"
|
||||
#include "contrib/sockaddr.h"
|
||||
#include "contrib/string.h"
|
||||
|
||||
|
|
@ -166,16 +165,8 @@ int conf_new(
|
|||
goto new_error;
|
||||
}
|
||||
|
||||
// Initialize a config mempool.
|
||||
out->mm = malloc(sizeof(knot_mm_t));
|
||||
if (out->mm == NULL) {
|
||||
ret = KNOT_ENOMEM;
|
||||
goto new_error;
|
||||
}
|
||||
mm_ctx_init(out->mm);
|
||||
|
||||
// Initialize query modules list.
|
||||
out->query_modules = mm_alloc(out->mm, sizeof(list_t));
|
||||
out->query_modules = malloc(sizeof(list_t));
|
||||
if (out->query_modules == NULL) {
|
||||
ret = KNOT_ENOMEM;
|
||||
goto new_error;
|
||||
|
|
@ -201,7 +192,7 @@ int conf_new(
|
|||
goto new_error;
|
||||
}
|
||||
|
||||
ret = out->api->init(&out->db, out->mm, &lmdb_opts);
|
||||
ret = out->api->init(&out->db, NULL, &lmdb_opts);
|
||||
|
||||
// Remove the database to ensure it is temporary.
|
||||
if (!remove_path(lmdb_opts.path)) {
|
||||
|
|
@ -217,7 +208,7 @@ int conf_new(
|
|||
lmdb_opts.flags.env |= KNOT_DB_LMDB_RDONLY;
|
||||
}
|
||||
|
||||
ret = out->api->init(&out->db, out->mm, &lmdb_opts);
|
||||
ret = out->api->init(&out->db, NULL, &lmdb_opts);
|
||||
}
|
||||
if (ret != KNOT_EOK) {
|
||||
goto new_error;
|
||||
|
|
@ -295,11 +286,10 @@ int conf_clone(
|
|||
|
||||
// Set shared items.
|
||||
out->api = s_conf->api;
|
||||
out->mm = s_conf->mm;
|
||||
out->db = s_conf->db;
|
||||
|
||||
// Initialize query modules list.
|
||||
out->query_modules = mm_alloc(out->mm, sizeof(list_t));
|
||||
out->query_modules = malloc(sizeof(list_t));
|
||||
if (out->query_modules == NULL) {
|
||||
yp_schema_free(out->schema);
|
||||
free(out);
|
||||
|
|
@ -310,7 +300,7 @@ int conf_clone(
|
|||
// Open common read-only transaction.
|
||||
ret = conf_refresh_txn(out);
|
||||
if (ret != KNOT_EOK) {
|
||||
mm_free(out->mm, out->query_modules);
|
||||
free(out->query_modules);
|
||||
yp_schema_free(out->schema);
|
||||
free(out);
|
||||
return ret;
|
||||
|
|
@ -349,7 +339,7 @@ conf_t *conf_update(
|
|||
conf->io.zones = s_conf->io.zones;
|
||||
}
|
||||
if ((flags & CONF_UPD_FMODULES) && s_conf != NULL) {
|
||||
mm_free(conf->mm, conf->query_modules);
|
||||
free(conf->query_modules);
|
||||
conf->query_modules = s_conf->query_modules;
|
||||
conf->query_plan = s_conf->query_plan;
|
||||
}
|
||||
|
|
@ -403,16 +393,13 @@ void conf_free(
|
|||
|
||||
conf_mod_load_purge(conf, false);
|
||||
conf_deactivate_modules(conf->query_modules, &conf->query_plan);
|
||||
mm_free(conf->mm, conf->query_modules);
|
||||
free(conf->query_modules);
|
||||
conf_mod_unload_shared(conf);
|
||||
|
||||
if (!conf->is_clone) {
|
||||
if (conf->api != NULL) {
|
||||
conf->api->deinit(conf->db);
|
||||
}
|
||||
if (conf->mm != NULL) {
|
||||
free(conf->mm);
|
||||
}
|
||||
}
|
||||
|
||||
free(conf);
|
||||
|
|
|
|||
|
|
@ -81,8 +81,6 @@ typedef struct {
|
|||
const struct knot_db_api *api;
|
||||
/*! Configuration schema. */
|
||||
yp_item_t *schema;
|
||||
/*! Memory context. */
|
||||
knot_mm_t *mm;
|
||||
/*! Configuration database. */
|
||||
knot_db_t *db;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -824,7 +824,7 @@ static void upd_changes(
|
|||
// Prepare zone changes storage if it doesn't exist.
|
||||
trie_t *zones = conf()->io.zones;
|
||||
if (zones == NULL) {
|
||||
zones = trie_create(conf()->mm);
|
||||
zones = trie_create(NULL);
|
||||
if (zones == NULL) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ void conf_activate_modules(
|
|||
}
|
||||
|
||||
// Create query plan.
|
||||
*query_plan = query_plan_create(conf->mm);
|
||||
*query_plan = query_plan_create();
|
||||
if (*query_plan == NULL) {
|
||||
ret = KNOT_ENOMEM;
|
||||
goto activate_error;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#include "knot/conf/tools.h"
|
||||
#include "knot/nameserver/query_module.h"
|
||||
#include "knot/nameserver/process_query.h"
|
||||
#include "contrib/mempattern.h"
|
||||
|
||||
#ifdef HAVE_ATOMIC
|
||||
#define ATOMIC_ADD(dst, val) __atomic_add_fetch(&(dst), (val), __ATOMIC_RELAXED)
|
||||
|
|
@ -45,14 +44,13 @@ int knotd_conf_check_ref(knotd_conf_check_args_t *args)
|
|||
return check_ref(args);
|
||||
}
|
||||
|
||||
struct query_plan *query_plan_create(knot_mm_t *mm)
|
||||
struct query_plan *query_plan_create(void)
|
||||
{
|
||||
struct query_plan *plan = mm_alloc(mm, sizeof(struct query_plan));
|
||||
struct query_plan *plan = malloc(sizeof(struct query_plan));
|
||||
if (plan == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
plan->mm = mm;
|
||||
for (unsigned i = 0; i < KNOTD_STAGES; ++i) {
|
||||
init_list(&plan->stage[i]);
|
||||
}
|
||||
|
|
@ -69,17 +67,16 @@ void query_plan_free(struct query_plan *plan)
|
|||
for (unsigned i = 0; i < KNOTD_STAGES; ++i) {
|
||||
struct query_step *step = NULL, *next = NULL;
|
||||
WALK_LIST_DELSAFE(step, next, plan->stage[i]) {
|
||||
mm_free(plan->mm, step);
|
||||
free(step);
|
||||
}
|
||||
}
|
||||
|
||||
mm_free(plan->mm, plan);
|
||||
free(plan);
|
||||
}
|
||||
|
||||
static struct query_step *make_step(knot_mm_t *mm, query_step_process_f process,
|
||||
void *ctx)
|
||||
static struct query_step *make_step(query_step_process_f process, void *ctx)
|
||||
{
|
||||
struct query_step *step = mm_calloc(mm, 1, sizeof(struct query_step));
|
||||
struct query_step *step = calloc(1, sizeof(struct query_step));
|
||||
if (step == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -93,7 +90,7 @@ static struct query_step *make_step(knot_mm_t *mm, query_step_process_f process,
|
|||
int query_plan_step(struct query_plan *plan, knotd_stage_t stage,
|
||||
query_step_process_f process, void *ctx)
|
||||
{
|
||||
struct query_step *step = make_step(plan->mm, process, ctx);
|
||||
struct query_step *step = make_step(process, ctx);
|
||||
if (step == NULL) {
|
||||
return KNOT_ENOMEM;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,12 +44,11 @@ struct query_step {
|
|||
* assembly phase, for example 'before processing', 'answer section' and so on.
|
||||
*/
|
||||
struct query_plan {
|
||||
knot_mm_t *mm;
|
||||
list_t stage[KNOTD_STAGES];
|
||||
};
|
||||
|
||||
/*! \brief Create an empty query plan. */
|
||||
struct query_plan *query_plan_create(knot_mm_t *mm);
|
||||
struct query_plan *query_plan_create(void);
|
||||
|
||||
/*! \brief Free query plan and all planned steps. */
|
||||
void query_plan_free(struct query_plan *plan);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -21,8 +21,6 @@
|
|||
#include "libknot/libknot.h"
|
||||
#include "knot/nameserver/query_module.h"
|
||||
#include "libknot/packet/pkt.h"
|
||||
#include "contrib/mempattern.h"
|
||||
#include "contrib/ucw/mempool.h"
|
||||
|
||||
/* Universal processing stage. */
|
||||
unsigned state_visit(unsigned state, knot_pkt_t *pkt, knotd_qdata_t *qdata,
|
||||
|
|
@ -39,15 +37,11 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
plan_lazy();
|
||||
|
||||
/* Create processing context. */
|
||||
knot_mm_t mm;
|
||||
mm_ctx_mempool(&mm, MM_DEFAULT_BLKSIZE);
|
||||
|
||||
/* Create a map of expected steps. */
|
||||
bool state_map[KNOTD_STAGES] = { false };
|
||||
|
||||
/* Prepare query plan. */
|
||||
struct query_plan *plan = query_plan_create(&mm);
|
||||
struct query_plan *plan = query_plan_create();
|
||||
ok(plan != NULL, "query_plan: create");
|
||||
|
||||
/* Register all stage visits. */
|
||||
|
|
@ -85,8 +79,5 @@ int main(int argc, char *argv[])
|
|||
/* Free the query plan. */
|
||||
query_plan_free(plan);
|
||||
|
||||
/* Cleanup. */
|
||||
mp_delete((struct mempool *)mm.ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue