summaryrefslogtreecommitdiff
path: root/mgmtd/mgmt_txn.c
diff options
context:
space:
mode:
Diffstat (limited to 'mgmtd/mgmt_txn.c')
-rw-r--r--mgmtd/mgmt_txn.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/mgmtd/mgmt_txn.c b/mgmtd/mgmt_txn.c
index df2a1d852d..35d67e247e 100644
--- a/mgmtd/mgmt_txn.c
+++ b/mgmtd/mgmt_txn.c
@@ -49,7 +49,6 @@ struct mgmt_set_cfg_req {
enum mgmt_commit_phase {
MGMTD_COMMIT_PHASE_PREPARE_CFG = 0,
MGMTD_COMMIT_PHASE_TXN_CREATE,
- MGMTD_COMMIT_PHASE_SEND_CFG,
MGMTD_COMMIT_PHASE_APPLY_CFG,
MGMTD_COMMIT_PHASE_TXN_DELETE,
MGMTD_COMMIT_PHASE_MAX
@@ -62,8 +61,6 @@ static inline const char *mgmt_commit_phase2str(enum mgmt_commit_phase cmt_phase
return "PREP-CFG";
case MGMTD_COMMIT_PHASE_TXN_CREATE:
return "CREATE-TXN";
- case MGMTD_COMMIT_PHASE_SEND_CFG:
- return "SEND-CFG";
case MGMTD_COMMIT_PHASE_APPLY_CFG:
return "APPLY-CFG";
case MGMTD_COMMIT_PHASE_TXN_DELETE:
@@ -105,6 +102,7 @@ struct mgmt_commit_cfg_req {
uint8_t abort : 1;
uint8_t implicit : 1;
uint8_t rollback : 1;
+ uint8_t init : 1;
/* Track commit phases */
enum mgmt_commit_phase phase;
@@ -750,6 +748,14 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn,
mgmt_history_rollback_complete(success);
}
+ if (txn->commit_cfg_req->req.commit_cfg.init) {
+ /*
+ * This is the backend init request.
+ * We need to unlock the running datastore.
+ */
+ mgmt_ds_unlock(txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx);
+ }
+
txn->commit_cfg_req->req.commit_cfg.cmt_stats = NULL;
mgmt_txn_req_free(&txn->commit_cfg_req);
@@ -1178,13 +1184,10 @@ static int mgmt_txn_send_be_cfg_data(struct mgmt_txn_ctx *txn,
cmtcfg_req->cmt_stats->last_num_cfgdata_reqs++;
}
- cmtcfg_req->be_phase[adapter->id] = MGMTD_COMMIT_PHASE_SEND_CFG;
-
/*
- * This could be the last Backend Client to send CFGDATA_CREATE_REQ to.
- * Try moving the commit to next phase.
+ * We don't advance the phase here, instead that is driven by the
+ * cfg_reply.
*/
- mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req);
return 0;
}
@@ -1385,24 +1388,6 @@ static void mgmt_txn_process_commit_cfg(struct event *thread)
*/
mgmt_txn_send_be_txn_create(txn);
break;
- case MGMTD_COMMIT_PHASE_SEND_CFG:
- if (mm->perf_stats_en)
- gettimeofday(&cmtcfg_req->cmt_stats->send_cfg_start,
- NULL);
- /*
- * All CFGDATA_CREATE_REQ should have been sent to
- * Backend by now.
- */
-#ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED
- __dbg("txn-id: %" PRIu64 " session-id: %" PRIu64
- " trigger sending CFG_VALIDATE_REQ to all backend clients",
- txn->txn_id, txn->session_id);
-#else /* ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED */
- __dbg("txn-id: %" PRIu64 " session-id: %" PRIu64
- " trigger sending CFG_APPLY_REQ to all backend clients",
- txn->txn_id, txn->session_id);
-#endif /* ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED */
- break;
case MGMTD_COMMIT_PHASE_APPLY_CFG:
if (mm->perf_stats_en)
gettimeofday(&cmtcfg_req->cmt_stats->apply_cfg_start,
@@ -2081,15 +2066,26 @@ int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter,
struct mgmt_commit_cfg_req *cmtcfg_req;
static struct mgmt_commit_stats dummy_stats;
struct nb_config_cbs *adapter_cfgs = NULL;
+ struct mgmt_ds_ctx *ds_ctx;
memset(&dummy_stats, 0, sizeof(dummy_stats));
if (connect) {
- /* Get config for this single backend client */
+ ds_ctx = mgmt_ds_get_ctx_by_id(mm, MGMTD_DS_RUNNING);
+ assert(ds_ctx);
+ /*
+ * Lock the running datastore to prevent any changes while we
+ * are initializing the backend.
+ */
+ if (mgmt_ds_lock(ds_ctx, 0) != 0)
+ return -1;
+
+ /* Get config for this single backend client */
mgmt_be_get_adapter_config(adapter, &adapter_cfgs);
if (!adapter_cfgs || RB_EMPTY(nb_config_cbs, adapter_cfgs)) {
SET_FLAG(adapter->flags,
MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED);
+ mgmt_ds_unlock(ds_ctx);
return 0;
}
@@ -2101,6 +2097,7 @@ int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter,
if (!txn) {
__log_err("Failed to create CONFIG Transaction for downloading CONFIGs for client '%s'",
adapter->name);
+ mgmt_ds_unlock(ds_ctx);
nb_config_diff_del_changes(adapter_cfgs);
return -1;
}
@@ -2114,10 +2111,11 @@ int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter,
txn_req = mgmt_txn_req_alloc(txn, 0, MGMTD_TXN_PROC_COMMITCFG);
txn_req->req.commit_cfg.src_ds_id = MGMTD_DS_NONE;
txn_req->req.commit_cfg.src_ds_ctx = 0;
- txn_req->req.commit_cfg.dst_ds_id = MGMTD_DS_NONE;
- txn_req->req.commit_cfg.dst_ds_ctx = 0;
+ txn_req->req.commit_cfg.dst_ds_id = MGMTD_DS_RUNNING;
+ txn_req->req.commit_cfg.dst_ds_ctx = ds_ctx;
txn_req->req.commit_cfg.validate_only = false;
txn_req->req.commit_cfg.abort = false;
+ txn_req->req.commit_cfg.init = true;
txn_req->req.commit_cfg.cmt_stats = &dummy_stats;
txn_req->req.commit_cfg.cfg_chgs = adapter_cfgs;