Commit dab2f58e authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

conf: code cleanup: get DB path unified

parent af578293
......@@ -1052,43 +1052,18 @@ char* conf_zonefile_txn(
return get_filename(conf, txn, zone, file);
}
char* conf_journalfile_txn(
char* conf_db_txn(
conf_t *conf,
knot_db_txn_t *txn)
{
conf_val_t val = conf_default_get_txn(conf, txn, C_STORAGE);
char *storage = conf_abs_path(&val, NULL);
val = conf_default_get_txn(conf, txn, C_JOURNAL_DB);
char *journaldir = conf_abs_path(&val, storage);
free(storage);
return journaldir;
}
char* conf_kaspdir_txn(
conf_t *conf,
knot_db_txn_t *txn)
{
conf_val_t val = conf_default_get_txn(conf, txn, C_STORAGE);
char *storage = conf_abs_path(&val, NULL);
val = conf_default_get_txn(conf, txn, C_KASP_DB);
char *kaspdir = conf_abs_path(&val, storage);
free(storage);
return kaspdir;
}
char* conf_timerdb_txn(
conf_t *conf,
knot_db_txn_t *txn)
knot_db_txn_t *txn,
const yp_name_t *db_type)
{
conf_val_t val = conf_default_get_txn(conf, txn, C_STORAGE);
char *storage = conf_abs_path(&val, NULL);
val = conf_default_get_txn(conf, txn, C_TIMER_DB);
char *timerdb = conf_abs_path(&val, storage);
val = conf_default_get_txn(conf, txn, db_type);
char *dbdir = conf_abs_path(&val, storage);
free(storage);
return timerdb;
return dbdir;
}
size_t conf_udp_threads_txn(
......
......@@ -593,40 +593,25 @@ static inline char* conf_zonefile(
}
/*!
* Gets the absolute journal file path.
* Gets the absolute directory path for a database.
*
* e.g. Journal, KASP db, Timers
*
* \note The result must be explicitly deallocated.
*
* \param[in] conf Configuration.
* \param[in] txn Configuration DB transaction.
*
* \return Absolute journal file path string pointer.
* \return Absolute database path string pointer.
*/
char* conf_journalfile_txn(
conf_t *conf,
knot_db_txn_t *txn);
static inline char* conf_journalfile(
conf_t *conf)
{
return conf_journalfile_txn(conf, &conf->read_txn);
}
char* conf_kaspdir_txn(
conf_t *conf,
knot_db_txn_t *txn);
static inline char* conf_kaspdir(
conf_t *conf)
{
return conf_kaspdir_txn(conf, &conf->read_txn);
}
char* conf_timerdb_txn(
char* conf_db_txn(conf_t *conf,
knot_db_txn_t *txn,
const yp_name_t *db_type);
static inline char* conf_db(
conf_t *conf,
knot_db_txn_t *txn);
static inline char* conf_timerdb(
conf_t *conf)
const yp_name_t *db_type)
{
return conf_timerdb_txn(conf, &conf->read_txn);
return conf_db_txn(conf, &conf->read_txn, db_type);
}
/*!
......
......@@ -153,7 +153,7 @@ int kdnssec_ctx_init(conf_t *conf, kdnssec_ctx_t *ctx, const knot_dname_t *zone_
goto init_error;
}
ctx->kasp_zone_path = conf_kaspdir(conf);
ctx->kasp_zone_path = conf_db(conf, C_KASP_DB);
if (ctx->kasp_zone_path == NULL) {
ret = KNOT_ENOMEM;
goto init_error;
......
......@@ -581,7 +581,7 @@ int knotd_mod_dnssec_init(knotd_mod_t *mod)
}
kaspdb = (knot_lmdb_db_t *)(mod->dnssec + 1);
char *kasp_dir = conf_kaspdir(mod->config);
char *kasp_dir = conf_db(mod->config, C_KASP_DB);
conf_val_t kasp_size = conf_default_get(mod->config, C_MAX_KASP_DB_SIZE);
knot_lmdb_init(kaspdb, kasp_dir, conf_int(&kasp_size), 0, "keys_db");
free(kasp_dir);
......
......@@ -449,21 +449,21 @@ int server_init(server_t *server, int bg_workers)
return KNOT_ENOMEM;
}
char *journal_dir = conf_journalfile(conf());
char *journal_dir = conf_db(conf(), C_JOURNAL_DB);
conf_val_t journal_size = conf_default_get(conf(), C_MAX_JOURNAL_DB_SIZE);
conf_val_t journal_mode = conf_default_get(conf(), C_JOURNAL_DB_MODE);
knot_lmdb_init(&server->journaldb, journal_dir, conf_int(&journal_size), journal_env_flags(conf_opt(&journal_mode)), NULL);
free(journal_dir);
char *kasp_dir = conf_kaspdir(conf());
char *kasp_dir = conf_db(conf(), C_KASP_DB);
conf_val_t kasp_size = conf_default_get(conf(), C_MAX_KASP_DB_SIZE);
knot_lmdb_init(&server->kaspdb, kasp_dir, conf_int(&kasp_size), 0, "keys_db");
free(kasp_dir);
char *timerdb = conf_timerdb(conf());
conf_val_t timerdb_size = conf_default_get(conf(), C_MAX_TIMER_DB_SIZE);
knot_lmdb_init(&server->timerdb, timerdb, conf_int(&timerdb_size), 0, NULL);
free(timerdb);
char *timer_dir = conf_db(conf(), C_TIMER_DB);
conf_val_t timer_size = conf_default_get(conf(), C_MAX_TIMER_DB_SIZE);
knot_lmdb_init(&server->timerdb, timer_dir, conf_int(&timer_size), 0, NULL);
free(timer_dir);
return KNOT_EOK;
}
......@@ -789,7 +789,7 @@ static int reconfigure_threads(conf_t *conf, server_t *server)
static int reconfigure_journal_db(conf_t *conf, server_t *server)
{
char *journal_dir = conf_journalfile(conf);
char *journal_dir = conf_db(conf, C_JOURNAL_DB);
conf_val_t journal_size = conf_default_get(conf, C_MAX_JOURNAL_DB_SIZE);
conf_val_t journal_mode = conf_default_get(conf, C_JOURNAL_DB_MODE);
int ret = knot_lmdb_reinit(&server->journaldb, journal_dir, conf_int(&journal_size),
......@@ -804,7 +804,7 @@ static int reconfigure_journal_db(conf_t *conf, server_t *server)
static int reconfigure_kasp_db(conf_t *conf, server_t *server)
{
char *kasp_dir = conf_kaspdir(conf);
char *kasp_dir = conf_db(conf, C_KASP_DB);
conf_val_t kasp_size = conf_default_get(conf, C_MAX_KASP_DB_SIZE);
int ret = knot_lmdb_reinit(&server->kaspdb, kasp_dir, conf_int(&kasp_size), 0);
if (ret != KNOT_EOK) {
......@@ -817,10 +817,10 @@ static int reconfigure_kasp_db(conf_t *conf, server_t *server)
static int reconfigure_timer_db(conf_t *conf, server_t *server)
{
char *timerdb = conf_timerdb(conf);
conf_val_t timerdb_size = conf_default_get(conf, C_MAX_TIMER_DB_SIZE);
int ret = knot_lmdb_reconfigure(&server->timerdb, timerdb, conf_int(&timerdb_size), 0);
free(timerdb);
char *timer_dir = conf_db(conf, C_TIMER_DB);
conf_val_t timer_size = conf_default_get(conf, C_MAX_TIMER_DB_SIZE);
int ret = knot_lmdb_reconfigure(&server->timerdb, timer_dir, conf_int(&timer_size), 0);
free(timer_dir);
return ret;
}
......
......@@ -125,7 +125,7 @@ static int key_command(int argc, char *argv[], int opt_ind)
kdnssec_ctx_t kctx = { 0 };
conf_val_t mapsize = conf_default_get(conf(), C_MAX_KASP_DB_SIZE);
char *kasp_dir = conf_kaspdir(conf());
char *kasp_dir = conf_db(conf(), C_KASP_DB);
knot_lmdb_init(&kaspdb, kasp_dir, conf_int(&mapsize), 0, "keys_db");
free(kasp_dir);
......
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