Skip to content

Commit

Permalink
Use LOG_VERSION: 3 for number of log entries support
Browse files Browse the repository at this point in the history
  • Loading branch information
vrahane committed Apr 2, 2024
1 parent a66e6ef commit 68bc308
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
20 changes: 2 additions & 18 deletions sys/log/full/include/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,11 @@ struct log_handler {
/* Image hash length to be looged */
#define LOG_IMG_HASHLEN 4

/* Flags used to indicate type of data in reserved payload*/
#define LOG_FLAGS_IMG_HASH (1 << 0)
/* Flags used to indicate type of data in reserved payload */
#define LOG_FLAGS_IMG_HASH (1 << 0)
#define LOG_FLAGS_NUM_ENTRIES (1 << 1)

#if MYNEWT_VAL(LOG_VERSION) == 3
struct log_entry_hdr {
int64_t ue_ts;
uint32_t ue_index;
uint8_t ue_module;
uint8_t ue_level;
uint8_t ue_etype : 4;
uint8_t ue_flags : 4;
uint8_t ue_imghash[4];
} __attribute__((__packed__));
#elif MYNEWT_VAL(LOG_VERSION) == 4
struct log_entry_hdr {
int64_t ue_ts;
uint32_t ue_index;
Expand All @@ -160,9 +150,7 @@ struct log_entry_hdr {

#define LOG_BASE_ENTRY_HDR_SIZE (15)

#if MYNEWT_VAL(LOG_FLAGS_NUM_ENTRIES)
#define LOG_NUM_ENTRIES_SIZE (sizeof(((struct log *)0)->l_num_entries))
#endif

#define LOG_MODULE_STR(module) log_module_get_name(module)

Expand Down Expand Up @@ -229,9 +217,7 @@ struct log {
#if !MYNEWT_VAL(LOG_GLOBAL_IDX)
uint32_t l_idx;
#endif
#if MYNEWT_VAL(LOG_FLAGS_NUM_ENTRIES)
uint32_t l_num_entries;
#endif
#if MYNEWT_VAL(LOG_STATS)
STATS_SECT_DECL(logs) l_stats;
#endif
Expand Down Expand Up @@ -786,8 +772,6 @@ log_read_hdr_by_idx(struct log *log, uint32_t idx, struct log_entry_hdr *out_hdr
* @param log The log to get number of entries for
* @param idx The log index to read number of entries from
* @param num_entries Ptr to fill up number of entries in log
*
* @return 0 on success, non-zero on failure
*/
int
log_get_entries(struct log *log, uint32_t idx, uint32_t *entries);
Expand Down
14 changes: 3 additions & 11 deletions sys/log/full/src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ log_read_hdr_walk(struct log *log, struct log_offset *log_offset,
}
}

#if MYNEWT_VAL(LOG_FLAGS_NUM_ENTRIES)
if (arg->hdr->ue_flags & LOG_FLAGS_NUM_ENTRIES) {
rc = log_fill_num_entries(log, dptr, arg->hdr, offset);
if (!rc || rc == SYS_ENOTSUP) {
Expand All @@ -346,7 +345,6 @@ log_read_hdr_walk(struct log *log, struct log_offset *log_offset,
arg->read_success = 0;
}
}
#endif

/* Abort the walk; only one header needed. */
return 1;
Expand Down Expand Up @@ -511,16 +509,13 @@ log_register(const char *name, struct log *log, const struct log_handler *lh,
log->l_idx = hdr.ue_index + 1;
}
#endif

#if MYNEWT_VAL(LOG_FLAGS_NUM_ENTRIES)
/* If this is a persisted log, read the num_entries from its most
* recent entry. We need to ensure the number of entries are
* monotonically increasing.
*/
if (hdr.ue_num_entries >= log->l_num_entries) {
log->l_num_entries = hdr.ue_num_entries + 1;
}
#endif
OS_EXIT_CRITICAL(sr);
}
}
Expand All @@ -544,11 +539,9 @@ log_hdr_len(const struct log_entry_hdr *hdr)
len += LOG_IMG_HASHLEN;
}

#if MYNEWT_VAL(LOG_FLAGS_NUM_ENTRIES)
if (hdr->ue_flags & LOG_FLAGS_NUM_ENTRIES) {
len += LOG_NUM_ENTRIES_SIZE;
}
#endif

return len;
}
Expand Down Expand Up @@ -1084,7 +1077,6 @@ log_read_hdr(struct log *log, const void *dptr, struct log_entry_hdr *hdr)
}
}

#if MYNEWT_VAL(LOG_FLAGS_NUM_ENTRIES)
if (hdr->ue_flags & LOG_FLAGS_NUM_ENTRIES) {
bytes_read = log_read(log, dptr, &hdr->ue_num_entries,
LOG_BASE_ENTRY_HDR_SIZE + bytes_read,
Expand All @@ -1093,7 +1085,6 @@ log_read_hdr(struct log *log, const void *dptr, struct log_entry_hdr *hdr)
return SYS_EIO;
}
}
#endif

return 0;
}
Expand Down Expand Up @@ -1148,9 +1139,8 @@ log_flush(struct log *log)
{
int rc;

#if MYNEWT_VAL(LOG_FLAGS_NUM_ENTRIES)
log->l_num_entries = 0;
#endif

rc = log->l_log->log_flush(log);
if (rc != 0) {
goto err;
Expand Down Expand Up @@ -1254,6 +1244,8 @@ log_fill_num_entries(struct log *log, const void *dptr,
return rc;
}
#else
hdr->ue_num_entries = 0;

return SYS_ENOTSUP;
#endif
}
Expand Down

0 comments on commit 68bc308

Please sign in to comment.