Commit 09222d11 authored by Daniel Salzman's avatar Daniel Salzman

conf: add dynamic changes context

parent 47139ad3
......@@ -309,11 +309,22 @@ int conf_clone(
}
void conf_update(
conf_t *conf)
conf_t *conf,
conf_update_flag_t flags)
{
// Remove the clone flag for new master configuration.
if (conf != NULL) {
conf->is_clone = false;
if ((flags & CONF_UPD_FCONFIO) && s_conf != NULL) {
conf->io.flags = s_conf->io.flags;
conf->io.zones = s_conf->io.zones;
}
if ((flags & CONF_UPD_FMODULES) && s_conf != NULL) {
list_dup(&conf->query_modules, &s_conf->query_modules,
sizeof(struct query_module));
conf->query_plan = s_conf->query_plan;
}
}
conf_t **current_conf = &s_conf;
......@@ -324,6 +335,15 @@ void conf_update(
if (old_conf != NULL) {
// Remove the clone flag if a single configuration.
old_conf->is_clone = (conf != NULL) ? true : false;
if (flags & CONF_UPD_FCONFIO) {
old_conf->io.zones = NULL;
}
if (flags & CONF_UPD_FMODULES) {
init_list(&old_conf->query_modules);
old_conf->query_plan = NULL;
}
conf_free(old_conf);
}
}
......@@ -343,6 +363,10 @@ void conf_free(
if (conf->io.txn != NULL) {
conf->api->txn_abort(conf->io.txn_stack);
}
if (conf->io.zones != NULL) {
hattrie_free(conf->io.zones);
mm_free(conf->mm, conf->io.zones);
}
conf_deactivate_modules(&conf->query_modules, &conf->query_plan);
......
......@@ -27,6 +27,7 @@
#include "libknot/libknot.h"
#include "libknot/yparser/ypscheme.h"
#include "contrib/hat-trie/hat-trie.h"
#include "contrib/ucw/lists.h"
/*! Default template identifier. */
......@@ -81,6 +82,10 @@ typedef struct {
knot_db_txn_t *txn;
/*! Stack of nested writing transactions. */
knot_db_txn_t txn_stack[CONF_MAX_TXN_DEPTH];
/*! Master transaction flags. */
yp_flag_t flags;
/*! Changed zones. */
hattrie_t *zones;
} io;
/*! Current config file (for reload if started with config file). */
......@@ -119,6 +124,15 @@ typedef enum {
CONF_FNOHOSTNAME = 1 << 2, /*!< Don't set the hostname. */
} conf_flag_t;
/*!
* Configuration update flags.
*/
typedef enum {
CONF_UPD_FNONE = 0, /*!< Empty flag. */
CONF_UPD_FMODULES = 1 << 0, /*!< Reuse previous global modules. */
CONF_UPD_FCONFIO = 1 << 1, /*!< Reuse previous cofio reload context. */
} conf_update_flag_t;
/*!
* Returns the active configuration.
*/
......@@ -177,10 +191,12 @@ int conf_clone(
/*!
* Replaces the active configuration with the specified one.
*
* \param[in] conf New configuration.
* \param[in] conf New configuration.
* \param[in] flags Update flags.
*/
void conf_update(
conf_t *conf
conf_t *conf,
conf_update_flag_t flags
);
/*!
......
......@@ -102,7 +102,7 @@ static int options_init_modern(options_t *options)
}
// Update to the new config.
conf_update(new_conf);
conf_update(new_conf, CONF_UPD_FNONE);
return DNSSEC_EOK;
}
......@@ -127,7 +127,7 @@ void options_cleanup(options_t *options)
}
if (!options->legacy) {
conf_update(NULL);
conf_update(NULL, CONF_UPD_FNONE);
}
free(options->kasp_dir);
......
......@@ -345,7 +345,7 @@ static unsigned char complete(EditLine *el, int ch)
}
complete_exit:
conf_update(NULL);
conf_update(NULL, CONF_UPD_FNONE);
tok_reset(tok);
tok_end(tok);
......
......@@ -105,7 +105,7 @@ int set_config(const cmd_desc_t *desc, params_t *params)
}
/* Update to the new config. */
conf_update(new_conf);
conf_update(new_conf, CONF_UPD_FNONE);
return KNOT_EOK;
}
......@@ -216,7 +216,7 @@ int process_cmd(int argc, const char **argv, params_t *params)
/* Set control interface if necessary. */
ret = set_ctl(&args.ctl, desc, params);
if (ret != KNOT_EOK) {
conf_update(NULL);
conf_update(NULL, CONF_UPD_FNONE);
return ret;
}
......@@ -225,7 +225,7 @@ int process_cmd(int argc, const char **argv, params_t *params)
/* Cleanup */
unset_ctl(args.ctl);
conf_update(NULL);
conf_update(NULL, CONF_UPD_FNONE);
return ret;
}
......@@ -358,7 +358,7 @@ static int set_config(const char *confdb, const char *config)
&new_conf->query_plan);
/* Update to the new config. */
conf_update(new_conf);
conf_update(new_conf, CONF_UPD_FNONE);
return KNOT_EOK;
}
......
......@@ -39,7 +39,7 @@ static inline int test_conf(const char *conf_str, const yp_item_t *scheme)
return ret;
}
conf_update(new_conf);
conf_update(new_conf, CONF_UPD_FNONE);
return KNOT_EOK;
}
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