Commit 4d2d5f36 authored by Jan Kadlec's avatar Jan Kadlec

bulk updates: more review remarks, mostly renaming + mm_ctx_t where

missing
parent daa32307
......@@ -424,13 +424,11 @@ static int finalize_updated_zone(zone_contents_t *contents_copy,
return KNOT_EINVAL;
}
int ret = KNOT_EOK;
if (set_nsec3_names) {
ret = zone_contents_adjust_full(contents_copy, NULL, NULL);
return zone_contents_adjust_full(contents_copy, NULL, NULL);
} else {
ret = zone_contents_adjust_pointers(contents_copy);
return zone_contents_adjust_pointers(contents_copy);
}
return ret;
}
/* ------------------------------- API -------------------------------------- */
......
......@@ -63,8 +63,8 @@ static int add_rr_to_list(list_t *l, const knot_rrset_t *rr)
}
/*!< \brief Checks whether RRSet exists in the zone. */
static int check_rrset_exists(zone_update_t *update,
const knot_rrset_t *rrset, uint16_t *rcode)
static int check_rrset_exists(zone_update_t *update, const knot_rrset_t *rrset,
uint16_t *rcode)
{
assert(rrset->type != KNOT_RRTYPE_ANY);
......@@ -296,7 +296,7 @@ static void remove_header_from_changeset(zone_contents_t *z, const knot_rrset_t
static void remove_owner_from_changeset(zone_contents_t *z, const knot_dname_t *owner)
{
zone_node_t *n = (zone_node_t *)zone_contents_find_node(z, owner);
node_free_rrsets(n);
node_free_rrsets(n, NULL);
}
/* --------------------- true/false helper functions ------------------------ */
......@@ -334,8 +334,8 @@ static bool should_replace(const knot_rrset_t *rrset)
}
/*!< \brief Returns true if node will be empty after update application. */
static bool node_empty(const zone_node_t *node, knot_dname_t *owner,
const changeset_t *changeset)
static bool node_will_be_empty(const zone_node_t *node, knot_dname_t *owner,
const changeset_t *changeset)
{
if (node == NULL && name_added(changeset, owner)) {
// Node created in update.
......@@ -528,7 +528,7 @@ static int process_add_cname(const zone_node_t *node,
}
return add_rr_to_chgset(rr, changeset, NULL);
} else if (!node_empty(node, rr->owner, changeset)) {
} else if (!node_will_be_empty(node, rr->owner, changeset)) {
// Other occupied node => ignore.
return KNOT_EOK;
} else {
......
......@@ -18,18 +18,13 @@
#include "common-knot/lists.h"
#include "common/mempool.h"
static bool node_empty(const zone_node_t *node)
{
return node == NULL || node->rrset_count == 0;
}
static int add_to_node(zone_node_t *old_node, const zone_node_t *add_node,
static int add_to_node(zone_node_t *node, const zone_node_t *add_node,
mm_ctx_t *mm)
{
for (uint16_t i = 0; i < add_node->rrset_count; ++i) {
knot_rrset_t rr = node_rrset_at(add_node, i);
if (!knot_rrset_empty(&rr)) {
int ret = node_add_rrset(old_node, &rr, mm);
int ret = node_add_rrset(node, &rr, mm);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -39,13 +34,13 @@ static int add_to_node(zone_node_t *old_node, const zone_node_t *add_node,
return KNOT_EOK;
}
static int rem_from_node(zone_node_t *old_node, const zone_node_t *rem_node,
static int rem_from_node(zone_node_t *node, const zone_node_t *rem_node,
mm_ctx_t *mm)
{
for (uint16_t i = 0; i < rem_node->rrset_count; ++i) {
// Remove each found RR from 'old_node'.
// Remove each found RR from 'node'.
knot_rrset_t rem_rrset = node_rrset_at(rem_node, i);
knot_rdataset_t *to_change = node_rdataset(old_node, rem_rrset.type);
knot_rdataset_t *to_change = node_rdataset(node, rem_rrset.type);
if (to_change) {
// Remove data from synthesized node
int ret = knot_rdataset_subtract(to_change,
......@@ -67,7 +62,6 @@ static int apply_changes_to_node(zone_node_t *synth_node, const zone_node_t *add
if (!node_empty(add_node)) {
int ret = add_to_node(synth_node, add_node, mm);
if (ret != KNOT_EOK) {
node_free(&synth_node, mm);
return ret;
}
}
......@@ -76,7 +70,6 @@ static int apply_changes_to_node(zone_node_t *synth_node, const zone_node_t *add
if (!node_empty(rem_node)) {
int ret = rem_from_node(synth_node, rem_node, mm);
if (ret != KNOT_EOK) {
node_free(&synth_node, mm);
return ret;
}
}
......@@ -84,15 +77,15 @@ static int apply_changes_to_node(zone_node_t *synth_node, const zone_node_t *add
return KNOT_EOK;
}
static int deep_copy_node_data(zone_node_t *node_copy, const zone_node_t *old_node,
static int deep_copy_node_data(zone_node_t *node_copy, const zone_node_t *node,
mm_ctx_t *mm)
{
// Clear space for RRs
node_copy->rrs = NULL;
node_copy->rrset_count = 0;
for (uint16_t i = 0; i < old_node->rrset_count; ++i) {
knot_rrset_t rr = node_rrset_at(old_node, i);
for (uint16_t i = 0; i < node->rrset_count; ++i) {
knot_rrset_t rr = node_rrset_at(node, i);
int ret = node_add_rrset(node_copy, &rr, mm);
if (ret != KNOT_EOK) {
return ret;
......@@ -102,16 +95,16 @@ static int deep_copy_node_data(zone_node_t *node_copy, const zone_node_t *old_no
return KNOT_EOK;
}
static zone_node_t *node_deep_copy(const zone_node_t *old_node, mm_ctx_t *mm)
static zone_node_t *node_deep_copy(const zone_node_t *node, mm_ctx_t *mm)
{
// Shallow copy old node
zone_node_t *synth_node = node_shallow_copy(old_node, mm);
zone_node_t *synth_node = node_shallow_copy(node, mm);
if (synth_node == NULL) {
return NULL;
}
// Deep copy data inside node copy.
int ret = deep_copy_node_data(synth_node, old_node, mm);
int ret = deep_copy_node_data(synth_node, node, mm);
if (ret != KNOT_EOK) {
node_free(&synth_node, mm);
return NULL;
......@@ -169,6 +162,8 @@ const zone_node_t *zone_update_get_node(zone_update_t *update, const knot_dname_
int ret = apply_changes_to_node(synth_node, add_node, rem_node,
&update->mm);
if (ret != KNOT_EOK) {
node_free_rrsets(synth_node, &update->mm);
node_free(synth_node, &update->mm);
return NULL;
}
......@@ -177,8 +172,8 @@ const zone_node_t *zone_update_get_node(zone_update_t *update, const knot_dname_
void zone_update_clear(zone_update_t *update)
{
mp_delete(update->mm.ctx);
memset(&update->mm, 0, sizeof(update->mm));
update->zone = NULL;
update->change = NULL;
if (update) {
mp_delete(update->mm.ctx);
memset(&update, 0, sizeof(*update));
}
}
......@@ -106,7 +106,7 @@ static int zone_contents_destroy_node_rrsets_from_tree(
UNUSED(data);
assert(tnode != NULL);
if (*tnode != NULL) {
node_free_rrsets(*tnode);
node_free_rrsets(*tnode, NULL);
node_free(tnode, NULL);
}
......
......@@ -53,7 +53,7 @@ static int add_rrset_no_merge(zone_node_t *node, const knot_rrset_t *rrset,
return KNOT_EINVAL;
}
const size_t prev_nlen = (node->rrset_count) * sizeof(struct rr_data);
const size_t prev_nlen = node->rrset_count * sizeof(struct rr_data);
const size_t nlen = (node->rrset_count + 1) * sizeof(struct rr_data);
void *p = mm_realloc(mm, node->rrs, nlen, prev_nlen);
if (p == NULL) {
......@@ -107,7 +107,7 @@ zone_node_t *node_new(const knot_dname_t *owner, mm_ctx_t *mm)
return ret;
}
void node_free_rrsets(zone_node_t *node)
void node_free_rrsets(zone_node_t *node, mm_ctx_t *mm)
{
if (node == NULL) {
return;
......@@ -285,3 +285,8 @@ bool node_rrtype_exists(const zone_node_t *node, uint16_t type)
{
return node_rdataset(node, type) != NULL;
}
bool node_empty(const zone_node_t *node)
{
return node == NULL || node->rrset_count == 0;
}
......@@ -86,6 +86,7 @@ enum node_flags {
* \brief Creates and initializes new node structure.
*
* \param owner Node's owner, will be duplicated.
* \param mm Memory context to use.
*
* \return Newly created node or NULL if an error occured.
*/
......@@ -95,9 +96,10 @@ zone_node_t *node_new(const knot_dname_t *owner, mm_ctx_t *mm);
* \brief Destroys allocated data within the node
* structure, but not the node itself.
*
* \param node Node that contains data to be destroyed.
* \param node Node that contains data to be destroyed.
* \param mm Memory context to use.
*/
void node_free_rrsets(zone_node_t *node);
void node_free_rrsets(zone_node_t *node, mm_ctx_t *mm);
/*!
* \brief Destroys the node structure.
......@@ -105,7 +107,8 @@ void node_free_rrsets(zone_node_t *node);
* Does not destroy the data within the node.
* Also sets the given pointer to NULL.
*
* \param node Node to be destroyed.
* \param node Node to be destroyed.
* \param mm Memory context to use.
*/
void node_free(zone_node_t **node, mm_ctx_t *mm);
......@@ -113,6 +116,7 @@ void node_free(zone_node_t **node, mm_ctx_t *mm);
* \brief Creates a shallow copy of node structure, RR data are shared.
*
* \param src Source of the copy.
* \param mm Memory context to use.
*
* \return Copied node if success, NULL otherwise.
*/
......@@ -194,6 +198,16 @@ bool node_rrtype_is_signed(const zone_node_t *node, uint16_t type);
*/
bool node_rrtype_exists(const zone_node_t *node, uint16_t type);
/*!
* \brief Checks whether node is empty. Node is empty when NULL or when no
* RRSets are in it.
*
* \param node Node to check in.
*
* \return True/False.
*/
bool node_empty(const zone_node_t *node);
/* -------------------- Inline RRSet initializations ------------------------ */
/*!
......
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