Skip to content
Snippets Groups Projects
Commit 87ca2a0f authored by Jan Kadlec's avatar Jan Kadlec
Browse files

Merge branch 'timers-in-storage-subdir' into 'master'

persistent timers in storage subdirectory

See merge request !292
parents 399c9a80 f619edda
Branches
Tags
No related merge requests found
......@@ -42,7 +42,7 @@ struct namedb_api {
/* Context operations */
knot_namedb_t *(*init)(const char *handle, mm_ctx_t *mm);
knot_namedb_t *(*init)(const char *config, mm_ctx_t *mm);
void (*deinit)(knot_namedb_t *db);
/* Transactions */
......
......@@ -17,10 +17,14 @@
#ifdef HAVE_LMDB
#include <lmdb.h>
#include <sys/stat.h>
#include "common/namedb/namedb_lmdb.h"
#include "libknot/errcode.h"
#define LMDB_DIR_MODE 0770
#define LMDB_FILE_MODE 0660
struct lmdb_env
{
MDB_dbi dbi;
......@@ -28,14 +32,30 @@ struct lmdb_env
mm_ctx_t *pool;
};
static int dbase_open(struct lmdb_env *env, const char *handle)
static int create_env_dir(const char *path)
{
int r = mkdir(path, LMDB_DIR_MODE);
if (r == -1 && errno != EEXIST) {
return knot_errno_to_error(errno);
}
return KNOT_EOK;
}
static int dbase_open(struct lmdb_env *env, const char *path)
{
int ret = mdb_env_create(&env->env);
if (ret != 0) {
return ret;
}
ret = mdb_env_open(env->env, handle, 0, 0644);
ret = create_env_dir(path);
if (ret != KNOT_EOK) {
mdb_env_close(env->env);
return ret;
}
ret = mdb_env_open(env->env, path, 0, LMDB_FILE_MODE);
if (ret != 0) {
mdb_env_close(env->env);
return ret;
......@@ -70,7 +90,7 @@ static void dbase_close(struct lmdb_env *env)
mdb_env_close(env->env);
}
static knot_namedb_t *init(const char *handle, mm_ctx_t *mm)
static knot_namedb_t *init(const char *config, mm_ctx_t *mm)
{
struct lmdb_env *env = mm_alloc(mm, sizeof(struct lmdb_env));
if (env == NULL) {
......@@ -78,7 +98,7 @@ static knot_namedb_t *init(const char *handle, mm_ctx_t *mm)
}
memset(env, 0, sizeof(struct lmdb_env));
int ret = dbase_open(env, handle);
int ret = dbase_open(env, config);
if (ret != 0) {
mm_free(mm, env);
return NULL;
......
......@@ -15,6 +15,7 @@
*/
#include "libknot/dname.h"
#include "common/mem.h"
#include "common/namedb/namedb.h"
#include "common/namedb/namedb_lmdb.h"
#include "knot/zone/timers.h"
......@@ -125,7 +126,16 @@ knot_namedb_t *open_timers_db(const char *storage)
// No-op if we don't have lmdb, all other operations will no-op as well then
return NULL;
#else
return namedb_lmdb_api()->init(storage, NULL);
char *path = sprintf_alloc("%s/timers", storage);
if (!path) {
return NULL;
}
knot_namedb_t *db = namedb_lmdb_api()->init(path, NULL);
free(path);
return db;
#endif
}
......
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