Skip to content

Commit

Permalink
Merge pull request #14544 from idryzhov/mgmt-scratch-buffer
Browse files Browse the repository at this point in the history
mgmt: delete candidate scratch buffer
  • Loading branch information
donaldsharp authored Nov 8, 2023
2 parents fb9a27b + a962f29 commit 85a80ba
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 103 deletions.
68 changes: 1 addition & 67 deletions lib/northbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,14 @@ struct nb_config *nb_config_new(struct lyd_node *dnode)
config->dnode = yang_dnode_new(ly_native_ctx, true);
config->version = 0;

RB_INIT(nb_config_cbs, &config->cfg_chgs);

return config;
}

void nb_config_free(struct nb_config *config)
{
if (config->dnode)
yang_dnode_free(config->dnode);
nb_config_diff_del_changes(&config->cfg_chgs);

XFREE(MTYPE_NB_CONFIG, config);
}

Expand All @@ -326,8 +324,6 @@ struct nb_config *nb_config_dup(const struct nb_config *config)
dup->dnode = yang_dnode_dup(config->dnode);
dup->version = config->version;

RB_INIT(nb_config_cbs, &dup->cfg_chgs);

return dup;
}

Expand Down Expand Up @@ -753,65 +749,6 @@ int nb_candidate_edit(struct nb_config *candidate,
return NB_OK;
}

static void nb_update_candidate_changes(struct nb_config *candidate,
struct nb_cfg_change *change,
uint32_t *seq)
{
enum nb_operation oper = change->operation;
char *xpath = change->xpath;
struct lyd_node *root = NULL;
struct lyd_node *dnode;
struct nb_config_cbs *cfg_chgs = &candidate->cfg_chgs;
int op;

switch (oper) {
case NB_OP_CREATE:
case NB_OP_MODIFY:
root = yang_dnode_get(candidate->dnode, xpath);
break;
case NB_OP_DESTROY:
root = yang_dnode_get(running_config->dnode, xpath);
/* code */
break;
case NB_OP_MOVE:
case NB_OP_PRE_VALIDATE:
case NB_OP_APPLY_FINISH:
case NB_OP_GET_ELEM:
case NB_OP_GET_NEXT:
case NB_OP_GET_KEYS:
case NB_OP_LOOKUP_ENTRY:
case NB_OP_RPC:
break;
default:
assert(!"non-enum value, invalid");
}

if (!root)
return;

LYD_TREE_DFS_BEGIN (root, dnode) {
op = nb_lyd_diff_get_op(dnode);
switch (op) {
case 'c': /* create */
nb_config_diff_created(dnode, seq, cfg_chgs);
LYD_TREE_DFS_continue = 1;
break;
case 'd': /* delete */
nb_config_diff_deleted(dnode, seq, cfg_chgs);
LYD_TREE_DFS_continue = 1;
break;
case 'r': /* replace */
nb_config_diff_add_change(cfg_chgs, NB_OP_MODIFY, seq,
dnode);
break;
case 'n': /* none */
default:
break;
}
LYD_TREE_DFS_END(root, dnode);
}
}

static bool nb_is_operation_allowed(struct nb_node *nb_node,
struct nb_cfg_change *change)
{
Expand All @@ -829,8 +766,6 @@ void nb_candidate_edit_config_changes(
size_t num_cfg_changes, const char *xpath_base, const char *curr_xpath,
int xpath_index, char *err_buf, int err_bufsize, bool *error)
{
uint32_t seq = 0;

if (error)
*error = false;

Expand Down Expand Up @@ -900,7 +835,6 @@ void nb_candidate_edit_config_changes(
*error = true;
continue;
}
nb_update_candidate_changes(candidate_config, change, &seq);
}

if (error && *error) {
Expand Down
1 change: 0 additions & 1 deletion lib/northbound.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ struct nb_transaction {
struct nb_config {
struct lyd_node *dnode;
uint32_t version;
struct nb_config_cbs cfg_chgs;
};

/* Callback function used by nb_oper_data_iterate(). */
Expand Down
16 changes: 0 additions & 16 deletions mgmtd/mgmt_ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ static int mgmt_ds_replace_dst_with_src_ds(struct mgmt_ds_ctx *src,
dst->root.dnode_root = yang_dnode_dup(src->root.dnode_root);
}

if (src->ds_id == MGMTD_DS_CANDIDATE) {
/*
* Drop the changes in scratch-buffer.
*/
MGMTD_DS_DBG("Emptying Candidate Scratch buffer!");
nb_config_diff_del_changes(&src->root.cfg_root->cfg_chgs);
}

return 0;
}

Expand All @@ -126,14 +118,6 @@ static int mgmt_ds_merge_src_with_dst_ds(struct mgmt_ds_ctx *src,
return ret;
}

if (src->ds_id == MGMTD_DS_CANDIDATE) {
/*
* Drop the changes in scratch-buffer.
*/
MGMTD_DS_DBG("Emptying Candidate Scratch buffer!");
nb_config_diff_del_changes(&src->root.cfg_root->cfg_chgs);
}

return 0;
}

Expand Down
24 changes: 5 additions & 19 deletions mgmtd/mgmt_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,25 +1193,11 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn)
goto mgmt_txn_prepare_config_done;
}

/*
* Check for diffs from scratch buffer. If found empty
* get the diff from Candidate DS itself.
*/
cfg_chgs = &nb_config->cfg_chgs;
if (RB_EMPTY(nb_config_cbs, cfg_chgs)) {
/*
* This could be the case when the config is directly
* loaded onto the candidate DS from a file. Get the
* diff from a full comparison of the candidate and
* running DSs.
*/
nb_config_diff(mgmt_ds_get_nb_config(
txn->commit_cfg_req->req.commit_cfg
.dst_ds_ctx),
nb_config, &changes);
cfg_chgs = &changes;
del_cfg_chgs = true;
}
nb_config_diff(mgmt_ds_get_nb_config(txn->commit_cfg_req->req.commit_cfg
.dst_ds_ctx),
nb_config, &changes);
cfg_chgs = &changes;
del_cfg_chgs = true;

if (RB_EMPTY(nb_config_cbs, cfg_chgs)) {
/*
Expand Down

0 comments on commit 85a80ba

Please sign in to comment.