Commit 0e67ac5d authored by Dominik Taborsky's avatar Dominik Taborsky

zone-api: get rid of RCU in zone_update, move contents switch.

parent 33cf8b64
......@@ -154,7 +154,8 @@ static int process_normal(zone_t *zone, list_t *requests)
}
// Apply changes.
ret = zone_update_commit(&up);
zone_contents_t *new_contents = NULL;
ret = zone_update_commit(&up, &new_contents);
zone_update_clear(&up);
if (ret != KNOT_EOK) {
if (ret == KNOT_ETTL) {
......@@ -165,6 +166,22 @@ static int process_normal(zone_t *zone, list_t *requests)
return ret;
}
/* If there is anything to change */
if (new_contents) {
/* Temporarily unlock locked configuration. */
rcu_read_unlock();
/* Switch zone contents. */
zone_contents_t *old_contents = zone_switch_contents(zone, new_contents);
/* Sync RCU. */
synchronize_rcu();
rcu_read_lock();
/* Clear obsolete zone contents. */
update_free_zone(&old_contents);
}
/* Sync zonefile immediately if configured. */
conf_val_t val = conf_zone_get(conf(), C_ZONEFILE_SYNC, zone->name);
if (conf_int(&val) == 0) {
......
......@@ -24,8 +24,6 @@
#include "libknot/internal/lists.h"
#include "libknot/internal/mempool.h"
#include <urcu.h>
static int add_to_node(zone_node_t *node, const zone_node_t *add_node,
mm_ctx_t *mm)
{
......@@ -389,7 +387,7 @@ static int set_new_soa(zone_update_t *update)
return KNOT_EOK;
}
static int commit_incremental(zone_update_t *update)
static int commit_incremental(zone_update_t *update, zone_contents_t **contents_out)
{
assert(update);
......@@ -439,28 +437,18 @@ static int commit_incremental(zone_update_t *update)
return ret;
}
/* Temporarily unlock locked configuration. */
rcu_read_unlock();
// Switch zone contents.
zone_contents_t *old_contents = zone_switch_contents(update->zone, new_contents);
synchronize_rcu();
rcu_read_lock();
// Clear obsolete zone contents
update_free_zone(&old_contents);
update_cleanup(&update->change);
changeset_clear(&update->change);
*contents_out = new_contents;
return KNOT_EOK;
}
int zone_update_commit(zone_update_t *update)
int zone_update_commit(zone_update_t *update, zone_contents_t **contents_out)
{
if (update->flags & UPDATE_INCREMENTAL) {
return commit_incremental(update);
return commit_incremental(update, contents_out);
}
return KNOT_ENOTSUP;
......
......@@ -140,11 +140,12 @@ int zone_update_remove(zone_update_t *update, const knot_rrset_t *rrset);
/*!
* \brief Commits all changes to the zone, signs it, saves changes to journal.
*
* \param update Zone update.
* \param update Zone update.
* \param contents_out Where to store the resulting zone contents pointer.
*
* \return KNOT_E*
*/
int zone_update_commit(zone_update_t *update);
int zone_update_commit(zone_update_t *update, zone_contents_t **contents_out);
/*!
* \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