Commit 00b6db41 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

apply: COW mutex -> semaphore, cause freed by RCU in other thread

parent 13376937
...@@ -420,7 +420,7 @@ void update_cleanup(apply_ctx_t *ctx) ...@@ -420,7 +420,7 @@ void update_cleanup(apply_ctx_t *ctx)
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) { if (ctx->cow_mutex != NULL) {
pthread_mutex_unlock(ctx->cow_mutex); sem_post(ctx->cow_mutex);
} }
} }
...@@ -449,7 +449,7 @@ void update_rollback(apply_ctx_t *ctx) ...@@ -449,7 +449,7 @@ void update_rollback(apply_ctx_t *ctx)
} }
if (ctx->cow_mutex != NULL) { if (ctx->cow_mutex != NULL) {
pthread_mutex_unlock(ctx->cow_mutex); sem_post(ctx->cow_mutex);
} }
free(ctx->contents->nodes); free(ctx->contents->nodes);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#pragma once #pragma once
#include <pthread.h> #include <semaphore.h>
#include "knot/zone/contents.h" #include "knot/zone/contents.h"
#include "knot/updates/changesets.h" #include "knot/updates/changesets.h"
...@@ -31,7 +31,7 @@ struct apply_ctx { ...@@ -31,7 +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 sem_t *cow_mutex; // pointer to zone_t struct
}; };
typedef struct apply_ctx apply_ctx_t; typedef struct apply_ctx apply_ctx_t;
......
...@@ -127,7 +127,7 @@ int init_base(zone_update_t *update, zone_t *zone, zone_contents_t *old_contents ...@@ -127,7 +127,7 @@ 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); sem_wait(&zone->cow_lock);
update->a_ctx->cow_mutex = &zone->cow_lock; update->a_ctx->cow_mutex = &zone->cow_lock;
int ret = KNOT_EINVAL; int ret = KNOT_EINVAL;
...@@ -137,7 +137,7 @@ int init_base(zone_update_t *update, zone_t *zone, zone_contents_t *old_contents ...@@ -137,7 +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); sem_post(&zone->cow_lock);
free(update->a_ctx); free(update->a_ctx);
} }
...@@ -221,7 +221,7 @@ int zone_update_from_contents(zone_update_t *update, zone_t *zone_without_conten ...@@ -221,7 +221,7 @@ 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); sem_wait(&update->zone->cow_lock);
update->a_ctx->cow_mutex = &update->zone->cow_lock; update->a_ctx->cow_mutex = &update->zone->cow_lock;
if (flags & UPDATE_INCREMENTAL) { if (flags & UPDATE_INCREMENTAL) {
...@@ -343,7 +343,7 @@ void zone_update_clear(zone_update_t *update) ...@@ -343,7 +343,7 @@ void zone_update_clear(zone_update_t *update)
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) { if (update->a_ctx != NULL && update->a_ctx->cow_mutex != NULL) {
pthread_mutex_unlock(update->a_ctx->cow_mutex); sem_post(update->a_ctx->cow_mutex);
} }
free(update->a_ctx); free(update->a_ctx);
mp_delete(update->mm.ctx); mp_delete(update->mm.ctx);
......
...@@ -175,7 +175,7 @@ zone_t* zone_new(const knot_dname_t *name) ...@@ -175,7 +175,7 @@ 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); sem_init(&zone->cow_lock, 1, 1);
// Preferred master lock // Preferred master lock
pthread_mutex_init(&zone->preferred_lock, NULL); pthread_mutex_init(&zone->preferred_lock, NULL);
...@@ -215,8 +215,8 @@ void zone_free(zone_t **zone_ptr) ...@@ -215,8 +215,8 @@ 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); sem_wait(&zone->cow_lock);
pthread_mutex_destroy(&zone->cow_lock); sem_destroy(&zone->cow_lock);
/* Control update. */ /* Control update. */
zone_control_clear(zone); zone_control_clear(zone);
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#pragma once #pragma once
#include <semaphore.h>
#include "knot/conf/conf.h" #include "knot/conf/conf.h"
#include "knot/conf/confio.h" #include "knot/conf/confio.h"
#include "knot/journal/journal_basic.h" #include "knot/journal/journal_basic.h"
...@@ -72,7 +74,7 @@ typedef struct zone ...@@ -72,7 +74,7 @@ typedef struct zone
struct zone_update *control_update; struct zone_update *control_update;
/*! \brief Ensue one COW tramsaction on zone's trees at a time. */ /*! \brief Ensue one COW tramsaction on zone's trees at a time. */
pthread_mutex_t cow_lock; sem_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;
......
...@@ -108,9 +108,9 @@ static int test_node_unified(zone_node_t *n1, void *v) ...@@ -108,9 +108,9 @@ static int test_node_unified(zone_node_t *n1, void *v)
static void test_zone_unified(zone_t *z) static void test_zone_unified(zone_t *z)
{ {
pthread_mutex_lock(&z->cow_lock); sem_wait(&z->cow_lock);
zone_tree_apply(z->contents->nodes, test_node_unified, NULL); zone_tree_apply(z->contents->nodes, test_node_unified, NULL);
pthread_mutex_unlock(&z->cow_lock); sem_post(&z->cow_lock);
} }
void test_full(zone_t *zone, zs_scanner_t *sc) void test_full(zone_t *zone, zs_scanner_t *sc)
......
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