From b0698daaa42510c442936241f0a09e09d26a27e6 Mon Sep 17 00:00:00 2001 From: Xu Xingliang Date: Wed, 5 Jun 2024 10:49:17 +0800 Subject: [PATCH] fs: tweak backtrace for file open Signed-off-by: Xu Xingliang --- fs/inode/fs_files.c | 12 +----------- fs/inode/inode.h | 5 +++-- fs/procfs/fs_procfsproc.c | 7 +++---- fs/vfs/fs_open.c | 5 +++++ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index 5017a72a8e..338982a703 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -494,17 +494,7 @@ FAR char *file_dump_backtrace(FAR struct file *filep, FAR char *buffer, size_t len) { #if CONFIG_FS_BACKTRACE > 0 - FAR const char *format = "%0*p "; - int k; - - buffer[0] = '\0'; - for (k = 0; k < CONFIG_FS_BACKTRACE && filep->f_backtrace[k]; k++) - { - snprintf(buffer + k * FS_BACKTRACE_WIDTH, - len - k * FS_BACKTRACE_WIDTH, - format, FS_BACKTRACE_WIDTH - 1, - filep->f_backtrace[k]); - } + backtrace_format(buffer, len, filep->f_backtrace, CONFIG_FS_BACKTRACE); #else buffer[0] = '\0'; #endif diff --git a/fs/inode/inode.h b/fs/inode/inode.h index a3bfe991cb..aa92bb27c2 100644 --- a/fs/inode/inode.h +++ b/fs/inode/inode.h @@ -70,12 +70,13 @@ # define FS_ADD_BACKTRACE(filep) \ do \ { \ - int n = sched_backtrace(_SCHED_GETTID(), filep->f_backtrace, \ + int n = sched_backtrace(_SCHED_GETTID(), \ + (filep)->f_backtrace, \ CONFIG_FS_BACKTRACE, \ CONFIG_FS_BACKTRACE_SKIP); \ if (n < CONFIG_FS_BACKTRACE) \ { \ - (filep->f_backtrace)[n] = NULL; \ + (filep)->f_backtrace[n] = NULL; \ } \ } \ while (0) diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 4284d40008..f8e570b8a1 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -1245,6 +1245,9 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile, size_t buflen, off_t offset) { FAR struct task_group_s *group = tcb->group; + FAR struct file *filep; + char backtrace[BACKTRACE_BUFFER_SIZE(CONFIG_FS_BACKTRACE)]; + char path[PATH_MAX]; size_t remaining; size_t linesize; size_t copysize; @@ -1252,10 +1255,6 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile, int count; int i; - FAR struct file *filep; - char path[PATH_MAX]; - char backtrace[FS_BACKTRACE_BUFFER_LEN]; - DEBUGASSERT(group != NULL); count = files_countlist(&group->tg_filelist); diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index da2bc1c45c..2913f0cf24 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -350,6 +350,11 @@ int file_open(FAR struct file *filep, FAR const char *path, int oflags, ...) ret = file_vopen(filep, path, oflags, 0, ap); va_end(ap); + if (ret >= OK) + { + FS_ADD_BACKTRACE(filep); + } + return ret; }