diff options
| author | Jafar Al-Gharaibeh <jafar@atcorp.com> | 2023-06-25 10:22:34 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-25 10:22:34 -0500 | 
| commit | 64ef7364c6c4ef8a0db7f47fdd9de4e451763702 (patch) | |
| tree | 13878218d483ef79438e03ce6375969878b6ea02 /mgmtd/mgmt_history.c | |
| parent | 0ea4297e3c3e55d3894820f9359215b6957fa213 (diff) | |
| parent | 6dccdb9b0d1b3bbf04196f712ebccf9a8f39e47e (diff) | |
Merge pull request #13846 from LabNConsulting/chopps/backport-13795frr-9.0-rc
backport of #13795
Diffstat (limited to 'mgmtd/mgmt_history.c')
| -rw-r--r-- | mgmtd/mgmt_history.c | 38 | 
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)  | 
