From commits-return-8427-archive-asf-public=cust-asf.ponee.io@nuttx.apache.org Wed Apr 29 23:10:25 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id A26D9180654 for ; Thu, 30 Apr 2020 01:10:25 +0200 (CEST) Received: (qmail 81656 invoked by uid 500); 29 Apr 2020 23:10:25 -0000 Mailing-List: contact commits-help@nuttx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nuttx.apache.org Delivered-To: mailing list commits@nuttx.apache.org Received: (qmail 81647 invoked by uid 99); 29 Apr 2020 23:10:25 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Apr 2020 23:10:25 +0000 From: =?utf-8?q?GitBox?= To: commits@nuttx.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bincubator-nuttx=5D_Oxore_opened_a_new_issue_=23912?= =?utf-8?q?=3A_tmpfs=3A_tmpfs=5Fstatfs_recursively_removes_files?= Message-ID: Date: Wed, 29 Apr 2020 23:10:24 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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