Commit 12b03578 authored by Daniel Salzman's avatar Daniel Salzman

conf: fix query_modules list reuse upon conf-commit (adding zones)

parent 16de44cc
...@@ -168,7 +168,7 @@ static void dump_to_file(FILE *fd, server_t *server) ...@@ -168,7 +168,7 @@ static void dump_to_file(FILE *fd, server_t *server)
dump_ctx_t ctx = { dump_ctx_t ctx = {
.fd = fd, .fd = fd,
.query_modules = &conf()->query_modules, .query_modules = conf()->query_modules,
}; };
// Dump global statistics. // Dump global statistics.
......
...@@ -157,9 +157,6 @@ int conf_new( ...@@ -157,9 +157,6 @@ int conf_new(
} }
memset(out, 0, sizeof(conf_t)); memset(out, 0, sizeof(conf_t));
// Initialize query modules list.
init_list(&out->query_modules);
// Initialize config schema. // Initialize config schema.
int ret = yp_schema_copy(&out->schema, schema); int ret = yp_schema_copy(&out->schema, schema);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
...@@ -174,6 +171,14 @@ int conf_new( ...@@ -174,6 +171,14 @@ int conf_new(
} }
mm_ctx_mempool(out->mm, MM_DEFAULT_BLKSIZE); mm_ctx_mempool(out->mm, MM_DEFAULT_BLKSIZE);
// Initialize query modules list.
out->query_modules = mm_alloc(out->mm, sizeof(list_t));
if (out->query_modules == NULL) {
ret = KNOT_ENOMEM;
goto new_error;
}
init_list(out->query_modules);
// Set the DB api. // Set the DB api.
out->api = knot_db_lmdb_api(); out->api = knot_db_lmdb_api();
struct knot_db_lmdb_opts lmdb_opts = KNOT_DB_LMDB_OPTS_INITIALIZER; struct knot_db_lmdb_opts lmdb_opts = KNOT_DB_LMDB_OPTS_INITIALIZER;
...@@ -290,9 +295,19 @@ int conf_clone( ...@@ -290,9 +295,19 @@ int conf_clone(
out->mm = s_conf->mm; out->mm = s_conf->mm;
out->db = s_conf->db; out->db = s_conf->db;
// Initialize query modules list.
out->query_modules = mm_alloc(out->mm, sizeof(list_t));
if (out->query_modules == NULL) {
yp_schema_free(out->schema);
free(out);
return KNOT_ENOMEM;
}
init_list(out->query_modules);
// Open common read-only transaction. // Open common read-only transaction.
ret = conf_refresh_txn(out); ret = conf_refresh_txn(out);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
mm_free(out->mm, out->query_modules);
yp_schema_free(out->schema); yp_schema_free(out->schema);
free(out); free(out);
return ret; return ret;
...@@ -308,9 +323,6 @@ int conf_clone( ...@@ -308,9 +323,6 @@ int conf_clone(
out->hostname = strdup(s_conf->hostname); out->hostname = strdup(s_conf->hostname);
} }
// Initialize query modules list.
init_list(&out->query_modules);
// Initialize cached values. // Initialize cached values.
init_cache(out); init_cache(out);
...@@ -334,8 +346,7 @@ conf_t *conf_update( ...@@ -334,8 +346,7 @@ conf_t *conf_update(
conf->io.zones = s_conf->io.zones; conf->io.zones = s_conf->io.zones;
} }
if ((flags & CONF_UPD_FMODULES) && s_conf != NULL) { if ((flags & CONF_UPD_FMODULES) && s_conf != NULL) {
list_dup(&conf->query_modules, &s_conf->query_modules, conf->query_modules = s_conf->query_modules;
sizeof(knotd_mod_t));
conf->query_plan = s_conf->query_plan; conf->query_plan = s_conf->query_plan;
} }
} }
...@@ -353,7 +364,7 @@ conf_t *conf_update( ...@@ -353,7 +364,7 @@ conf_t *conf_update(
old_conf->io.zones = NULL; old_conf->io.zones = NULL;
} }
if (flags & CONF_UPD_FMODULES) { if (flags & CONF_UPD_FMODULES) {
WALK_LIST_FREE(old_conf->query_modules); old_conf->query_modules = NULL;
old_conf->query_plan = NULL; old_conf->query_plan = NULL;
} }
if (!(flags & CONF_UPD_FNOFREE)) { if (!(flags & CONF_UPD_FNOFREE)) {
...@@ -388,7 +399,8 @@ void conf_free( ...@@ -388,7 +399,8 @@ void conf_free(
} }
conf_mod_load_purge(conf, false); conf_mod_load_purge(conf, false);
conf_deactivate_modules(&conf->query_modules, &conf->query_plan); conf_deactivate_modules(conf->query_modules, &conf->query_plan);
mm_free(conf->mm, conf->query_modules);
conf_mod_unload_shared(conf); conf_mod_unload_shared(conf);
if (!conf->is_clone) { if (!conf->is_clone) {
......
...@@ -132,7 +132,7 @@ typedef struct { ...@@ -132,7 +132,7 @@ typedef struct {
/*! List of old schemas (lazy freed). */ /*! List of old schemas (lazy freed). */
old_schema_dynarray_t old_schemas; old_schema_dynarray_t old_schemas;
/*! List of active query modules. */ /*! List of active query modules. */
list_t query_modules; list_t *query_modules;
/*! Default query modules plan. */ /*! Default query modules plan. */
struct query_plan *query_plan; struct query_plan *query_plan;
} conf_t; } conf_t;
......
...@@ -1328,7 +1328,7 @@ static int ctl_stats(ctl_args_t *args, ctl_cmd_t cmd) ...@@ -1328,7 +1328,7 @@ static int ctl_stats(ctl_args_t *args, ctl_cmd_t cmd)
// Process modules metrics. // Process modules metrics.
if (section == NULL || strncasecmp(section, "mod-", strlen("mod-")) == 0) { if (section == NULL || strncasecmp(section, "mod-", strlen("mod-")) == 0) {
int ret = modules_stats(&conf()->query_modules, args, NULL); int ret = modules_stats(conf()->query_modules, args, NULL);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
send_error(args, knot_strerror(ret)); send_error(args, knot_strerror(ret));
return ret; return ret;
......
...@@ -657,7 +657,7 @@ int server_reload(server_t *server) ...@@ -657,7 +657,7 @@ int server_reload(server_t *server)
return ret; return ret;
} }
conf_activate_modules(new_conf, NULL, &new_conf->query_modules, conf_activate_modules(new_conf, NULL, new_conf->query_modules,
&new_conf->query_plan); &new_conf->query_plan);
} }
......
...@@ -368,7 +368,7 @@ static int set_config(const char *confdb, const char *config) ...@@ -368,7 +368,7 @@ static int set_config(const char *confdb, const char *config)
} }
/* Activate global query modules. */ /* Activate global query modules. */
conf_activate_modules(new_conf, NULL, &new_conf->query_modules, conf_activate_modules(new_conf, NULL, new_conf->query_modules,
&new_conf->query_plan); &new_conf->query_plan);
/* Update to the new config. */ /* Update to the new config. */
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import os import os
from dnstest.libknot import libknot from dnstest.libknot import libknot
from dnstest.module import ModStats
from dnstest.test import Test from dnstest.test import Test
from dnstest.utils import * from dnstest.utils import *
...@@ -12,6 +13,9 @@ t = Test() ...@@ -12,6 +13,9 @@ t = Test()
knot = t.server("knot") knot = t.server("knot")
# Enable a global module to check the modules reuse doesn't crash the server.
knot.add_module(None, ModStats())
ctl = libknot.control.KnotCtl() ctl = libknot.control.KnotCtl()
ZONE_NAME = "testzone." ZONE_NAME = "testzone."
......
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