This is an automated email from the ASF dual-hosted git repository. vipulrahane pushed a commit to branch sect_bmark_nolog_init_fix in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit b17d2630612a4a19060432387cf56a23be9c12de Author: Vipul Rahane <[email protected]> AuthorDate: Mon Mar 17 22:40:09 2025 -0700 sys/log: Fix Sector bookmark no log init and log flush - When no logs are present, sector bookmarks were not getting assigned if a log entry was generated Fixing this specific case. - On log flush/clear, next_sec was not getting pointed to earlier inited sect_cap - 1 value. --- sys/log/full/src/log_fcb.c | 34 ++++++++++++++++++++++++---------- sys/log/full/src/log_fcb_bmark.c | 5 +++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c index 529e8f473..392743590 100644 --- a/sys/log/full/src/log_fcb.c +++ b/sys/log/full/src/log_fcb.c @@ -211,21 +211,20 @@ log_fcb_find_gte(struct log *log, struct log_offset *log_offset, static int log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc) { - struct fcb *fcb; - struct fcb_log *fcb_log; + struct fcb_log *fcb_log = (struct fcb_log *)log->l_arg; + struct fcb *fcb = &fcb_log->fl_fcb; struct flash_area *old_fa; int rc = 0; #if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS) int active_id; uint32_t idx; + struct log_fcb_bset *bset = &fcb_log->fl_bset; #endif + #if MYNEWT_VAL(LOG_STATS) int cnt; #endif - fcb_log = (struct fcb_log *)log->l_arg; - fcb = &fcb_log->fl_fcb; - /* Cache active ID before appending */ #if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS) active_id = fcb->f_active_id; @@ -280,9 +279,8 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc) /* The FCB needs to be rotated, reinit previously allocated * bookmarks */ - log_fcb_init_bmarks(fcb_log, fcb_log->fl_bset.lfs_bmarks, - fcb_log->fl_bset.lfs_cap, - fcb_log->fl_bset.lfs_en_sect_bmarks); + log_fcb_init_bmarks(fcb_log, bset->lfs_bmarks, bset->lfs_cap, + bset->lfs_en_sect_bmarks); #endif #if MYNEWT_VAL(LOG_STORAGE_WATERMARK) @@ -301,12 +299,18 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc) #if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS) /* Add bookmark if entry is added to a new sector */ if (!rc && log->l_log->log_type != LOG_TYPE_STREAM) { - if (fcb->f_active_id != active_id) { + if (bset->lfs_en_sect_bmarks && + (!bset->lfs_bmarks[bset->lfs_sect_cap - 1].lfb_entry.fe_area || + fcb->f_active_id != active_id)) { #if MYNEWT_VAL(LOG_GLOBAL_IDX) idx = g_log_info.li_next_index; #else idx = log->l_idx; #endif + if (!bset->lfs_bmarks[bset->lfs_sect_cap - 1].lfb_entry.fe_area) { + bset->lfs_next_sect = bset->lfs_sect_cap - 1; + } + log_fcb_add_bmark(fcb_log, loc, idx, true); } } @@ -703,15 +707,25 @@ log_fcb_flush(struct log *log) { struct fcb_log *fcb_log; struct fcb *fcb; + int rc; fcb_log = (struct fcb_log *)log->l_arg; fcb = &fcb_log->fl_fcb; + rc = fcb_clear(fcb); + #if MYNEWT_VAL(LOG_FCB_BOOKMARKS) +#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS) + /* Reinit previously allocated bookmarks */ + log_fcb_init_bmarks(fcb_log, fcb_log->fl_bset.lfs_bmarks, + fcb_log->fl_bset.lfs_cap, + fcb_log->fl_bset.lfs_en_sect_bmarks); +#else log_fcb_clear_bmarks(fcb_log); +#endif #endif - return fcb_clear(fcb); + return rc; } static int diff --git a/sys/log/full/src/log_fcb_bmark.c b/sys/log/full/src/log_fcb_bmark.c index 2a210aa94..2ac090c50 100644 --- a/sys/log/full/src/log_fcb_bmark.c +++ b/sys/log/full/src/log_fcb_bmark.c @@ -205,6 +205,11 @@ log_fcb_clear_bmarks(struct fcb_log *fcb_log) fcb_log->fl_bset.lfs_size = 0; fcb_log->fl_bset.lfs_next_non_sect = 0; fcb_log->fl_bset.lfs_non_sect_size = 0; +#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS) + if (fcb_log->fl_bset.lfs_en_sect_bmarks) { + fcb_log->fl_bset.lfs_next_sect = fcb_log->fl_bset.lfs_sect_cap - 1; + } +#endif memset(fcb_log->fl_bset.lfs_bmarks, 0, sizeof(struct log_fcb_bmark) * fcb_log->fl_bset.lfs_cap);
