Commit 0067db2a authored by Dominik Taborsky's avatar Dominik Taborsky

zone_update: move RCU sync to zone_update_commit, cleanup

parent 5fc8ff08
......@@ -15,7 +15,6 @@
*/
#include <sys/socket.h>
#include <urcu.h>
#include "dnssec/random.h"
#include "knot/common/log.h"
......@@ -150,8 +149,7 @@ static int process_normal(conf_t *conf, zone_t *zone, list_t *requests)
}
// Apply changes.
zone_contents_t *new_contents = NULL;
ret = zone_update_commit(conf, &up, &new_contents);
ret = zone_update_commit(conf, &up);
if (ret != KNOT_EOK) {
if (ret == KNOT_ETTL) {
set_rcodes(requests, KNOT_RCODE_REFUSED);
......@@ -161,18 +159,6 @@ static int process_normal(conf_t *conf, zone_t *zone, list_t *requests)
return ret;
}
/* If there is anything to change */
if (new_contents) {
/* Switch zone contents. */
zone_contents_t *old_contents = zone_switch_contents(zone, new_contents);
/* Sync RCU. */
synchronize_rcu();
/* Clear obsolete zone contents. */
update_free_zone(&old_contents);
}
zone_update_clear(&up);
/* Sync zonefile immediately if configured. */
......
......@@ -22,6 +22,8 @@
#include "contrib/ucw/lists.h"
#include "contrib/ucw/mempool.h"
#include <urcu.h>
static int add_to_node(zone_node_t *node, const zone_node_t *add_node,
knot_mm_t *mm)
{
......@@ -254,8 +256,11 @@ const knot_rdataset_t *zone_update_to(zone_update_t *update)
void zone_update_clear(zone_update_t *update)
{
if (update) {
update_cleanup(&update->a_ctx);
changeset_clear(&update->change);
if (update->flags & UPDATE_INCREMENTAL) {
/* Revert any changes on error, do nothing on success. */
update_rollback(&update->a_ctx);
changeset_clear(&update->change);
}
mp_delete(update->mm.ctx);
memset(update, 0, sizeof(*update));
}
......@@ -444,13 +449,39 @@ static int commit_incremental(conf_t *conf, zone_update_t *update, zone_contents
return KNOT_EOK;
}
int zone_update_commit(conf_t *conf, zone_update_t *update, zone_contents_t **contents_out)
int zone_update_commit(conf_t *conf, zone_update_t *update)
{
if (!conf || !update) {
return KNOT_EINVAL;
}
int ret = KNOT_EOK;
zone_contents_t *new_contents = NULL;
if (update->flags & UPDATE_INCREMENTAL) {
return commit_incremental(conf, update, contents_out);
ret = commit_incremental(conf, update, &new_contents);
if (ret != KNOT_EOK) {
return ret;
}
} else {
return KNOT_ENOTSUP;
}
return KNOT_ENOTSUP;
/* If there is anything to change */
if (new_contents) {
/* Switch zone contents. */
zone_contents_t *old_contents = zone_switch_contents(update->zone, new_contents);
/* Sync RCU. */
synchronize_rcu();
if (update->flags & UPDATE_INCREMENTAL) {
update_cleanup(&update->a_ctx);
update_free_zone(&old_contents);
changeset_clear(&update->change);
}
}
return KNOT_EOK;
}
bool zone_update_no_change(zone_update_t *up)
......
......@@ -142,11 +142,10 @@ int zone_update_remove(zone_update_t *update, const knot_rrset_t *rrset);
*
* \param conf Configuration.
* \param update Zone update.
* \param contents_out Where to store the resulting zone contents pointer.
*
* \return KNOT_E*
*/
int zone_update_commit(conf_t *conf, zone_update_t *update, zone_contents_t **contents_out);
int zone_update_commit(conf_t *conf, zone_update_t *update);
/*!
* \brief Returns bool whether there are any changes at all.
......
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