summaryrefslogtreecommitdiff
path: root/mgmtd/mgmt_history.c
diff options
context:
space:
mode:
Diffstat (limited to 'mgmtd/mgmt_history.c')
-rw-r--r--mgmtd/mgmt_history.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/mgmtd/mgmt_history.c b/mgmtd/mgmt_history.c
index 54eb45fdf4..d4069325ca 100644
--- a/mgmtd/mgmt_history.c
+++ b/mgmtd/mgmt_history.c
@@ -196,23 +196,21 @@ static int mgmt_history_rollback_to_cmt(struct vty *vty,
}
src_ds_ctx = mgmt_ds_get_ctx_by_id(mm, MGMTD_DS_CANDIDATE);
- if (!src_ds_ctx) {
- vty_out(vty, "ERROR: Couldnot access Candidate datastore!\n");
- return -1;
- }
-
- /*
- * Note: Write lock on src_ds is not required. This is already
- * taken in 'conf te'.
- */
dst_ds_ctx = mgmt_ds_get_ctx_by_id(mm, MGMTD_DS_RUNNING);
- if (!dst_ds_ctx) {
- vty_out(vty, "ERROR: Couldnot access Running datastore!\n");
+ assert(src_ds_ctx);
+ assert(dst_ds_ctx);
+
+ ret = mgmt_ds_lock(src_ds_ctx, vty->mgmt_session_id);
+ if (ret != 0) {
+ vty_out(vty,
+ "Failed to lock the DS %u for rollback Reason: %s!\n",
+ MGMTD_DS_RUNNING, strerror(ret));
return -1;
}
- ret = mgmt_ds_write_lock(dst_ds_ctx);
+ ret = mgmt_ds_lock(dst_ds_ctx, vty->mgmt_session_id);
if (ret != 0) {
+ mgmt_ds_unlock(src_ds_ctx);
vty_out(vty,
"Failed to lock the DS %u for rollback Reason: %s!\n",
MGMTD_DS_RUNNING, strerror(ret));
@@ -223,27 +221,30 @@ static int mgmt_history_rollback_to_cmt(struct vty *vty,
ret = mgmt_ds_load_config_from_file(
src_ds_ctx, cmt_info->cmt_json_file, false);
if (ret != 0) {
- mgmt_ds_unlock(dst_ds_ctx);
vty_out(vty,
"Error with parsing the file with error code %d\n",
ret);
- return ret;
+ goto failed_unlock;
}
}
/* Internally trigger a commit-request. */
ret = mgmt_txn_rollback_trigger_cfg_apply(src_ds_ctx, dst_ds_ctx);
if (ret != 0) {
- mgmt_ds_unlock(dst_ds_ctx);
vty_out(vty,
"Error with creating commit apply txn with error code %d\n",
ret);
- return ret;
+ goto failed_unlock;
}
mgmt_history_dump_cmt_record_index();
/*
+ * TODO: Cleanup: the generic TXN code currently checks for rollback
+ * and does the unlock when it completes.
+ */
+
+ /*
* Block the rollback command from returning till the rollback
* is completed. On rollback completion mgmt_history_rollback_complete()
* shall be called to resume the rollback command return to VTYSH.
@@ -251,6 +252,11 @@ static int mgmt_history_rollback_to_cmt(struct vty *vty,
vty->mgmt_req_pending_cmd = "ROLLBACK";
rollback_vty = vty;
return 0;
+
+failed_unlock:
+ mgmt_ds_unlock(src_ds_ctx);
+ mgmt_ds_unlock(dst_ds_ctx);
+ return ret;
}
void mgmt_history_rollback_complete(bool success)