summaryrefslogtreecommitdiff
path: root/mgmtd
diff options
context:
space:
mode:
authorChristian Hopps <chopps@labn.net>2024-09-17 02:27:31 -0400
committerChristian Hopps <chopps@labn.net>2024-09-17 05:31:00 -0400
commitb097a966cbe73d7f77fefc4b3c4baf16ce2be214 (patch)
tree7a3122b15c7a8d42272586a862180bd56cebd389 /mgmtd
parent96db155acde43be7cd02d727285ed96e792e0454 (diff)
lib: mgmtd: add `changed` and `created` to edit-reply msg
- This is used for various return values in RESTCONF Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'mgmtd')
-rw-r--r--mgmtd/mgmt_fe_adapter.c24
-rw-r--r--mgmtd/mgmt_fe_adapter.h8
-rw-r--r--mgmtd/mgmt_txn.c10
3 files changed, 28 insertions, 14 deletions
diff --git a/mgmtd/mgmt_fe_adapter.c b/mgmtd/mgmt_fe_adapter.c
index 8ab66de687..8d305ed52f 100644
--- a/mgmtd/mgmt_fe_adapter.c
+++ b/mgmtd/mgmt_fe_adapter.c
@@ -1164,7 +1164,9 @@ done:
}
static int fe_adapter_send_edit_reply(struct mgmt_fe_session_ctx *session,
- uint64_t req_id, const char *xpath)
+ uint64_t req_id, bool changed,
+ bool created, const char *xpath,
+ const char *data)
{
struct mgmt_msg_edit_reply *msg;
int ret;
@@ -1173,14 +1175,19 @@ static int fe_adapter_send_edit_reply(struct mgmt_fe_session_ctx *session,
MTYPE_MSG_NATIVE_EDIT_REPLY);
msg->refer_id = session->session_id;
msg->req_id = req_id;
+ msg->changed = changed;
+ msg->created = created;
msg->code = MGMT_MSG_CODE_EDIT_REPLY;
mgmt_msg_native_xpath_encode(msg, xpath);
+ if (data)
+ mgmt_msg_native_append(msg, data, strlen(data) + 1);
+
__dbg("Sending edit-reply from adapter %s to session-id %" PRIu64
- " req-id %" PRIu64 " len %u",
- session->adapter->name, session->session_id, req_id,
- mgmt_msg_native_get_msg_len(msg));
+ " req-id %" PRIu64 " changed %u created %u len %u",
+ session->adapter->name, session->session_id, req_id, changed,
+ created, mgmt_msg_native_get_msg_len(msg));
ret = fe_adapter_send_native_msg(session->adapter, msg,
mgmt_msg_native_get_msg_len(msg),
@@ -1977,8 +1984,8 @@ int mgmt_fe_adapter_send_rpc_reply(uint64_t session_id, uint64_t txn_id,
int mgmt_fe_adapter_send_edit_reply(uint64_t session_id, uint64_t txn_id,
uint64_t req_id, bool unlock, bool commit,
- const char *xpath, int16_t error,
- const char *errstr)
+ bool created, const char *xpath,
+ int16_t error, const char *errstr)
{
struct mgmt_fe_session_ctx *session;
Mgmtd__DatastoreId ds_id, rds_id;
@@ -2009,11 +2016,12 @@ int mgmt_fe_adapter_send_edit_reply(uint64_t session_id, uint64_t txn_id,
}
}
- if (error)
+ if (error != 0 && error != -EALREADY)
ret = fe_adapter_send_error(session, req_id, false, error, "%s",
errstr);
else
- ret = fe_adapter_send_edit_reply(session, req_id, xpath);
+ ret = fe_adapter_send_edit_reply(session, req_id, created,
+ !error, xpath, errstr);
if (session->cfg_txn_id != MGMTD_TXN_ID_NONE && !commit)
mgmt_destroy_txn(&session->cfg_txn_id);
diff --git a/mgmtd/mgmt_fe_adapter.h b/mgmtd/mgmt_fe_adapter.h
index 5a7dec3e6f..4d94e7604f 100644
--- a/mgmtd/mgmt_fe_adapter.h
+++ b/mgmtd/mgmt_fe_adapter.h
@@ -193,14 +193,16 @@ extern int mgmt_fe_adapter_send_rpc_reply(uint64_t session_id, uint64_t txn_id,
* req_id: the req id for the edit message
* unlock: implicit-lock flag was set in the request
* commit: implicit-commit flag was set in the request
- * xpath: the xpath of the data node that was created
+ * created: true if the node was just created
+ * xpath: the xpath of the data node that was created/updated
* error: >0 LY_ERR, < 0 -errno
* errstr: the error string, if error is non-zero
*/
extern int mgmt_fe_adapter_send_edit_reply(uint64_t session_id, uint64_t txn_id,
uint64_t req_id, bool unlock,
- bool commit, const char *xpath,
- int16_t error, const char *errstr);
+ bool commit, bool created,
+ const char *xpath, int16_t error,
+ const char *errstr);
/**
* Send an error back to the FE client using native messaging.
diff --git a/mgmtd/mgmt_txn.c b/mgmtd/mgmt_txn.c
index 53d9f5c3fa..ccfdd7539f 100644
--- a/mgmtd/mgmt_txn.c
+++ b/mgmtd/mgmt_txn.c
@@ -94,6 +94,7 @@ DECLARE_LIST(mgmt_txn_batches, struct mgmt_txn_be_cfg_batch, list_linkage);
struct mgmt_edit_req {
char xpath_created[XPATH_MAXLEN];
+ bool created;
bool unlock;
};
@@ -742,6 +743,8 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn,
.edit->unlock,
true,
txn->commit_cfg_req->req.commit_cfg
+ .edit->created,
+ txn->commit_cfg_req->req.commit_cfg
.edit->xpath_created,
success ? 0 : -1,
error_if_any) != 0) {
@@ -2566,8 +2569,8 @@ int mgmt_txn_send_edit(uint64_t txn_id, uint64_t req_id,
assert(nb_config);
ret = nb_candidate_edit_tree(nb_config, operation, request_type, xpath,
- data, edit->xpath_created, errstr,
- sizeof(errstr));
+ data, &edit->created, edit->xpath_created,
+ errstr, sizeof(errstr));
if (ret)
goto reply;
@@ -2581,7 +2584,8 @@ int mgmt_txn_send_edit(uint64_t txn_id, uint64_t req_id,
}
reply:
mgmt_fe_adapter_send_edit_reply(txn->session_id, txn->txn_id, req_id,
- unlock, commit, edit->xpath_created,
+ unlock, commit, edit->created,
+ edit->xpath_created,
errno_from_nb_error(ret), errstr);
XFREE(MTYPE_MGMTD_TXN_REQ, edit);