Skip to content

Commit

Permalink
mgmtd: convert MGMTD_FE_CLIENT_DBG() to debug_fe_client()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hopps <[email protected]>
  • Loading branch information
choppsv1 committed Feb 1, 2024
1 parent 21f3b4e commit e9fc85f
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 126 deletions.
151 changes: 68 additions & 83 deletions lib/mgmt_fe_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ mgmt_fe_find_session_by_client_id(struct mgmt_fe_client *client,

FOREACH_SESSION_IN_LIST (client, session) {
if (session->client_id == client_id) {
MGMTD_FE_CLIENT_DBG("Found session-id %" PRIu64
" using client-id %" PRIu64,
session->session_id, client_id);
debug_fe_client("Found session-id %" PRIu64
" using client-id %" PRIu64,
session->session_id, client_id);
return session;
}
}
MGMTD_FE_CLIENT_DBG("Session not found using client-id %" PRIu64,
client_id);
debug_fe_client("Session not found using client-id %" PRIu64, client_id);
return NULL;
}

Expand All @@ -98,15 +97,14 @@ mgmt_fe_find_session_by_session_id(struct mgmt_fe_client *client,

FOREACH_SESSION_IN_LIST (client, session) {
if (session->session_id == session_id) {
MGMTD_FE_CLIENT_DBG(
"Found session of client-id %" PRIu64
" using session-id %" PRIu64,
session->client_id, session_id);
debug_fe_client("Found session of client-id %" PRIu64
" using session-id %" PRIu64,
session->client_id, session_id);
return session;
}
}
MGMTD_FE_CLIENT_DBG("Session not found using session-id %" PRIu64,
session_id);
debug_fe_client("Session not found using session-id %" PRIu64,
session_id);
return NULL;
}

Expand All @@ -133,8 +131,7 @@ static int mgmt_fe_send_register_req(struct mgmt_fe_client *client)
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_REGISTER_REQ;
fe_msg.register_req = &rgstr_req;

MGMTD_FE_CLIENT_DBG(
"Sending REGISTER_REQ message to MGMTD Frontend server");
debug_fe_client("Sending REGISTER_REQ message to MGMTD Frontend server");

return mgmt_fe_client_send_msg(client, &fe_msg, true);
}
Expand All @@ -160,9 +157,8 @@ static int mgmt_fe_send_session_req(struct mgmt_fe_client *client,
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_SESSION_REQ;
fe_msg.session_req = &sess_req;

MGMTD_FE_CLIENT_DBG(
"Sending SESSION_REQ %s message for client-id %" PRIu64,
create ? "create" : "destroy", session->client_id);
debug_fe_client("Sending SESSION_REQ %s message for client-id %" PRIu64,
create ? "create" : "destroy", session->client_id);

return mgmt_fe_client_send_msg(client, &fe_msg, true);
}
Expand All @@ -185,9 +181,8 @@ int mgmt_fe_send_lockds_req(struct mgmt_fe_client *client, uint64_t session_id,
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REQ;
fe_msg.lockds_req = &lockds_req;

MGMTD_FE_CLIENT_DBG(
"Sending LOCKDS_REQ (%sLOCK) message for DS:%s session-id %" PRIu64,
lock ? "" : "UN", dsid2name(ds_id), session_id);
debug_fe_client("Sending LOCKDS_REQ (%sLOCK) message for DS:%s session-id %" PRIu64,
lock ? "" : "UN", dsid2name(ds_id), session_id);


return mgmt_fe_client_send_msg(client, &fe_msg, scok);
Expand Down Expand Up @@ -215,10 +210,9 @@ int mgmt_fe_send_setcfg_req(struct mgmt_fe_client *client, uint64_t session_id,
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REQ;
fe_msg.setcfg_req = &setcfg_req;

MGMTD_FE_CLIENT_DBG(
"Sending SET_CONFIG_REQ message for DS:%s session-id %" PRIu64
" (#xpaths:%d)",
dsid2name(ds_id), session_id, num_data_reqs);
debug_fe_client("Sending SET_CONFIG_REQ message for DS:%s session-id %" PRIu64
" (#xpaths:%d)",
dsid2name(ds_id), session_id, num_data_reqs);

return mgmt_fe_client_send_msg(client, &fe_msg, false);
}
Expand All @@ -245,9 +239,8 @@ int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client,
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REQ;
fe_msg.commcfg_req = &commitcfg_req;

MGMTD_FE_CLIENT_DBG(
"Sending COMMIT_CONFIG_REQ message for Src-DS:%s, Dst-DS:%s session-id %" PRIu64,
dsid2name(src_ds_id), dsid2name(dest_ds_id), session_id);
debug_fe_client("Sending COMMIT_CONFIG_REQ message for Src-DS:%s, Dst-DS:%s session-id %" PRIu64,
dsid2name(src_ds_id), dsid2name(dest_ds_id), session_id);

return mgmt_fe_client_send_msg(client, &fe_msg, false);
}
Expand All @@ -273,10 +266,9 @@ int mgmt_fe_send_get_req(struct mgmt_fe_client *client, uint64_t session_id,
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GET_REQ;
fe_msg.get_req = &getcfg_req;

MGMTD_FE_CLIENT_DBG("Sending GET_REQ (iscfg %d) message for DS:%s session-id %" PRIu64
" (#xpaths:%d)",
is_config, dsid2name(ds_id), session_id,
num_data_reqs);
debug_fe_client("Sending GET_REQ (iscfg %d) message for DS:%s session-id %" PRIu64
" (#xpaths:%d)",
is_config, dsid2name(ds_id), session_id, num_data_reqs);

return mgmt_fe_client_send_msg(client, &fe_msg, false);
}
Expand Down Expand Up @@ -325,9 +317,9 @@ int mgmt_fe_send_get_data_req(struct mgmt_fe_client *client, uint64_t session_id
msg->flags = flags;
strlcpy(msg->xpath, xpath, xplen + 1);

MGMTD_FE_CLIENT_DBG("Sending GET_DATA_REQ session-id %" PRIu64
" req-id %" PRIu64 " xpath: %s",
session_id, req_id, xpath);
debug_fe_client("Sending GET_DATA_REQ session-id %" PRIu64
" req-id %" PRIu64 " xpath: %s",
session_id, req_id, xpath);

ret = mgmt_msg_native_send_msg(&client->client.conn, msg, false);
mgmt_msg_native_free_msg(msg);
Expand All @@ -348,30 +340,28 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client *client,
case MGMTD__FE_MESSAGE__MESSAGE_SESSION_REPLY:
if (fe_msg->session_reply->create &&
fe_msg->session_reply->has_client_conn_id) {
MGMTD_FE_CLIENT_DBG(
"Got SESSION_REPLY (create) for client-id %" PRIu64
" with session-id: %" PRIu64,
fe_msg->session_reply->client_conn_id,
fe_msg->session_reply->session_id);
debug_fe_client("Got SESSION_REPLY (create) for client-id %" PRIu64
" with session-id: %" PRIu64,
fe_msg->session_reply->client_conn_id,
fe_msg->session_reply->session_id);

session = mgmt_fe_find_session_by_client_id(
client, fe_msg->session_reply->client_conn_id);

if (session && fe_msg->session_reply->success) {
MGMTD_FE_CLIENT_DBG(
"Session Created for client-id %" PRIu64,
fe_msg->session_reply->client_conn_id);
debug_fe_client("Session Created for client-id %" PRIu64,
fe_msg->session_reply
->client_conn_id);
session->session_id =
fe_msg->session_reply->session_id;
} else {
MGMTD_FE_CLIENT_ERR(
log_err_fe_client(
"Session Create failed for client-id %" PRIu64,
fe_msg->session_reply->client_conn_id);
}
} else if (!fe_msg->session_reply->create) {
MGMTD_FE_CLIENT_DBG(
"Got SESSION_REPLY (destroy) for session-id %" PRIu64,
fe_msg->session_reply->session_id);
debug_fe_client("Got SESSION_REPLY (destroy) for session-id %" PRIu64,
fe_msg->session_reply->session_id);

session = mgmt_fe_find_session_by_session_id(
client, fe_msg->session_req->session_id);
Expand All @@ -388,8 +378,8 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client *client,
session->user_ctx);
break;
case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REPLY:
MGMTD_FE_CLIENT_DBG("Got LOCKDS_REPLY for session-id %" PRIu64,
fe_msg->lockds_reply->session_id);
debug_fe_client("Got LOCKDS_REPLY for session-id %" PRIu64,
fe_msg->lockds_reply->session_id);
session = mgmt_fe_find_session_by_session_id(
client, fe_msg->lockds_reply->session_id);

Expand All @@ -405,8 +395,8 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client *client,
fe_msg->lockds_reply->error_if_any);
break;
case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REPLY:
MGMTD_FE_CLIENT_DBG("Got SETCFG_REPLY for session-id %" PRIu64,
fe_msg->setcfg_reply->session_id);
debug_fe_client("Got SETCFG_REPLY for session-id %" PRIu64,
fe_msg->setcfg_reply->session_id);

session = mgmt_fe_find_session_by_session_id(
client, fe_msg->setcfg_reply->session_id);
Expand All @@ -423,8 +413,8 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client *client,
fe_msg->setcfg_reply->error_if_any);
break;
case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REPLY:
MGMTD_FE_CLIENT_DBG("Got COMMCFG_REPLY for session-id %" PRIu64,
fe_msg->commcfg_reply->session_id);
debug_fe_client("Got COMMCFG_REPLY for session-id %" PRIu64,
fe_msg->commcfg_reply->session_id);

session = mgmt_fe_find_session_by_session_id(
client, fe_msg->commcfg_reply->session_id);
Expand All @@ -443,8 +433,8 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client *client,
fe_msg->commcfg_reply->error_if_any);
break;
case MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY:
MGMTD_FE_CLIENT_DBG("Got GET_REPLY for session-id %" PRIu64,
fe_msg->get_reply->session_id);
debug_fe_client("Got GET_REPLY for session-id %" PRIu64,
fe_msg->get_reply->session_id);

session =
mgmt_fe_find_session_by_session_id(client,
Expand Down Expand Up @@ -513,16 +503,15 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client,
struct mgmt_msg_error *err_msg;
char *notify_data = NULL;

MGMTD_FE_CLIENT_DBG("Got native message for session-id %" PRIu64,
msg->refer_id);
debug_fe_client("Got native message for session-id %" PRIu64,
msg->refer_id);

if (msg->code != MGMT_MSG_CODE_NOTIFY) {
session = mgmt_fe_find_session_by_session_id(client,
msg->refer_id);
if (!session || !session->client) {
MGMTD_FE_CLIENT_ERR(
"No session for received native msg session-id %" PRIu64,
msg->refer_id);
log_err_fe_client("No session for received native msg session-id %" PRIu64,
msg->refer_id);
return;
}
}
Expand All @@ -534,7 +523,7 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client,

err_msg = (typeof(err_msg))msg;
if (!MGMT_MSG_VALIDATE_NUL_TERM(err_msg, msg_len)) {
MGMTD_FE_CLIENT_ERR("Corrupt error msg recv");
log_err_fe_client("Corrupt error msg recv");
return;
}
session->client->cbs.error_notify(client, client->user_data,
Expand All @@ -550,7 +539,7 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client,

tree_msg = (typeof(tree_msg))msg;
if (msg_len < sizeof(*tree_msg)) {
MGMTD_FE_CLIENT_ERR("Corrupt tree-data msg recv");
log_err_fe_client("Corrupt tree-data msg recv");
return;
}
session->client->cbs.get_tree_notify(client, client->user_data,
Expand All @@ -567,13 +556,13 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client,
case MGMT_MSG_CODE_NOTIFY:
notify_msg = (typeof(notify_msg))msg;
if (msg_len < sizeof(*notify_msg)) {
MGMTD_FE_CLIENT_ERR("Corrupt notify-data msg recv");
log_err_fe_client("Corrupt notify-data msg recv");
return;
}

if (notify_msg->result_type != LYD_LYB &&
!MGMT_MSG_VALIDATE_NUL_TERM(notify_msg, msg_len)) {
MGMTD_FE_CLIENT_ERR("Corrupt error msg recv");
log_err_fe_client("Corrupt error msg recv");
return;
}
if (notify_msg->result_type == LYD_JSON)
Expand All @@ -585,8 +574,8 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client,
notify_msg->result_type,
LYD_JSON, true);
if (!notify_data) {
MGMTD_FE_CLIENT_ERR("Can't convert format %d to JSON",
notify_msg->result_type);
log_err_fe_client("Can't convert format %d to JSON",
notify_msg->result_type);
return;
}
FOREACH_SESSION_IN_LIST (client, session) {
Expand All @@ -603,9 +592,9 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client,
darr_free(notify_data);
break;
default:
MGMTD_FE_CLIENT_ERR("unknown native message session-id %" PRIu64
" req-id %" PRIu64 " code %u",
msg->refer_id, msg->req_id, msg->code);
log_err_fe_client("unknown native message session-id %" PRIu64
" req-id %" PRIu64 " code %u",
msg->refer_id, msg->req_id, msg->code);
break;
}
}
Expand All @@ -626,20 +615,18 @@ static void mgmt_fe_client_process_msg(uint8_t version, uint8_t *data,
if (len >= sizeof(*msg))
fe_client_handle_native_msg(client, msg, len);
else
MGMTD_FE_CLIENT_ERR("native message to FE client %s too short %zu",
client->name, len);
log_err_fe_client("native message to FE client %s too short %zu",
client->name, len);
return;
}

fe_msg = mgmtd__fe_message__unpack(NULL, len, data);
if (!fe_msg) {
MGMTD_FE_CLIENT_DBG("Failed to decode %zu bytes from server.",
len);
debug_fe_client("Failed to decode %zu bytes from server.", len);
return;
}
MGMTD_FE_CLIENT_DBG(
"Decoded %zu bytes of message(msg: %u/%u) from server", len,
fe_msg->message_case, fe_msg->message_case);
debug_fe_client("Decoded %zu bytes of message(msg: %u/%u) from server",
len, fe_msg->message_case, fe_msg->message_case);
(void)mgmt_fe_client_handle_msg(client, fe_msg);
mgmtd__fe_message__free_unpacked(fe_msg, NULL);
}
Expand All @@ -660,7 +647,7 @@ static int _notify_connect_disconnect(struct msg_client *msg_client,

/* Walk list of sessions for this FE client deleting them */
if (!connected && mgmt_sessions_count(&client->sessions)) {
MGMTD_FE_CLIENT_DBG("Cleaning up existing sessions");
debug_fe_client("Cleaning up existing sessions");

FOREACH_SESSION_IN_LIST (client, session) {
assert(session->client);
Expand Down Expand Up @@ -731,7 +718,7 @@ static int mgmt_debug_fe_client_config_write(struct vty *vty)

void mgmt_debug_fe_client_show_debug(struct vty *vty)
{
if (MGMTD_DBG_FE_CLIENT_CHECK())
if (debug_check_fe_client())
vty_out(vty, "debug mgmt client frontend\n");
}

Expand Down Expand Up @@ -777,9 +764,9 @@ struct mgmt_fe_client *mgmt_fe_client_create(const char *client_name,
mgmt_fe_client_notify_disconnect,
mgmt_fe_client_process_msg, MGMTD_FE_MAX_NUM_MSG_PROC,
MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MAX_MSG_LEN, true,
"FE-client", MGMTD_DBG_FE_CLIENT_CHECK());
"FE-client", debug_check_fe_client());

MGMTD_FE_CLIENT_DBG("Initialized client '%s'", client_name);
debug_fe_client("Initialized client '%s'", client_name);

return client;
}
Expand Down Expand Up @@ -848,9 +835,8 @@ enum mgmt_result mgmt_fe_destroy_client_session(struct mgmt_fe_client *client,

if (session->session_id &&
mgmt_fe_send_session_req(client, session, false) != 0)
MGMTD_FE_CLIENT_ERR(
"Failed to send session destroy request for the session-id %" PRIu64,
session->session_id);
log_err_fe_client("Failed to send session destroy request for the session-id %" PRIu64,
session->session_id);

mgmt_sessions_del(&client->sessions, session);
XFREE(MTYPE_MGMTD_FE_SESSION, session);
Expand All @@ -867,8 +853,7 @@ void mgmt_fe_client_destroy(struct mgmt_fe_client *client)

assert(client == __fe_client);

MGMTD_FE_CLIENT_DBG("Destroying MGMTD Frontend Client '%s'",
client->name);
debug_fe_client("Destroying MGMTD Frontend Client '%s'", client->name);

FOREACH_SESSION_IN_LIST (client, session)
mgmt_fe_destroy_client_session(client, session->client_id);
Expand Down
6 changes: 3 additions & 3 deletions lib/mgmt_fe_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ extern struct debug mgmt_dbg_fe_client;
* API prototypes
***************************************************************/

#define MGMTD_FE_CLIENT_DBG(fmt, ...) \
#define debug_fe_client(fmt, ...) \
DEBUGD(&mgmt_dbg_fe_client, "FE-CLIENT: %s: " fmt, __func__, \
##__VA_ARGS__)
#define MGMTD_FE_CLIENT_ERR(fmt, ...) \
#define log_err_fe_client(fmt, ...) \
zlog_err("FE-CLIENT: %s: ERROR: " fmt, __func__, ##__VA_ARGS__)
#define MGMTD_DBG_FE_CLIENT_CHECK() \
#define debug_check_fe_client() \
DEBUG_MODE_CHECK(&mgmt_dbg_fe_client, DEBUG_MODE_ALL)

/*
Expand Down
Loading

0 comments on commit e9fc85f

Please sign in to comment.