summaryrefslogtreecommitdiff
path: root/lib/northbound.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/northbound.c')
-rw-r--r--lib/northbound.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/northbound.c b/lib/northbound.c
index 11007e4309..18500a8bd2 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -57,6 +57,8 @@ static struct {
const void *owner_user;
} running_config_mgmt_lock;
+/* Knob to record config transaction */
+static bool nb_db_enabled;
/*
* Global lock used to prevent multiple configuration transactions from
* happening concurrently.
@@ -680,8 +682,12 @@ int nb_candidate_commit_prepare(struct nb_context *context,
RB_INIT(nb_config_cbs, &changes);
nb_config_diff(running_config, candidate, &changes);
- if (RB_EMPTY(nb_config_cbs, &changes))
+ if (RB_EMPTY(nb_config_cbs, &changes)) {
+ snprintf(
+ errmsg, errmsg_len,
+ "No changes to apply were found during preparation phase");
return NB_ERR_NO_CHANGES;
+ }
if (nb_candidate_validate_code(context, candidate, &changes, errmsg,
errmsg_len)
@@ -707,30 +713,28 @@ int nb_candidate_commit_prepare(struct nb_context *context,
errmsg_len);
}
-void nb_candidate_commit_abort(struct nb_transaction *transaction)
+void nb_candidate_commit_abort(struct nb_transaction *transaction, char *errmsg,
+ size_t errmsg_len)
{
- char errmsg[BUFSIZ] = {0};
-
(void)nb_transaction_process(NB_EV_ABORT, transaction, errmsg,
- sizeof(errmsg));
+ errmsg_len);
nb_transaction_free(transaction);
}
void nb_candidate_commit_apply(struct nb_transaction *transaction,
- bool save_transaction, uint32_t *transaction_id)
+ bool save_transaction, uint32_t *transaction_id,
+ char *errmsg, size_t errmsg_len)
{
- char errmsg[BUFSIZ] = {0};
-
(void)nb_transaction_process(NB_EV_APPLY, transaction, errmsg,
- sizeof(errmsg));
- nb_transaction_apply_finish(transaction, errmsg, sizeof(errmsg));
+ errmsg_len);
+ nb_transaction_apply_finish(transaction, errmsg, errmsg_len);
/* Replace running by candidate. */
transaction->config->version++;
nb_config_replace(running_config, transaction->config, true);
/* Record transaction. */
- if (save_transaction
+ if (save_transaction && nb_db_enabled
&& nb_db_transaction_save(transaction, transaction_id) != NB_OK)
flog_warn(EC_LIB_NB_TRANSACTION_RECORD_FAILED,
"%s: failed to record transaction", __func__);
@@ -754,9 +758,9 @@ int nb_candidate_commit(struct nb_context *context, struct nb_config *candidate,
*/
if (ret == NB_OK)
nb_candidate_commit_apply(transaction, save_transaction,
- transaction_id);
+ transaction_id, errmsg, errmsg_len);
else if (transaction != NULL)
- nb_candidate_commit_abort(transaction);
+ nb_candidate_commit_abort(transaction, errmsg, errmsg_len);
return ret;
}
@@ -2214,7 +2218,7 @@ static void nb_load_callbacks(const struct frr_yang_module_info *module)
void nb_init(struct thread_master *tm,
const struct frr_yang_module_info *const modules[],
- size_t nmodules)
+ size_t nmodules, bool db_enabled)
{
unsigned int errors = 0;
@@ -2239,6 +2243,8 @@ void nb_init(struct thread_master *tm,
exit(1);
}
+ nb_db_enabled = db_enabled;
+
/* Create an empty running configuration. */
running_config = nb_config_new(NULL);
running_config_entries = hash_create(running_config_entry_key_make,