This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8d7916e57aa5c6ab3d788c9d1bfaf756c5bb5425
Author: jingfei <[email protected]>
AuthorDate: Thu Sep 17 09:57:38 2026 +0800

    fs/mount: drop statfs from mountpoint traversal
    
    umount_all() drives foreach_mountpoint() with the inode write lock held
    for the whole traversal. mountpoint_filter() issued a statfs() on every
    mountpoint inside that lock. For a proxy filesystem whose statfs is a
    blocking cross-core RPC, the reboot thread then waits (no timeout) for a
    reply while holding the write lock, and the peer core cannot make
    progress because the handler that serves its requests is itself blocked
    on the same lock as a reader -- a ring wait that hangs the system.
    
    statfs is not needed by the traversal itself. Make foreach_mountpoint_t
    hand only the mountpoint path; the only consumer that needs statfs
    (procfs fs/mount, fs/blocks, fs/usage) now calls statfs() itself, under
    its own read-lock traversal where recursive read is safe. This also
    unmounts mountpoints whose fs has no statfs method, which the old
    statfs-gated filter silently skipped.
    
    Signed-off-by: jingfei <[email protected]>
---
 fs/mount/fs_foreachmountpoint.c | 25 +++++-----------
 fs/mount/fs_procfs_mount.c      | 66 ++++++++++++++++++++++++++++-------------
 fs/mount/fs_umount2.c           |  5 +---
 fs/mount/mount.h                |  1 -
 4 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/fs/mount/fs_foreachmountpoint.c b/fs/mount/fs_foreachmountpoint.c
index 9607acf0944..5b20058644f 100644
--- a/fs/mount/fs_foreachmountpoint.c
+++ b/fs/mount/fs_foreachmountpoint.c
@@ -26,8 +26,6 @@
 
 #include <nuttx/config.h>
 
-#include <sys/statfs.h>
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -67,23 +65,20 @@ static int mountpoint_filter(FAR struct inode *node,
                              FAR char dirpath[PATH_MAX], FAR void *arg)
 {
   FAR struct enum_mountpoint_s *info = (FAR struct enum_mountpoint_s *)arg;
-  struct statfs statbuf;
   int pathlen;
   int namlen;
   int ret = OK;
 
   DEBUGASSERT(node && info && info->handler);
 
-  /* Check if the inode is a mountpoint.  Mountpoints must support statfs.
-   * If this one does not for some reason, then it will be ignored.
-   *
-   * The root node is a special case: It has no operations (u.i_mops == NULL)
+  /* Forward the mountpoint path only; callers needing statfs query it
+   * themselves.
    */
 
-  if (INODE_IS_MOUNTPT(node) && node->u.i_mops && node->u.i_mops->statfs)
+  if (INODE_IS_MOUNTPT(node))
     {
-      /* Yes... get the full path to the inode by concatenating the inode
-       * name and the path to the directory containing the inode.
+      /* Get the full path to the inode by concatenating the inode name and
+       * the path to the directory containing the inode.
        */
 
       pathlen = strnlen(dirpath, PATH_MAX);
@@ -100,15 +95,9 @@ static int mountpoint_filter(FAR struct inode *node,
 
       snprintf(&dirpath[pathlen], PATH_MAX - pathlen, "/%s", node->i_name);
 
-      /* Get the status of the file system */
-
-      memset(&statbuf, 0, sizeof(struct statfs));
-      if (node->u.i_mops->statfs(node, &statbuf) == OK)
-        {
-          /* And pass the full path and file system status to the handler */
+      /* Pass the full path to the handler */
 
-          ret = info->handler(dirpath, &statbuf, info->arg);
-        }
+      ret = info->handler(dirpath, info->arg);
 
       /* Truncate the path name back to the correct length */
 
diff --git a/fs/mount/fs_procfs_mount.c b/fs/mount/fs_procfs_mount.c
index 0bdbc0c1590..56eebb81e44 100644
--- a/fs/mount/fs_procfs_mount.c
+++ b/fs/mount/fs_procfs_mount.c
@@ -106,16 +106,13 @@ struct mount_info_s
 static void    mount_sprintf(FAR struct mount_info_s *info,
                              FAR const char *fmt, ...) printf_like(2, 3);
 #ifndef CONFIG_FS_PROCFS_EXCLUDE_MOUNT
-static int     mount_entry(FAR const char *mountpoint,
-                           FAR struct statfs *statbuf, FAR void *arg);
+static int     mount_entry(FAR const char *mountpoint, FAR void *arg);
 #endif
 #ifndef CONFIG_FS_PROCFS_EXCLUDE_BLOCKS
-static int     blocks_entry(FAR const char *mountpoint,
-                            FAR struct statfs *statbuf, FAR void *arg);
+static int     blocks_entry(FAR const char *mountpoint, FAR void *arg);
 #endif
 #ifndef CONFIG_FS_PROCFS_EXCLUDE_USAGE
-static int     usage_entry(FAR const char *mountpoint,
-                           FAR struct statfs *statbuf, FAR void *arg);
+static int     usage_entry(FAR const char *mountpoint, FAR void *arg);
 #endif
 
 /* File system methods */
@@ -212,17 +209,26 @@ static void mount_sprintf(FAR struct mount_info_s *info,
  ****************************************************************************/
 
 #ifndef CONFIG_FS_PROCFS_EXCLUDE_MOUNT
-static int mount_entry(FAR const char *mountpoint,
-                       FAR struct statfs *statbuf, FAR void *arg)
+static int mount_entry(FAR const char *mountpoint, FAR void *arg)
 {
   FAR struct mount_info_s *info = (FAR struct mount_info_s *)arg;
   FAR const char *fstype;
+  struct statfs statbuf;
 
-  DEBUGASSERT(mountpoint != NULL && statbuf != NULL && info != NULL);
+  DEBUGASSERT(mountpoint != NULL && info != NULL);
+
+  /* Query the file system here (the traversal only hands us the path).
+   * Skip this entry if it cannot be stat'ed.
+   */
+
+  if (statfs(mountpoint, &statbuf) < 0)
+    {
+      return OK;
+    }
 
   /* Get the file system type */
 
-  fstype = fs_gettype(statbuf);
+  fstype = fs_gettype(&statbuf);
 
   /* Generate mount list one line at a time */
 
@@ -243,12 +249,21 @@ static int mount_entry(FAR const char *mountpoint,
  ****************************************************************************/
 
 #ifndef CONFIG_FS_PROCFS_EXCLUDE_BLOCKS
-static int blocks_entry(FAR const char *mountpoint,
-                        FAR struct statfs *statbuf, FAR void *arg)
+static int blocks_entry(FAR const char *mountpoint, FAR void *arg)
 {
   FAR struct mount_info_s *info = (FAR struct mount_info_s *)arg;
+  struct statfs statbuf;
+
+  DEBUGASSERT(mountpoint != NULL && info != NULL);
 
-  DEBUGASSERT(mountpoint != NULL && statbuf != NULL && info != NULL);
+  /* Query the file system here (the traversal only hands us the path).
+   * Skip this entry if it cannot be stat'ed.
+   */
+
+  if (statfs(mountpoint, &statbuf) < 0)
+    {
+      return OK;
+    }
 
   /* Have we generated the header yet? */
 
@@ -265,8 +280,8 @@ static int blocks_entry(FAR const char *mountpoint,
 
   mount_sprintf(info, "%6zu %10" PRIuOFF " %10" PRIuOFF
                 "  %10" PRIuOFF " %s\n",
-                statbuf->f_bsize, statbuf->f_blocks,
-                statbuf->f_blocks - statbuf->f_bavail, statbuf->f_bavail,
+                statbuf.f_bsize, statbuf.f_blocks,
+                statbuf.f_blocks - statbuf.f_bavail, statbuf.f_bavail,
                 mountpoint);
 
   return (info->totalsize >= info->buflen) ? 1 : 0;
@@ -285,11 +300,11 @@ static int blocks_entry(FAR const char *mountpoint,
  ****************************************************************************/
 
 #ifndef CONFIG_FS_PROCFS_EXCLUDE_USAGE
-static int usage_entry(FAR const char *mountpoint,
-                       FAR struct statfs *statbuf, FAR void *arg)
+static int usage_entry(FAR const char *mountpoint, FAR void *arg)
 {
   FAR struct mount_info_s *info = (FAR struct mount_info_s *)arg;
   FAR const char *fstype;
+  struct statfs statbuf;
   fsblkcnt_t size;
   fsblkcnt_t used;
   fsblkcnt_t free;
@@ -302,7 +317,16 @@ static int usage_entry(FAR const char *mountpoint,
     'B', 'K', 'M', 'G', 'T'
   };
 
-  DEBUGASSERT(mountpoint != NULL && statbuf != NULL && info != NULL);
+  DEBUGASSERT(mountpoint != NULL && info != NULL);
+
+  /* Query the file system here (the traversal only hands us the path).
+   * Skip this entry if it cannot be stat'ed.
+   */
+
+  if (statfs(mountpoint, &statbuf) < 0)
+    {
+      return OK;
+    }
 
   /* Have we generated the header yet? */
 
@@ -315,10 +339,10 @@ static int usage_entry(FAR const char *mountpoint,
 
   /* Get the file system type */
 
-  fstype = fs_gettype(statbuf);
+  fstype = fs_gettype(&statbuf);
 
-  size = statbuf->f_bsize * statbuf->f_blocks;
-  free = statbuf->f_bsize * statbuf->f_bavail;
+  size = statbuf.f_bsize * statbuf.f_blocks;
+  free = statbuf.f_bsize * statbuf.f_bavail;
   used = size - free;
 
   /* Find the label for size */
diff --git a/fs/mount/fs_umount2.c b/fs/mount/fs_umount2.c
index d313f4ab6dc..6452c1da2f1 100644
--- a/fs/mount/fs_umount2.c
+++ b/fs/mount/fs_umount2.c
@@ -27,7 +27,6 @@
 #include <nuttx/config.h>
 
 #include <sys/mount.h>
-#include <sys/statfs.h>
 #include <stdbool.h>
 #include <errno.h>
 #include <assert.h>
@@ -63,13 +62,11 @@
  *
  ****************************************************************************/
 
-static int umount_all_handler(FAR const char *mountpoint,
-                              FAR struct statfs *statbuf, FAR void *arg)
+static int umount_all_handler(FAR const char *mountpoint, FAR void *arg)
 {
   int ret;
 
   UNUSED(arg);
-  UNUSED(statbuf);
 
   /* Force-unmount the mountpoint.  nx_umount2() re-resolves the path and
    * flushes (syncfs) before unbind under the inode write lock that
diff --git a/fs/mount/mount.h b/fs/mount/mount.h
index b74023fc545..26b0cd8d339 100644
--- a/fs/mount/mount.h
+++ b/fs/mount/mount.h
@@ -45,7 +45,6 @@ struct inode;  /* Forward reference */
  */
 
 typedef int (*foreach_mountpoint_t)(FAR const char *mountpoint,
-                                    FAR struct statfs *statbuf,
                                     FAR void *arg);
 
 /****************************************************************************

Reply via email to