This is an automated email from the ASF dual-hosted git repository. vipulrahane pushed a commit to branch vipul/logging_num_entries_callbacks in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 2c4185d1dc08b995e7637fee73ef166ced4876bd Author: Vipul Rahane <vipul.rah...@juul.com> AuthorDate: Tue Feb 11 17:19:20 2025 -0800 Minor fixes, build and CLI --- sys/log/common/include/log_common/log_common.h | 34 ++-------- sys/log/full/include/log/log.h | 89 +++++++++++++------------- sys/log/full/include/log/log_fcb.h | 2 +- sys/log/full/src/log.c | 2 +- sys/log/full/src/log_cbmem.c | 17 ++--- sys/log/full/src/log_fcb.c | 5 +- sys/log/full/src/log_shell.c | 5 +- 7 files changed, 65 insertions(+), 89 deletions(-) diff --git a/sys/log/common/include/log_common/log_common.h b/sys/log/common/include/log_common/log_common.h index 45e259f8c..92b139bcd 100644 --- a/sys/log/common/include/log_common/log_common.h +++ b/sys/log/common/include/log_common/log_common.h @@ -138,36 +138,14 @@ typedef void log_append_cb(struct log *log, uint32_t idx); */ typedef void log_notify_rotate_cb(const struct log *log); -/** @typedef log_cbmem_trailer_append_cb - * @brief Callback that is executed each time the corresponding log entry is - * appended to - * - * @param log The log that was just appended to - * @param buf Pointer to the buffer that contains the log entry - * @param buflen Length of the trailer - * @return 0 on success, non-zero on failure - */ -typedef int log_cbmem_trailer_append_cb(struct log *log, uint8_t *buf, - uint16_t buflen); - -/** @typedef log_cbmem_trailer_mbuf_append_cb - * @brief Callback that is executed each time the corresponding log entry is - * appended to - * - * @param log The log that was just appended to - * @param om Pointer to the mbuf - * - * @return 0 on success, non-zero on failure - */ -typedef int log_cbmem_trailer_mbuf_append_cb(struct log *log, struct os_mbuf *om); - /** @typedef log_trailer_append_cb * @brief Callback that is executed each time the corresponding log entry is * appended to * * @param log The log that was just appended to * @param buf Buffer to append trailer to - * @param buflen Length of the trailer to be filled up + * @param buflen Pointer to the length of the trailer to be filled up + * optionally * @param loc Argument pointing to the location of * the entry * @param f_offset Pointer to the offset(optional) at which append should @@ -176,7 +154,7 @@ typedef int log_cbmem_trailer_mbuf_append_cb(struct log *log, struct os_mbuf *om * @return 0 on success, non-zero on failure */ typedef int log_trailer_append_cb(struct log *log, uint8_t *buf, - uint16_t buflen, void *loc, + uint16_t *buflen, void *loc, uint16_t *f_offset); /** @typedef log_mbuf_trailer_append_cb @@ -199,14 +177,14 @@ typedef int log_trailer_mbuf_append_cb(struct log *log, struct os_mbuf *om, * @brief Callback that is executed each time a trailer is processed * * @param log The log that was just appended to - * @param hdr Pointer to the log netry header + * @param arg Void pointer for a custom arg * @param dptr Pointer to the data buffer * @param len Length of the trailer * * @return 0 on success, non-zero on failure */ -typedef int log_process_trailer_cb(struct log *log, struct log_entry_hdr *hdr, - const void *dptr, uint16_t len); +typedef int log_process_trailer_cb(struct log *log, void *arg, const void *dptr, + uint16_t len); /** @typedef log_trailer_len_cb * @brief Callback used to read length of trailer in a log entry diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h index 2be91efa6..745610b1e 100644 --- a/sys/log/full/include/log/log.h +++ b/sys/log/full/include/log/log.h @@ -247,8 +247,6 @@ struct log { log_trailer_append_cb *l_trailer_append_cb; log_process_trailer_cb *l_process_trailer_cb; log_trailer_mbuf_append_cb *l_trailer_mbuf_append_cb; - log_cbmem_trailer_append_cb *l_cbmem_trailer_append_cb; - log_cbmem_trailer_mbuf_append_cb *l_cbmem_trailer_mbuf_append_cb; void *l_trailer_arg; #if MYNEWT_VAL(LOG_STATS) STATS_SECT_DECL(logs) l_stats; @@ -724,9 +722,9 @@ uint8_t log_get_level(const struct log *log); void log_set_max_entry_len(struct log *log, uint16_t max_entry_len); /** - * Return last entry index in log. + * @brief Return last entry index in log. * - * @param log Log to check last entry index from. + * @param log Log to check last entry index from. * * @return last entry index */ @@ -734,13 +732,13 @@ uint32_t log_get_last_index(struct log *log); #if MYNEWT_VAL(LOG_STORAGE_INFO) /** - * Return information about log storage + * @brief Return information about log storage * * This return information about size and usage of storage on top of which log * instance is created. * - * @param log The log to query. - * @param info The destination to write information to. + * @param log The log to query. + * @param info The destination to write information to. * * @return 0 on success, error code otherwise * @@ -749,17 +747,17 @@ int log_storage_info(struct log *log, struct log_storage_info *info); #endif /** - * Assign a callback function to be notified when the log is about to be rotated. + * @brief Assign a callback function to be notified when the log is about to be rotated. * - * @param log The log - * @param cb The callback function to be executed. + * @param log The log + * @param cb The callback function to be executed. */ void log_set_rotate_notify_cb(struct log *log, log_notify_rotate_cb *cb); #if MYNEWT_VAL(LOG_STORAGE_WATERMARK) /** - * Set watermark on log + * @brief Set watermark on log * * This sets watermark on log item with given index. This information is used * to calculate size of entries which were logged after watermark item, i.e. @@ -774,9 +772,9 @@ int log_set_watermark(struct log *log, uint32_t index); #endif /** - * Fill log current image hash + * @brief Fill log current image hash * - * @param hdr Ptr to the header + * @param hdr Ptr to the header * * @return 0 on success, non-zero on failure */ @@ -784,10 +782,10 @@ int log_fill_current_img_hash(struct log_entry_hdr *hdr); /** - * Get the length of data in medium - storage (fcb/fcb2), memory or stream + * @brief Get the length of data in medium - storage (fcb/fcb2), memory or stream * - * @param log The log to get number of entries for - * @param len Length in medium with padding if any + * @param log The log to get number of entries for + * @param len Length in medium with padding if any */ int log_len_in_medium(struct log *log, uint16_t len); @@ -795,50 +793,51 @@ log_len_in_medium(struct log *log, uint16_t len); /** * @brief Reads the trailer length * - * @param hdr Ptr to the header + * @param hdr Ptr to the header * * @return Length of the trailer */ uint16_t log_trailer_len(struct log *log, const struct log_entry_hdr *hdr); /** - * Append trailer to the log entry + * @brief Append trailer to the log entry * - * @param log Pointer to the log - * @param buf Pointer to the buffer containing trailer - * @param buflen Length of the trailer - * @param loc Pointer to the log entry - * @param f_offset Pointer to the offset(optional) at which append should - * happen, gets updated once append is successful + * @param log Pointer to the log + * @param buf Pointer to the buffer containing trailer + * @param buflen Pointer to the length of the trailer + * @param loc Pointer to the log entry + * @param f_offset Pointer to the offset(optional) at which append should + * happen, gets updated once append is successful * @return 0 on success, non-zero on failure */ int -log_trailer_append(struct log *log, uint8_t *buf, uint16_t buflen, +log_trailer_append(struct log *log, uint8_t *buf, uint16_t *buflen, void *loc, uint16_t *f_offset); /** - * Append trailer in an mbuf to the log entry + * @brief Append trailer in an mbuf to the log entry * - * @param log Pointer to the log - * @param om Pointer to the os_mbuf - * @param loc Pointer to the log entry - * @param f_offset The offset(optional) at which append should - * happen + * @param log Pointer to the log + * @param om Pointer to the os_mbuf + * @param loc Pointer to the log entry + * @param f_offset The offset(optional) at which append should + * happen + * @return 0 on success; nonzero on failure. */ int log_mbuf_trailer_append(struct log *log, struct os_mbuf *om, void *loc, uint16_t f_offset); /** - * Reads the final log entry's header and processes trailer if the flag + * @brief Reads the final log entry's header and processes trailer if the flag * indicates so from the specified log. * - * @param log The log to read from. - * @param out_hdr On success, the last entry header gets written - * here. - * @param trailer_exists Pointer to a boolean + * @param log The log to read from. + * @param out_hdr On success, the last entry header gets written + * here. + * @param trailer_exists Pointer to a boolean * - * @return 0 on success; nonzero on failure. + * @return 0 on success; nonzero on failure. */ int log_read_last_hdr_trailer(struct log *log, struct log_entry_hdr *out_hdr, @@ -846,12 +845,12 @@ log_read_last_hdr_trailer(struct log *log, struct log_entry_hdr *out_hdr, #if MYNEWT_VAL(LOG_FLAGS_TRAILER_SUPPORT) /** - * Register trailer callbacks + * @brief Register trailer callbacks * - * @param log Pointer to the log - * @param ltac Pointer to the log trailer append callback - * @param ltlc Pointer to the log trailer length callback - * @param lptc Pointer to the log process trailer callback + * @param log Pointer to the log + * @param ltac Pointer to the log trailer append callback + * @param ltlc Pointer to the log trailer length callback + * @param lptc Pointer to the log process trailer callback */ static inline void log_register_trailer_cbs(struct log *log, log_trailer_append_cb *ltac, @@ -864,10 +863,10 @@ log_register_trailer_cbs(struct log *log, log_trailer_append_cb *ltac, } /** - * Register trailer callbacks + * @brief Register trailer callbacks * - * @param log Pointer to the log - * @param ltmac Pointer to the log trailer mbuf append callback + * @param log Pointer to the log + * @param ltmac Pointer to the log trailer mbuf append callback */ static inline void log_register_mbuf_trailer_cbs(struct log *log, diff --git a/sys/log/full/include/log/log_fcb.h b/sys/log/full/include/log/log_fcb.h index ff81fcc28..f787c1521 100644 --- a/sys/log/full/include/log/log_fcb.h +++ b/sys/log/full/include/log/log_fcb.h @@ -146,7 +146,7 @@ const struct log_fcb_bmark * log_fcb_closest_bmark(const struct fcb_log *fcb_log, uint32_t index); /** - * Inserts a bookmark into the provided log. + * @brief Inserts a bookmark into the provided log. * * @param fcb_log The log to insert a bookmark into. * @param entry The entry the bookmark should point to. diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c index 957560fb6..05b8d238d 100644 --- a/sys/log/full/src/log.c +++ b/sys/log/full/src/log.c @@ -495,7 +495,7 @@ log_trailer_len(struct log *log, const struct log_entry_hdr *hdr) } int -log_trailer_append(struct log *log, uint8_t *buf, uint16_t buflen, +log_trailer_append(struct log *log, uint8_t *buf, uint16_t *buflen, void *loc, uint16_t *f_offset) { if (log->l_trailer_append_cb) { diff --git a/sys/log/full/src/log_cbmem.c b/sys/log/full/src/log_cbmem.c index 9940384b8..364ec5087 100644 --- a/sys/log/full/src/log_cbmem.c +++ b/sys/log/full/src/log_cbmem.c @@ -60,12 +60,12 @@ log_cbmem_append_body(struct log *log, const struct log_entry_hdr *hdr, } if (hdr->ue_flags & LOG_FLAGS_TRAILER_SUPPORT) { - if (log->l_cbmem_trailer_append_cb) { - rc = log->l_cbmem_trailer_append_cb(log, trailer, trailer_len); - if (!rc) { - sg->count += ((trailer_len - sizeof(sg->count))/sizeof(sg->entries[0])); - sg->entries[3].flat_len = trailer_len; - } + rc = log_trailer_append(log, trailer, &trailer_len, NULL, NULL); + if (rc && rc != SYS_ENOTSUP) { + return rc; + } else if (!rc) { + sg->count += ((trailer_len - sizeof(sg->count))/sizeof(sg->entries[0])); + sg->entries[3].flat_len = trailer_len; } } @@ -115,8 +115,9 @@ log_cbmem_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr, } if (hdr->ue_flags & LOG_FLAGS_TRAILER_SUPPORT) { - if (log->l_cbmem_trailer_mbuf_append_cb) { - log->l_cbmem_trailer_mbuf_append_cb(log, om); + rc = log_mbuf_trailer_append(log, om, NULL, 0); + if (rc) { + return rc; } } diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c index 91ff20a97..9928ad96b 100644 --- a/sys/log/full/src/log_fcb.c +++ b/sys/log/full/src/log_fcb.c @@ -26,7 +26,6 @@ #include "flash_map/flash_map.h" #include "fcb/fcb.h" #include "log/log.h" -#include <console/console.h> static int log_fcb_rtr_erase(struct log *log); @@ -293,7 +292,7 @@ log_fcb_write_mbuf(struct fcb_entry *loc, struct os_mbuf *om) return 0; } -int +static int log_fcb_hdr_trailer_bytes(uint16_t align, uint16_t len) { uint16_t mod; @@ -422,7 +421,7 @@ log_fcb_append_body(struct log *log, const struct log_entry_hdr *hdr, /* The first trailer gets appended after the padding + trailer_alignment * Trailers start from updated loc.fe_data_off. */ - rc = log_trailer_append(log, buf, trailer_len, &loc, NULL); + rc = log_trailer_append(log, buf, &trailer_len, &loc, NULL); if (rc && rc != SYS_ENOTSUP) { return rc; } diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c index 60d37399d..a10c08eb1 100644 --- a/sys/log/full/src/log_shell.c +++ b/sys/log/full/src/log_shell.c @@ -88,8 +88,6 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset, bool read_hash = ueh->ue_flags & LOG_FLAGS_IMG_HASH; bool add_lf = true; - dlen = min(len, 128); - if (arg) { arg->count++; /* Continue walk if number of entries to skip not reached yet */ @@ -98,6 +96,8 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset, } } + dlen = min(len, 128); + if (read_data) { rc = log_read_body(log, dptr, data, 0, dlen); if (rc < 0) { @@ -118,7 +118,6 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset, console_printf(" [%llu] ", ueh->ue_ts); } - console_printf(" [%llu] ", ueh->ue_ts); #if MYNEWT_VAL(LOG_SHELL_SHOW_INDEX) console_printf(" [ix=%lu] ", ueh->ue_index); #endif