You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/04/29 23:10:24 UTC

[GitHub] [incubator-nuttx] Oxore opened a new issue #912: tmpfs: tmpfs_statfs recursively removes files

Oxore opened a new issue #912:
URL: https://github.com/apache/incubator-nuttx/issues/912


   # Steps to reproduce
   ## Prerequisites
   
   Linux environment. `arm-none-eabi-gcc` toolchain, gcc version 9.3.0. QEMU with ARM emulation.
   
   **NuttX commit:** 5b839061f960cadb3fda19a51679484b95f8d6e3
   
   **Apps commit:** dcc620e6b8418f81615f7875db56ed443ac642d6
   
   ## Preparation
   
   Let's assume we have cloned NuttX repo into `/nuttx` and apps repo into `/apps`.  Current working directory: `/nuttx`. Prepare config:
   
       ./tools/configure.sh -l -a ../apps lm3s6965-ek:nsh
   
   Adjust configuration:
   
       CONFIG_TIVA_ETHERNET=n
       CONFIG_NET=n
       CONFIG_FS_TMPFS=y
       CONFIG_FS_PROCFS=y
   
   Build:
   
       CROSSDEV=arm-none-eabi- make
   
   Run:
   
       qemu-system-arm -M lm3s6965evb -kernel ./nuttx
   
   Go to `serial0` (Ctrl+Alt+3) and get the console.
   
   ## Actual steps to reproduce
   
   At `nsh` prompt type:
   
       mkdir /tmp/dir
       echo >/tmp/file
       echo >/tmp/dir/file2
       ls /tmp
       ls /tmp/dir
   
   You can see created files and directory. Now run the following:
   
       df
   
   or:
   
       cat /proc/fs/usage
   
   then run:
   
       ls /tmp
       ls /tmp/dir
   
   There is no `/tmp/dir/file2` anymore, but `/tmp/file` still exists, though. So files in `/tmp` always exist, but any directory in `/tmp` becomes recursively cleaned up.
   
   I expect, that when I run `df`, all my files in `/tmp` and deeper do not get changed or deleted, but they disappear.
   
   # Possible fix or just pointing to a buggy line of code
   
   When file `/proc/fs/tmpfs` is being read, it's `read` op calls `tmpfs_statfs`, that has subsequent call to `tmpfs_foreach`, which contains unconditional recursive call to itself with `tmpfs_free_callout` value being passed to the argument `callout`. This is why all files **in all directories of** `/tmp` disappear, but files and directories in `/tmp` (the root of `tmpfs`) stay on.
   
   Here is an "one line" fix:
   
   ```diff
   diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c
   index 43fb0fc081..915ccb6aec 100644
   --- a/fs/tmpfs/fs_tmpfs.c
   +++ b/fs/tmpfs/fs_tmpfs.c
   @@ -1322,7 +1322,7 @@ static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo,
               * action will be to delete the directory.
               */
   
   -          ret = tmpfs_foreach(next, tmpfs_free_callout, NULL);
   +          ret = tmpfs_foreach(next, callout, arg);
              if (ret < 0)
                {
                  return -ECANCELED;
   ```
   
   So...
   
   **Does it fix the bug?** Yes, it looks like it fixes it. If we create more files we get values increased in `df` output for `/tmp` and all files in `/tmp` and in it's directories persist.
   
   **Does it introduce more bugs?** I don't know.
   
   How can I test it? I hope that original author has better understanding of what is going on here and how to properly fix the bug.
   
   I can try to open a pull request and carefully adjust all the code around, if somebody explain how I test my changes or at least point the places where to put attention to.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on issue #912: tmpfs: tmpfs_statfs recursively removes files

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on issue #912:
URL: https://github.com/apache/incubator-nuttx/issues/912#issuecomment-621570571


   @Oxore thanks for the detailed bug report and analysis. Your change looks correctly, could you open a PR?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org