From 2ea9a2e311148c9721718058e2ca5d63d882c08f Mon Sep 17 00:00:00 2001 From: vdutta Date: Tue, 9 Nov 2021 20:11:52 +0530 Subject: [PATCH] Stage var state uci --- dmentry.c | 14 ++++++++++---- libbbf_api/dmuci.c | 2 +- libbbf_api/dmuci.h | 12 ++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dmentry.c b/dmentry.c index 3f03f4e8..50abf53e 100644 --- a/dmentry.c +++ b/dmentry.c @@ -267,7 +267,7 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, fault = dm_entry_add_object(ctx); if (!fault) { dmuci_set_value_varstate("cwmp", "cpe", "ParameterKey", arg1 ? arg1 : ""); - dmuci_commit_package_varstate("cwmp"); + dmuci_save_package_varstate("cwmp"); dmuci_change_packages(&head_package_change); } break; @@ -275,7 +275,7 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, fault = dm_entry_delete_object(ctx); if (!fault) { dmuci_set_value_varstate("cwmp", "cpe", "ParameterKey", arg1 ? arg1 : ""); - dmuci_commit_package_varstate("cwmp"); + dmuci_save_package_varstate("cwmp"); dmuci_change_packages(&head_package_change); } break; @@ -308,10 +308,12 @@ int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1) { struct set_tmp *n = NULL, *p = NULL; int fault = 0; + bool set_success = false; switch(cmd) { case CMD_SET_VALUE: ctx->setaction = VALUESET; + set_success = false; list_for_each_entry_safe(n, p, &ctx->set_list_tmp, list) { ctx->in_param = n->name; ctx->in_value = n->value ? n->value : ""; @@ -321,10 +323,11 @@ int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1) add_list_fault_param(ctx, ctx->in_param, usp_fault_map(fault)); break; } + set_success = true; } - if (!fault) { + if (!fault && set_success == true) { dmuci_set_value_varstate("cwmp", "cpe", "ParameterKey", arg1 ? arg1 : ""); - dmuci_commit_package_varstate("cwmp"); + dmuci_save_package_varstate("cwmp"); dmuci_change_packages(&head_package_change); dmuci_save(); } @@ -407,6 +410,8 @@ int dm_entry_restart_services(void) dmubus_call_set("uci", "commit", UBUS_ARGS{{"config", pc->package, String}}, 1); } } + + dmuci_commit_package_varstate("cwmp"); free_all_list_package_change(&head_package_change); return 0; @@ -421,6 +426,7 @@ int dm_entry_revert_changes(void) list_for_each_entry(pc, &head_package_change, list) { dmubus_call_set("uci", "revert", UBUS_ARGS{{"config", pc->package, String}}, 1); } + dmuci_revert_package_varstate("cwmp"); free_all_list_package_change(&head_package_change); return 0; diff --git a/libbbf_api/dmuci.c b/libbbf_api/dmuci.c index f5a46fa5..978e7437 100644 --- a/libbbf_api/dmuci.c +++ b/libbbf_api/dmuci.c @@ -20,7 +20,7 @@ static struct uci_context *uci_ctx = NULL; static char *db_config = NULL; NEW_UCI_PATH(bbfdm, BBFDM_CONFIG, BBFDM_SAVEDIR) -NEW_UCI_PATH(varstate, VARSTATE_CONFDIR, NULL) +NEW_UCI_PATH(varstate, VARSTATE_CONFDIR, VARSTATE_SAVEDIR) int dmuci_init(void) { diff --git a/libbbf_api/dmuci.h b/libbbf_api/dmuci.h index 5a15c9ce..8a1ba3cb 100644 --- a/libbbf_api/dmuci.h +++ b/libbbf_api/dmuci.h @@ -31,6 +31,7 @@ #define BBFDM_SAVEDIR "/tmp/.bbfdm" #define UCI_CONFIG_DIR "/etc/config/" #define VARSTATE_CONFDIR "/var/state/" +#define VARSTATE_SAVEDIR "/tmp/.bbfdm_var" enum dm_uci_cmp { CMP_SECTION, @@ -307,6 +308,15 @@ int dmuci_save_package_##UCI_PATH(char *package) \ uci_ctx = save_uci_ctx; \ return res; \ }\ +int dmuci_revert_package_##UCI_PATH(char *package) \ +{\ + struct uci_context *save_uci_ctx; \ + save_uci_ctx = uci_ctx; \ + uci_ctx = uci_ctx_##UCI_PATH; \ + int res = dmuci_revert_package(package); \ + uci_ctx = save_uci_ctx; \ + return res; \ +}\ int dmuci_delete_by_section_unnamed_##UCI_PATH(struct uci_section *s, char *option, char *value)\ {\ struct uci_context *save_uci_ctx; \ @@ -366,6 +376,8 @@ int dmuci_commit_package_bbfdm(char *package); int dmuci_commit_bbfdm(void); int dmuci_revert_bbfdm(void); int dmuci_commit_package_varstate(char *package); +int dmuci_save_package_varstate(char *package); +int dmuci_revert_package_varstate(char *package); struct uci_section *dmuci_walk_section_bbfdm(char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk); int dmuci_init_bbfdm(void);