Store session backup to persistent storage

This commit is contained in:
Suvendhu Hansa 2024-10-24 05:21:07 +00:00 committed by IOPSYS Dev
parent 5c94fa6b1a
commit 384c929c51
No known key found for this signature in database
5 changed files with 29 additions and 2 deletions

View file

@ -233,6 +233,19 @@ All backup session indexes are successive in the enumeration and starts with `BK
For each kind of backup session data, there are insert functions that call `build_xml_node_data` and load functions that calls `load_xml_node_data`. For each kind of backup session data, there are insert functions that call `build_xml_node_data` and load functions that calls `load_xml_node_data`.
### NOTE:
This backup session feature has been limited to soft reboot and system upgrade, thus in case of power cycle or hard reboot, icwmp can not store the
data in `/etc/icwmpd/icwmpd_backkup_session.xml`. Due to this limitation there is a chance that icwmp may send wrong event or not send an expected
event in the first inform message after power up. For e.g: icwmp after power cycle may send `0 BOOTSTRAP` event even though it connects the same ACS.
So, to avoid this problem a compile time flag `PERSIST_BACKUP_SESSION_EVENTS` has been added, by enabling this flag icwmp will store the backup session
information in flash (persistent storage) drive at every successful session end and after boot up icwmp loads the session information from flash drive
if there exist any.
#### Precaution:
This feature will increase the flash write operation, so user need to reconsider about enabling this flag. If flash has less write limit then it is
better to disable this feature because after exceeding the write limit, flash could be corrupted.
## UCI and config mangement ## UCI and config mangement
- [UCI](./docs/api/uci/cwmp.md) - [UCI](./docs/api/uci/cwmp.md)

View file

@ -58,7 +58,6 @@ void bkp_session_save()
fp = fopen(CWMP_BKP_FILE, "w"); fp = fopen(CWMP_BKP_FILE, "w");
mxmlSaveFile(bkp_tree, fp, MXML_NO_CALLBACK); mxmlSaveFile(bkp_tree, fp, MXML_NO_CALLBACK);
fclose(fp); fclose(fp);
sync();
} }
void bkp_session_create_file() void bkp_session_create_file()

View file

@ -23,6 +23,11 @@
#define CWMP_BACKUP_SESSION "<cwmp></cwmp>" #define CWMP_BACKUP_SESSION "<cwmp></cwmp>"
#define CWMP_BKP_FILE "/var/run/icwmpd/icwmpd_backup_session.xml" #define CWMP_BKP_FILE "/var/run/icwmpd/icwmpd_backup_session.xml"
#ifdef PERSIST_BACKUP_SESSION_EVENTS
#define CWMP_BKP_FILE_PERSISTENT "/etc/icwmpd/icwmpd_backup_session.xml"
#endif
typedef enum backup_loading typedef enum backup_loading
{ {
ALL, ALL,

View file

@ -469,7 +469,7 @@ int copy(const char *from, const char *to)
if (fd_from < 0) if (fd_from < 0)
return -1; return -1;
fd_to = open(to, O_WRONLY | O_CREAT | O_EXCL, 0666); fd_to = open(to, O_WRONLY | O_CREAT | O_EXCL | O_SYNC, 0666);
if (fd_to < 0) if (fd_to < 0)
goto out_error; goto out_error;

View file

@ -411,6 +411,16 @@ void start_cwmp_session(void)
cwmp_ctx.retry_count_session = 0; cwmp_ctx.retry_count_session = 0;
set_cwmp_session_status(SESSION_SUCCESS, 0); set_cwmp_session_status(SESSION_SUCCESS, 0);
#ifdef PERSIST_BACKUP_SESSION_EVENTS
// session ended successfully so store next session events in persistent
// storage to avoid loss of events over power cycle
if (file_exists(CWMP_BKP_FILE)) {
CWMP_LOG(DEBUG, "Copied events backup file to persistent storage");
copy(CWMP_BKP_FILE, CWMP_BKP_FILE_PERSISTENT);
}
#endif
if (cwmp_ctx.throttle_session_triggered == true) { if (cwmp_ctx.throttle_session_triggered == true) {
cwmp_ctx.throttle_session_triggered = false; cwmp_ctx.throttle_session_triggered = false;
if (!cwmp_ctx.throttle_session) { if (!cwmp_ctx.throttle_session) {