From 25b834e09c86b3957dc66470d741a91a22404a12 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Tue, 25 Oct 2022 12:29:22 +0000 Subject: [PATCH] system-plugin: remove storing to startup DS on every change and plugin cleanup --- src/startup/load.c | 10 ++-- src/startup/store.c | 10 ++-- src/subscription/change.c | 93 +++---------------------------------- src/system.c | 2 +- src/system/api/ntp/change.c | 12 ++--- 5 files changed, 24 insertions(+), 103 deletions(-) diff --git a/src/startup/load.c b/src/startup/load.c index 3ddfebe..ddcca4d 100644 --- a/src/startup/load.c +++ b/src/startup/load.c @@ -186,7 +186,7 @@ static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *sessi struct lyd_node *clock_container_node = NULL; bool timezone_name_enabled = false; - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out); if (timezone_name_enabled) { error = system_load_timezone_name(ctx, timezone_name_buffer); @@ -233,8 +233,8 @@ static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const SRPLG_LOG_INF(PLUGIN_NAME, "Loading NTP data"); - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out); - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out); if (ntp_enabled) { error = system_ly_tree_create_ntp(ly_ctx, parent_node, &ntp_container_node); @@ -432,8 +432,8 @@ static int system_startup_load_authentication(void *priv, sr_session_ctx_t *sess bool enabled_authentication = false; bool enabled_local_users = false; - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "authentication", &enabled_authentication), error_out); - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "local-users", &enabled_local_users), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "authentication", &enabled_authentication), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "local-users", &enabled_local_users), error_out); if (enabled_authentication) { // create authentication container diff --git a/src/startup/store.c b/src/startup/store.c index c344de3..61bd17c 100644 --- a/src/startup/store.c +++ b/src/startup/store.c @@ -236,7 +236,7 @@ static int system_startup_store_timezone_name(void *priv, const struct lyd_node struct lyd_node *clock_container_node = NULL, *timezone_name_node = NULL; - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out); if (timezone_name_enabled) { clock_container_node = srpc_ly_tree_get_child_container(system_container_node, "clock"); @@ -309,8 +309,8 @@ static int system_startup_store_ntp(void *priv, const struct lyd_node *system_co system_ntp_server_t temp_server = {0}; srpc_check_status_t server_check_status = srpc_check_status_none; - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out); - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out); if (ntp_enabled) { SRPLG_LOG_INF(PLUGIN_NAME, "Storing NTP startup data"); @@ -729,8 +729,8 @@ static int system_startup_store_authentication(void *priv, const struct lyd_node // srpc srpc_check_status_t user_check_status = srpc_check_status_none, key_check_status = srpc_check_status_none; - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "authentication", &authentication_enabled), error_out); - SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "local-users", &local_users_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "authentication", &authentication_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "local-users", &local_users_enabled), error_out); if (authentication_enabled) { SRPLG_LOG_INF(PLUGIN_NAME, "Storing authentication startup data"); diff --git a/src/subscription/change.c b/src/subscription/change.c index 1efb75e..c4e25f6 100644 --- a/src/subscription/change.c +++ b/src/subscription/change.c @@ -61,12 +61,6 @@ int system_subscription_change_contact(sr_session_ctx_t *session, uint32_t subsc if (event == SR_EV_ABORT) { SRPLG_LOG_ERR(PLUGIN_NAME, "Aborting changes for %s", xpath); goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { error = srpc_iterate_changes(ctx, session, xpath, system_change_contact, NULL, NULL); if (error) { @@ -92,12 +86,6 @@ int system_subscription_change_hostname(sr_session_ctx_t *session, uint32_t subs if (event == SR_EV_ABORT) { SRPLG_LOG_ERR(PLUGIN_NAME, "Aborting changes for %s", xpath); goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { error = srpc_iterate_changes(ctx, session, xpath, system_change_hostname, NULL, NULL); if (error) { @@ -123,12 +111,6 @@ int system_subscription_change_location(sr_session_ctx_t *session, uint32_t subs if (event == SR_EV_ABORT) { SRPLG_LOG_ERR(PLUGIN_NAME, "Aborting changes for %s", xpath); goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { error = srpc_iterate_changes(ctx, session, xpath, system_change_location, NULL, NULL); if (error) { @@ -157,14 +139,8 @@ int system_subscription_change_timezone_name(sr_session_ctx_t *session, uint32_t if (event == SR_EV_ABORT) { SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { - SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out); if (timezone_name_enabled) { error = srpc_iterate_changes(ctx, session, xpath, system_change_timezone_name, NULL, NULL); @@ -192,12 +168,6 @@ int system_subscription_change_timezone_utc_offset(sr_session_ctx_t *session, ui if (event == SR_EV_ABORT) { SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { SRPLG_LOG_ERR(PLUGIN_NAME, "Unsupported option for now"); } @@ -222,18 +192,12 @@ int system_subscription_change_ntp_enabled(sr_session_ctx_t *session, uint32_t s SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); error = -1; goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { // get feature status - SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out); if (ntp_enabled) { - SRPC_SAFE_CALL(srpc_iterate_changes(ctx, session, xpath, system_ntp_change_enabled, NULL, NULL), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_iterate_changes(ctx, session, xpath, system_ntp_change_enabled, NULL, NULL), error_out); } } @@ -261,19 +225,13 @@ int system_subscription_change_ntp_server(sr_session_ctx_t *session, uint32_t su SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); error = -1; goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { // make sure the last change servers were free'd and set to NULL assert(ctx->temp_ntp_servers == NULL); // get features - SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out); - SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out); if (ntp_enabled) { // load all system NTP servers @@ -414,13 +372,6 @@ int system_subscription_change_dns_resolver_search(sr_session_ctx_t *session, ui SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); error = -1; goto error_out; - } else if (event == SR_EV_DONE) { - SRPLG_LOG_INF(PLUGIN_NAME, "Done processing changes - storing data into startup"); - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { // make sure the last change search values were free'd and set to NULL assert(ctx->temp_dns_search == NULL); @@ -481,12 +432,6 @@ int system_subscription_change_dns_resolver_server(sr_session_ctx_t *session, ui SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); error = -1; goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { // make sure the last change servers were free'd and set to NULL assert(ctx->temp_dns_servers == NULL); @@ -575,12 +520,6 @@ int system_subscription_change_dns_resolver_timeout(sr_session_ctx_t *session, u SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); error = -1; goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { SRPLG_LOG_ERR(PLUGIN_NAME, "Unsupported option for now"); } @@ -601,12 +540,6 @@ int system_subscription_change_dns_resolver_attempts(sr_session_ctx_t *session, SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); error = -1; goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { SRPLG_LOG_ERR(PLUGIN_NAME, "Unsupported option for now"); } @@ -628,12 +561,6 @@ int system_subscription_change_authentication_user_authentication_order(sr_sessi SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); error = -1; goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { } @@ -660,20 +587,14 @@ int system_subscription_change_authentication_user(sr_session_ctx_t *session, ui SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath); error = -1; goto error_out; - } else if (event == SR_EV_DONE) { - error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error)); - goto error_out; - } } else if (event == SR_EV_CHANGE) { // assert user database is NULL from the last change assert(ctx->temp_users.created == NULL); assert(ctx->temp_users.modified == NULL); assert(ctx->temp_users.deleted == NULL); - SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "authentication", &authentication_enabled), error_out); - SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "local-users", &local_users_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "authentication", &authentication_enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "local-users", &local_users_enabled), error_out); if (authentication_enabled && local_users_enabled) { // load current users into modifed list so they can also be modified diff --git a/src/system.c b/src/system.c index 932c452..f533def 100644 --- a/src/system.c +++ b/src/system.c @@ -162,7 +162,7 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data) const char *feature = features[i]; bool enabled = false; - SRPC_SAFE_CALL(srpc_check_feature_status(running_session, "ietf-system", feature, &enabled), error_out); + SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(running_session, "ietf-system", feature, &enabled), error_out); SRPLG_LOG_INF(PLUGIN_NAME, "ietf-system feature \"%s\" status = %s", feature, enabled ? "enabled" : "disabled"); } diff --git a/src/system/api/ntp/change.c b/src/system/api/ntp/change.c index d8f02cd..5ea5fe4 100644 --- a/src/system/api/ntp/change.c +++ b/src/system/api/ntp/change.c @@ -39,17 +39,17 @@ int system_ntp_change_enabled(void *priv, sr_session_ctx_t *session, const srpc_ case SR_OP_CREATED: case SR_OP_MODIFIED: if (enabled) { - SRPC_SAFE_CALL(system("systemctl start ntp"), error_out); - SRPC_SAFE_CALL(system("systemctl enable ntp"), error_out); + SRPC_SAFE_CALL_ERR(error, system("systemctl start ntp"), error_out); + SRPC_SAFE_CALL_ERR(error, system("systemctl enable ntp"), error_out); } else { - SRPC_SAFE_CALL(system("systemctl stop ntp"), error_out); - SRPC_SAFE_CALL(system("systemctl disable ntp"), error_out); + SRPC_SAFE_CALL_ERR(error, system("systemctl stop ntp"), error_out); + SRPC_SAFE_CALL_ERR(error, system("systemctl disable ntp"), error_out); } break; case SR_OP_DELETED: // set default value = true - SRPC_SAFE_CALL(system("systemctl start ntp"), error_out); - SRPC_SAFE_CALL(system("systemctl enable ntp"), error_out); + SRPC_SAFE_CALL_ERR(error, system("systemctl start ntp"), error_out); + SRPC_SAFE_CALL_ERR(error, system("systemctl enable ntp"), error_out); break; case SR_OP_MOVED: break;