You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2024/04/02 21:31:14 UTC
(mynewt-core) 01/01: Use LOG_VERSION: 3 for number of log entries support
This is an automated email from the ASF dual-hosted git repository.
vipulrahane pushed a commit to branch vipul/logging_num_entries
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 68bc308b4083b3aa4e17f91ae9426c5921a67512
Author: Vipul Rahane <vi...@apache.org>
AuthorDate: Tue Apr 2 14:30:51 2024 -0700
Use LOG_VERSION: 3 for number of log entries support
---
sys/log/full/include/log/log.h | 20 ++------------------
sys/log/full/src/log.c | 14 +++-----------
2 files changed, 5 insertions(+), 29 deletions(-)
diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h
index 1b0309e79..dc0cef7a0 100644
--- a/sys/log/full/include/log/log.h
+++ b/sys/log/full/include/log/log.h
@@ -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;
@@ -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)
@@ -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
@@ -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);
diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 68481b2e8..9c19893a5 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -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) {
@@ -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;
@@ -511,8 +509,6 @@ 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.
@@ -520,7 +516,6 @@ log_register(const char *name, struct log *log, const struct log_handler *lh,
if (hdr.ue_num_entries >= log->l_num_entries) {
log->l_num_entries = hdr.ue_num_entries + 1;
}
-#endif
OS_EXIT_CRITICAL(sr);
}
}
@@ -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;
}
@@ -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,
@@ -1093,7 +1085,6 @@ log_read_hdr(struct log *log, const void *dptr, struct log_entry_hdr *hdr)
return SYS_EIO;
}
}
-#endif
return 0;
}
@@ -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;
@@ -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
}