Skip to content

Commit 8eb69b5

Browse files
committed
mgmtd: normalize argument order to copy(dst, src)
Having just completed a code audit during RCA, the fact that we have 2 different argument orders for the related datastore copying functions was unnecessary and super confusing. Fix this code-maintenance/comprehension mistake and move the newer mgmtd copy routines to use the same arg order as the pre-existing underlying northbound copy functions (i.e., use `copy(dst, src)`) Signed-off-by: Christian Hopps <chopps@labn.net>
1 parent b12b4c2 commit 8eb69b5

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

mgmtd/mgmt_ds.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ static int mgmt_ds_dump_in_memory(struct mgmt_ds_ctx *ds_ctx,
7474
return 0;
7575
}
7676

77-
static int mgmt_ds_replace_dst_with_src_ds(struct mgmt_ds_ctx *src,
78-
struct mgmt_ds_ctx *dst)
77+
static int __dscopy(struct mgmt_ds_ctx *dst, struct mgmt_ds_ctx *src)
7978
{
8079
if (!src || !dst)
8180
return -1;
@@ -95,8 +94,7 @@ static int mgmt_ds_replace_dst_with_src_ds(struct mgmt_ds_ctx *src,
9594
return 0;
9695
}
9796

98-
static int mgmt_ds_merge_src_with_dst_ds(struct mgmt_ds_ctx *src,
99-
struct mgmt_ds_ctx *dst)
97+
static int __dsmerge(struct mgmt_ds_ctx *dst, struct mgmt_ds_ctx *src)
10098
{
10199
int ret;
102100

@@ -251,14 +249,13 @@ void mgmt_ds_unlock(struct mgmt_ds_ctx *ds_ctx)
251249
ds_ctx->locked = 0;
252250
}
253251

254-
int mgmt_ds_copy_dss(struct mgmt_ds_ctx *src_ds_ctx,
255-
struct mgmt_ds_ctx *dst_ds_ctx, bool updt_cmt_rec)
252+
int mgmt_ds_copy_dss(struct mgmt_ds_ctx *dst, struct mgmt_ds_ctx *src, bool updt_cmt_rec)
256253
{
257-
if (mgmt_ds_replace_dst_with_src_ds(src_ds_ctx, dst_ds_ctx) != 0)
254+
if (__dscopy(dst, src) != 0)
258255
return -1;
259256

260-
if (updt_cmt_rec && dst_ds_ctx->ds_id == MGMTD_DS_RUNNING)
261-
mgmt_history_new_record(dst_ds_ctx);
257+
if (updt_cmt_rec && dst->ds_id == MGMTD_DS_RUNNING)
258+
mgmt_history_new_record(dst);
262259

263260
return 0;
264261
}
@@ -416,9 +413,9 @@ int mgmt_ds_load_config_from_file(struct mgmt_ds_ctx *dst,
416413
parsed.ds_id = dst->ds_id;
417414

418415
if (merge)
419-
mgmt_ds_merge_src_with_dst_ds(&parsed, dst);
416+
__dsmerge(dst, &parsed);
420417
else
421-
mgmt_ds_replace_dst_with_src_ds(&parsed, dst);
418+
__dscopy(dst, &parsed);
422419

423420
nb_config_free(parsed.root.cfg_root);
424421

mgmtd/mgmt_ds.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,19 @@ extern void mgmt_ds_unlock(struct mgmt_ds_ctx *ds_ctx);
196196
/*
197197
* Copy from source to destination datastore.
198198
*
199-
* src_ds
200-
* Source datastore handle (ds to be copied from).
201-
*
202-
* dst_ds
199+
* dst
203200
* Destination datastore handle (ds to be copied to).
204201
*
202+
* src
203+
* Source datastore handle (ds to be copied from).
204+
*
205205
* update_cmd_rec
206206
* TRUE if need to update commit record, FALSE otherwise.
207207
*
208208
* Returns:
209209
* 0 on success, -1 on failure.
210210
*/
211-
extern int mgmt_ds_copy_dss(struct mgmt_ds_ctx *src_ds_ctx,
212-
struct mgmt_ds_ctx *dst_ds_ctx,
213-
bool update_cmt_rec);
211+
extern int mgmt_ds_copy_dss(struct mgmt_ds_ctx *dst, struct mgmt_ds_ctx *src, bool update_cmt_rec);
214212

215213
/*
216214
* Fetch northbound configuration for a given datastore context.

mgmtd/mgmt_txn.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -764,17 +764,15 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn,
764764
!txn->commit_cfg_req->req.commit_cfg.rollback);
765765

766766
/*
767-
* Successful commit: Merge Src DS into Dst DS if and only if
767+
* Successful commit: Copy Src DS to Dst DS if and only if
768768
* this was not a validate-only or abort request.
769769
*/
770770
if ((txn->session_id &&
771771
!txn->commit_cfg_req->req.commit_cfg.validate_only &&
772772
!txn->commit_cfg_req->req.commit_cfg.abort) ||
773773
txn->commit_cfg_req->req.commit_cfg.rollback) {
774-
mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg
775-
.src_ds_ctx,
776-
txn->commit_cfg_req->req.commit_cfg
777-
.dst_ds_ctx,
774+
mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx,
775+
txn->commit_cfg_req->req.commit_cfg.src_ds_ctx,
778776
create_cmt_info_rec);
779777
}
780778

@@ -783,22 +781,18 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn,
783781
* request.
784782
*/
785783
if (txn->session_id && txn->commit_cfg_req->req.commit_cfg.abort)
786-
mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg
787-
.dst_ds_ctx,
788-
txn->commit_cfg_req->req.commit_cfg
789-
.src_ds_ctx,
790-
false);
784+
mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg.src_ds_ctx,
785+
txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx, false);
791786
} else {
792787
/*
793788
* The commit has failied. For implicit commit requests restore
794-
* back the contents of the candidate DS.
789+
* back the contents of the candidate DS. For non-implicit
790+
* commit we want to allow the user to re-commit on the changes
791+
* (whether further modified or not).
795792
*/
796793
if (txn->commit_cfg_req->req.commit_cfg.implicit)
797-
mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg
798-
.dst_ds_ctx,
799-
txn->commit_cfg_req->req.commit_cfg
800-
.src_ds_ctx,
801-
false);
794+
mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg.src_ds_ctx,
795+
txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx, false);
802796
}
803797

804798
if (txn->commit_cfg_req->req.commit_cfg.rollback) {

0 commit comments

Comments
 (0)