Commit 77845cc0 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

update: mutex avoid next update before cleanup by call_rcu

parent 00fa2fdd
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> /* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -418,6 +418,10 @@ void update_cleanup(apply_ctx_t *ctx) ...@@ -418,6 +418,10 @@ void update_cleanup(apply_ctx_t *ctx)
// also the nodes not being affected by the update itself // also the nodes not being affected by the update itself
// might be affected // might be affected
zone_trees_unify_binodes(ctx->contents->nodes, ctx->contents->nsec3_nodes); zone_trees_unify_binodes(ctx->contents->nodes, ctx->contents->nsec3_nodes);
if (ctx->cow_mutex != NULL) {
pthread_mutex_unlock(ctx->cow_mutex);
}
} }
void update_rollback(apply_ctx_t *ctx) void update_rollback(apply_ctx_t *ctx)
...@@ -442,6 +446,10 @@ void update_rollback(apply_ctx_t *ctx) ...@@ -442,6 +446,10 @@ void update_rollback(apply_ctx_t *ctx)
trie_cow_rollback(ctx->contents->nsec3_nodes->cow, trie_cb_noop, NULL); trie_cow_rollback(ctx->contents->nsec3_nodes->cow, trie_cb_noop, NULL);
} }
if (ctx->cow_mutex != NULL) {
pthread_mutex_unlock(ctx->cow_mutex);
}
free(ctx->contents->nodes); free(ctx->contents->nodes);
free(ctx->contents->nsec3_nodes); free(ctx->contents->nsec3_nodes);
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> /* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#pragma once #pragma once
#include <pthread.h>
#include "knot/zone/contents.h" #include "knot/zone/contents.h"
#include "knot/updates/changesets.h" #include "knot/updates/changesets.h"
#include "contrib/ucw/lists.h" #include "contrib/ucw/lists.h"
...@@ -29,6 +31,7 @@ struct apply_ctx { ...@@ -29,6 +31,7 @@ struct apply_ctx {
zone_tree_t *node_ptrs; /*!< Just pointers to the affected nodes in contents. */ zone_tree_t *node_ptrs; /*!< Just pointers to the affected nodes in contents. */
zone_tree_t *nsec3_ptrs; /*!< The same for NSEC3 nodes. */ zone_tree_t *nsec3_ptrs; /*!< The same for NSEC3 nodes. */
uint32_t flags; uint32_t flags;
pthread_mutex_t *cow_mutex; // pointer to zone_t struct
}; };
typedef struct apply_ctx apply_ctx_t; typedef struct apply_ctx apply_ctx_t;
......
...@@ -127,6 +127,9 @@ int init_base(zone_update_t *update, zone_t *zone, zone_contents_t *old_contents ...@@ -127,6 +127,9 @@ int init_base(zone_update_t *update, zone_t *zone, zone_contents_t *old_contents
return KNOT_ENOMEM; return KNOT_ENOMEM;
} }
pthread_mutex_lock(&zone->cow_lock);
update->a_ctx->cow_mutex = &zone->cow_lock;
int ret = KNOT_EINVAL; int ret = KNOT_EINVAL;
if (flags & UPDATE_INCREMENTAL) { if (flags & UPDATE_INCREMENTAL) {
ret = init_incremental(update, zone, old_contents, flags & UPDATE_JOURNAL); ret = init_incremental(update, zone, old_contents, flags & UPDATE_JOURNAL);
...@@ -134,6 +137,7 @@ int init_base(zone_update_t *update, zone_t *zone, zone_contents_t *old_contents ...@@ -134,6 +137,7 @@ int init_base(zone_update_t *update, zone_t *zone, zone_contents_t *old_contents
ret = init_full(update, zone); ret = init_full(update, zone);
} }
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
pthread_mutex_unlock(&zone->cow_lock);
free(update->a_ctx); free(update->a_ctx);
} }
...@@ -217,6 +221,9 @@ int zone_update_from_contents(zone_update_t *update, zone_t *zone_without_conten ...@@ -217,6 +221,9 @@ int zone_update_from_contents(zone_update_t *update, zone_t *zone_without_conten
return KNOT_ENOMEM; return KNOT_ENOMEM;
} }
pthread_mutex_lock(&update->zone->cow_lock);
update->a_ctx->cow_mutex = &update->zone->cow_lock;
if (flags & UPDATE_INCREMENTAL) { if (flags & UPDATE_INCREMENTAL) {
int ret = changeset_init(&update->change, zone_without_contents->name); int ret = changeset_init(&update->change, zone_without_contents->name);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
...@@ -335,6 +342,9 @@ void zone_update_clear(zone_update_t *update) ...@@ -335,6 +342,9 @@ void zone_update_clear(zone_update_t *update)
update_cleanup(update->a_ctx); update_cleanup(update->a_ctx);
zone_contents_deep_free(update->new_cont); zone_contents_deep_free(update->new_cont);
} }
if (update->a_ctx != NULL && update->a_ctx->cow_mutex != NULL) {
pthread_mutex_unlock(update->a_ctx->cow_mutex);
}
free(update->a_ctx); free(update->a_ctx);
mp_delete(update->mm.ctx); mp_delete(update->mm.ctx);
memset(update, 0, sizeof(*update)); memset(update, 0, sizeof(*update));
......
...@@ -175,6 +175,8 @@ zone_t* zone_new(const knot_dname_t *name) ...@@ -175,6 +175,8 @@ zone_t* zone_new(const knot_dname_t *name)
zone->ddns_queue_size = 0; zone->ddns_queue_size = 0;
init_list(&zone->ddns_queue); init_list(&zone->ddns_queue);
pthread_mutex_init(&zone->cow_lock, NULL);
// Preferred master lock // Preferred master lock
pthread_mutex_init(&zone->preferred_lock, NULL); pthread_mutex_init(&zone->preferred_lock, NULL);
...@@ -213,6 +215,9 @@ void zone_free(zone_t **zone_ptr) ...@@ -213,6 +215,9 @@ void zone_free(zone_t **zone_ptr)
free_ddns_queue(zone); free_ddns_queue(zone);
pthread_mutex_destroy(&zone->ddns_lock); pthread_mutex_destroy(&zone->ddns_lock);
pthread_mutex_lock(&zone->cow_lock);
pthread_mutex_destroy(&zone->cow_lock);
/* Control update. */ /* Control update. */
zone_control_clear(zone); zone_control_clear(zone);
......
...@@ -71,6 +71,9 @@ typedef struct zone ...@@ -71,6 +71,9 @@ typedef struct zone
/*! \brief Control update context. */ /*! \brief Control update context. */
struct zone_update *control_update; struct zone_update *control_update;
/*! \brief Ensue one COW tramsaction on zone's trees at a time. */
pthread_mutex_t cow_lock;
/*! \brief Ptr to journal DB (in struct server) */ /*! \brief Ptr to journal DB (in struct server) */
knot_lmdb_db_t *journaldb; knot_lmdb_db_t *journaldb;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
#include <assert.h> #include <assert.h>
#include <pthread.h>
#include <tap/basic.h> #include <tap/basic.h>
#include <tap/files.h> #include <tap/files.h>
#include <unistd.h> #include <unistd.h>
...@@ -105,9 +106,11 @@ static int test_node_unified(zone_node_t *n1, void *v) ...@@ -105,9 +106,11 @@ static int test_node_unified(zone_node_t *n1, void *v)
return KNOT_EOK; return KNOT_EOK;
} }
static void test_zone_unified(zone_contents_t *z) static void test_zone_unified(zone_t *z)
{ {
zone_tree_apply(z->nodes, test_node_unified, NULL); pthread_mutex_lock(&z->cow_lock);
zone_tree_apply(z->contents->nodes, test_node_unified, NULL);
pthread_mutex_unlock(&z->cow_lock);
} }
void test_full(zone_t *zone, zs_scanner_t *sc) void test_full(zone_t *zone, zs_scanner_t *sc)
...@@ -223,7 +226,7 @@ void test_full(zone_t *zone, zs_scanner_t *sc) ...@@ -223,7 +226,7 @@ void test_full(zone_t *zone, zs_scanner_t *sc)
rrset_present = node_contains_rr(node, &rrset); rrset_present = node_contains_rr(node, &rrset);
ok(ret == KNOT_EOK && rrset_present, "full zone update: commit"); ok(ret == KNOT_EOK && rrset_present, "full zone update: commit");
test_zone_unified(zone->contents); test_zone_unified(zone);
knot_rdataset_clear(&rrset.rrs, NULL); knot_rdataset_clear(&rrset.rrs, NULL);
} }
...@@ -325,7 +328,7 @@ void test_incremental(zone_t *zone, zs_scanner_t *sc) ...@@ -325,7 +328,7 @@ void test_incremental(zone_t *zone, zs_scanner_t *sc)
rrset_present = node_contains_rr(iter_node, &rrset); rrset_present = node_contains_rr(iter_node, &rrset);
ok(ret == KNOT_EOK && rrset_present, "incremental zone update: commit"); ok(ret == KNOT_EOK && rrset_present, "incremental zone update: commit");
test_zone_unified(zone->contents); test_zone_unified(zone);
knot_rdataset_clear(&rrset.rrs, NULL); knot_rdataset_clear(&rrset.rrs, NULL);
} }
......
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