mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-29 23:08:38 +00:00
lib: avoid expensive operations when editing a candidate config
nb_candidate_edit() was calling both the lyd_schema_sort() and lyd_validate() functions whenever a new node was added to the candidate configuration. This was done to ensure the candidate is always ready to be displayed correctly (libyang only creates default child nodes during the validation process, and data nodes aren't guaranteed to be ordered by default). The problem is that the two aforementioned functions are too expensive to be called in the northbound hot path. Instead, it makes more sense to call them only before displaying the configuration (in which case a recursive sort needs to be done). Introduce the nb_cli_show_config_prepare() to achieve that purpose. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
c7c9103b01
commit
5e6a9350c1
@ -1709,6 +1709,8 @@ static int vty_write_config(struct vty *vty)
|
||||
if (host.noconfig)
|
||||
return CMD_SUCCESS;
|
||||
|
||||
nb_cli_show_config_prepare(running_config, false);
|
||||
|
||||
if (vty->type == VTY_TERM) {
|
||||
vty_out(vty, "\nCurrent configuration:\n");
|
||||
vty_out(vty, "!\n");
|
||||
|
@ -516,17 +516,6 @@ int nb_candidate_edit(struct nb_config *candidate,
|
||||
__func__);
|
||||
return NB_ERR;
|
||||
}
|
||||
|
||||
/*
|
||||
* If a new node was created, call lyd_validate() only to create
|
||||
* default child nodes.
|
||||
*/
|
||||
if (dnode) {
|
||||
lyd_schema_sort(dnode, 0);
|
||||
lyd_validate(&dnode,
|
||||
LYD_OPT_CONFIG | LYD_OPT_WHENAUTODEL,
|
||||
ly_native_ctx);
|
||||
}
|
||||
break;
|
||||
case NB_OP_DESTROY:
|
||||
dnode = yang_dnode_get(candidate->dnode, xpath_edit);
|
||||
|
@ -421,6 +421,23 @@ static struct lyd_node *ly_iter_next_up(const struct lyd_node *elem)
|
||||
return elem->parent;
|
||||
}
|
||||
|
||||
/* Prepare the configuration for display. */
|
||||
void nb_cli_show_config_prepare(struct nb_config *config, bool with_defaults)
|
||||
{
|
||||
lyd_schema_sort(config->dnode, 1);
|
||||
|
||||
/*
|
||||
* When "with-defaults" is used, call lyd_validate() only to create
|
||||
* default child nodes, ignoring any possible validation error. This
|
||||
* doesn't need to be done when displaying the running configuration
|
||||
* since it's always fully validated.
|
||||
*/
|
||||
if (with_defaults && config != running_config)
|
||||
(void)lyd_validate(&config->dnode,
|
||||
LYD_OPT_CONFIG | LYD_OPT_WHENAUTODEL,
|
||||
ly_native_ctx);
|
||||
}
|
||||
|
||||
void nb_cli_show_dnode_cmds(struct vty *vty, struct lyd_node *root,
|
||||
bool with_defaults)
|
||||
{
|
||||
@ -513,6 +530,8 @@ static int nb_cli_show_config(struct vty *vty, struct nb_config *config,
|
||||
struct yang_translator *translator,
|
||||
bool with_defaults)
|
||||
{
|
||||
nb_cli_show_config_prepare(config, with_defaults);
|
||||
|
||||
switch (format) {
|
||||
case NB_CFG_FMT_CMDS:
|
||||
nb_cli_show_config_cmds(vty, config, with_defaults);
|
||||
|
@ -109,6 +109,8 @@ extern void nb_cli_show_dnode_cmds(struct vty *vty, struct lyd_node *dnode,
|
||||
bool show_defaults);
|
||||
|
||||
/* Prototypes of internal functions. */
|
||||
extern void nb_cli_show_config_prepare(struct nb_config *config,
|
||||
bool with_defaults);
|
||||
extern void nb_cli_confirmed_commit_clean(struct vty *vty);
|
||||
extern int nb_cli_confirmed_commit_rollback(struct vty *vty);
|
||||
extern void nb_cli_install_default(int node);
|
||||
|
Loading…
Reference in New Issue
Block a user