Commit Graph

468 Commits

Author SHA1 Message Date
wangjianyu3 1bb0f19fd5 fs/rename: Do not send notify if the same
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-09-15 10:11:42 +08:00
ligd fab9369093 poll: fix thread_cancel() caused poll used after free
pthread 0          pthread1
fd 0
poll_setup
wait
                   cancel(thread 0)
                   fd 0 close
                   fd 0 notify (sem used after free)
poll_teardown

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-14 20:15:12 +08:00
ligd 6a2c03732f clock: Replace all ts and tick conversion functions
Using the ts/tick conversion functions provided in clock.h

Do this caused we want speed up the time calculation, so change:
clock_time2ticks, clock_ticks2time, clock_timespec_add,
clock_timespec_compare, clock_timespec_subtract... to MACRO

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
zhanghongyu 420648b0c6 drivers/pipes: add fcntl(F_SETPIPE_SZ/F_GETPIPE_SZ) support
allows user programs to modify pipe size, but not larger than
CONFIG_DEV_PIPE_MAXSIZE

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-09-10 11:35:15 +08:00
hujun5 198630a809 sched: use this_task replace nxsched_self
reason:
We can reduce a function call to improve performance.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-05 09:33:50 -03:00
Petro Karashchenko 1528b8dcca nuttx: resolve various 'FAR' and 'CODE' issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-26 10:21:03 +08:00
buxiasen 946ed96926 fs: add fs_heap, support shm/tmpfs/pseudofile with indepent heap
For some case, need large files from tmpfs or shmfs, will lead to high
pressure on memory fragments, add an optional fs_heap with independent
heap will benifit for memory fragments issue.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-08-25 22:12:37 +08:00
guohao15 94e9599e5c file_lock:fix memory alloc/free not match
Signed-off-by: guohao15 <guohao15@xiaomi.com>
2024-08-22 20:25:30 +08:00
chenrun1 271f76590f fs_lock/pathbuffer:Optimize code structure
Summary:
  Adjust code logic

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-22 01:54:22 +08:00
chenrun1 dba77ff043 fslock:Optimize the performance overhead caused by frequent close
Summary:
  Indicate whether the file is currently locked by adding a new field locked to filep.
    0 - Unlocked
    1 - Locked
  The status of the filep at close is used to determine whether to continue with the following procedure.

  Optimizing performance:
Before
  Time taken to close the file: 33984 nsec
After
  Time taken to close the file: 23744 nsec
Improvement of about 10 msec

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-22 01:54:22 +08:00
chenrun1 c528244f19 fs_lock:Fixed the problem that in multi-threaded situations, the bucket may be deleted by other factors during the search process, resulting in assertion.
hsearch_r(item = (key = 0x61492174,data = ?),action = ?, retval = 0x6266AC44, htab = 0x6159B758) H 1tem = Ckey = 0x61492174, data= :
 · action = ?
  retval = 0x6266AC44
  htab = 0x6159B758
  haad - 0x61616300
  ie= 0×38

file_lock_find_bucket(inline)
  filepath = 0x61492174
  hretvalue = 0x6055991D
  item = (key = 0x61492174, data = 0x0)

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-22 01:54:22 +08:00
chenrun1 0bf2634631 fs_lock:Reduce stack size
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-22 01:54:22 +08:00
guohao15 86e00896d3 fs:notify add support for inotify
support API: open close read write unlink mkdir rename fchstat rmdir symlink

Signed-off-by: guohao15 <guohao15@xiaomi.com>
2024-08-22 01:50:37 +08:00
guohao15 bed1845333 inode:call inode_release when close success
inode will be double released
in close(fd) and files_putlist(&group->tg_filelist)

Signed-off-by: guohao15 <guohao15@xiaomi.com>
2024-08-21 13:31:25 +08:00
chenrun1 d65f8bd4c1 filelock:Move filelock call to ioctl
Forward the implementation originally placed in fcntl to ioctl. in order
to achieve cross-core.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-18 19:56:49 +08:00
chenrun1 a1e3444df0 rpmsgfs:Support cross-core access using file locks on the same file
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-18 19:56:49 +08:00
Xiang Xiao 7c1768c167 fs/epoll: Double array size when it is full
correct the sequnce of array size from:
size, size, 2*size, 4*size, 8*size...
to:
size, 2*size, 4*size, 8*size, 16*size...

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-08-17 00:19:15 +02:00
Xiang Xiao 56b2e7254a fs/poll: Compute tick from millisecond by MSEC2TICK
reduce duplicate code

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-08-17 00:19:15 +02:00
Xu Xingliang b0698daaa4 fs: tweak backtrace for file open
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
2024-06-30 17:30:42 +08:00
Xu Xingliang 69d8a17dda fs: add backtrace to where file opens
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
2024-06-24 23:53:59 +08:00
Yanfeng Liu ce0c98f0fd fs/lock: prefer nxsched_self for modularity
Use of nxsched_self() is preferred from outside of the sched/ folder.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-06-09 20:22:02 +08:00
hujun5 236ec9844f fs: dup3 should pass the fdcheck & fdsan
Signed-off-by: hujun5 <hujun5@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-03-07 09:08:48 +08:00
ligd e1cd082c29 fs: enhance dup3() mulit-threads saftey
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-03-07 09:08:48 +08:00
hujun5 577eb47966 fdcheck: Enable fdcheck to automatically detect ownership of fd
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-03-07 09:08:48 +08:00
chao an 6d50274ebe nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications

In file included from libuv/src/unix/internal.h:25,
                 from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
   57 | #define container_of(ptr, type, member) \
      |
In file included from nuttx/include/nuttx/list.h:47,
                 from nuttx/include/nuttx/tls.h:40,
                 from nuttx/include/nuttx/sched.h:48,
                 from nuttx/include/nuttx/arch.h:87,
                 from nuttx/include/nuttx/userspace.h:35,
                 from nuttx/include/nuttx/mm/mm.h:30,
                 from nuttx/include/nuttx/kmalloc.h:34,
                 from nuttx/include/nuttx/lib/lib.h:31,
                 from nuttx/include/stdio.h:35,
                 from apps/system/libuv/libuv/include/uv.h:59,
                 from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
   48 | #define container_of(ptr, type, member) \
      |

Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 19:44:54 +08:00
chenrun1 ae730ac246 fs_lock:Avoid deadlock caused by KILL SIGNAL
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-21 13:29:36 -03:00
chenrun1 6e3e03f6b0 fs/vfs:cmakelists add fs_lock config
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-21 13:29:36 -03:00
Zhe Weng 14602be4cc fs/lock: Limit inode type for file locks
When we close a socket fd, it will call get path on sockets.
`close(socket_fd)` -> `file_closelk(filep)` -> `file_fcntl(F_GETPATH)`
It causes a heavy stack load for each socket close operation.
(We have `GETPATH` for sockets to be used for `fdinfo`)

But the socket fds are not intended to be used for file locks.
And so do some other file types, so we may just limit the usage of flock.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-02-21 13:29:36 -03:00
chenrun1 8cdec83adb fs_locks:Fix getlk's l pid return
When there is no conflicting lock, getlk should not tamper with the l_pid content from the upper layer

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-21 13:29:36 -03:00
chenrun1 5c6bd833ed fs_lock:Implementing file locks
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-21 13:29:36 -03:00
Saurav Pal 93d03d0418 fs: Add VFS docs
This commit adds VFS docmentation, and details about the VFS interface.

Signed-off-by: Saurav Pal <resyfer.dev@gmail.com>
2024-02-20 18:28:09 -08:00
Ville Juven f0846e1d2d fs/shmfs: Fix stat() system call for shmfs object
Set i_size for shmfs objects
2024-02-02 09:12:18 -08:00
Ville Juven 43a26220be fs/shmfs: Fix CONFIG_FS_SHM -> CONFIG_FS_SHMFS
The macro was wrong
2024-01-31 08:51:52 -08:00
chao an 8ff97f6210 compiler/tasking: fix unreachable code on tasking toolchain
ctc W544: ["serial/serial.c" 284/3] unreachable code
ctc W544: ["vfs/fs_lseek.c" 96/13] unreachable code
ctc W544: ["wqueue/kwork_thread.c" 210/32] unreachable code
ctc W544: ["stdio/lib_fopen.c" 327/19] unreachable code
ctc W544: ["stdio/lib_fopen.c" 404/13] unreachable code
ctc W544: ["string/lib_strcasestr.c" 120/3] unreachable code
ctc W544: ["unistd/lib_getopt_common.c" 156/21] unreachable code
ctc W544: ["unistd/lib_getopt_common.c" 216/21] unreachable code
ctc W544: ["wctype/lib_iswctype.c" 155/3] unreachable code

Signed-off-by: chao an <anchao@lixiang.com>
2024-01-30 20:53:00 -08:00
yinshengkai 9852428953 fs: procfs add poll support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-12-26 19:23:13 -08:00
Xiang Xiao eddd90de78 poll: pollsetup should notify only one fd passd by caller
since it's redundant to iterate the whole fds array in setup

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-11-21 09:07:17 +01:00
zhanghongyu 3610b25c91 cmake: add include path for special source
fix the cmake build error.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-11-07 17:39:03 +01:00
Bowen Wang 2f9c082f8f fs_epoll: serveral epoll issues fix
1. fs_epoll: try again when epoll_teardown() return 0
when poll_notify() called larger than twice when epoll_wait() blocked
in the eph->sem, the semcount will be larger than 1 when epoll_wait()
unblocked and will return 0 directly at the next epoll_wait.
So retry to wait the eph->sem again when epoll_teardown return 0.

2. fs_epoll: poll_setup the fd again even this fd got non-expected event
Some poll implementations need call poll_setup again when their internal
states changed (e.g., local socket), so should add the fd to the epoll
teardown list and poll_setup again at the next epoll_wait even this fd
got the user non-expected event.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-11-02 00:44:52 +08:00
dongjiuzhu1 73dc8f84cc fs/dup3: impletement dup3/nx_dup3_from_tcb function
refs: https://man7.org/linux/man-pages/man2/dup.2.html

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-27 21:15:07 +08:00
dongjiuzhu1 dc2dac2377 fs/dup/dup2: don't add O_CLOEXEC for new file descriptor
refs: https://man7.org/linux/man-pages/man2/dup.2.html

The two file descriptors do not share file descriptor flags (the
close-on-exec flag).  The close-on-exec flag (FD_CLOEXEC; see
fcntl(2)) for the duplicate descriptor is off.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-27 21:15:07 +08:00
dongjiuzhu1 dcc006035d fs/rename: fix use after free issue about rename
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-26 01:04:23 +08:00
Xiang Xiao d84aba8a42 fs: Change inode_checkflags to static function
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-22 21:23:08 +03:00
Xiang Xiao b1c8c84e81 stdio: Merge fs_fdopen into fdopen to simplify the code logi
since fs_fdopen could avoid call the kernel specific function now

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 13:34:00 +08:00
Xiang Xiao 62c2b1abba stdio: Initialize stdin, stdout and stderr directly
and then remove group_setupstreams

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 13:34:00 +08:00
ThomasNS 696717b28b add munmap logic to pseudofs 2023-10-13 03:17:27 +08:00
guohao15 2bce0f404c fs:add syncfs api for sync whole fs data
Signed-off-by: guohao15 <guohao15@xiaomi.com>
2023-09-23 15:58:00 +08:00
Petro Karashchenko 0e42808923 fs/vfs: remove redundant return in nx_vopen
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-09-16 14:17:47 +08:00
dongjiuzhu1 6367f2469c fs/vfs: fix dup issue for eventfd/signalfd/timerfd
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-09-11 19:57:34 +08:00
xuxin19 b1cc5b50b1 cmake:complete missing changes during cmake reforming for fs
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-09-08 21:20:16 +03:00
wanggang26 3dbface167 Revert commit 35602cc2ef
Reason for revert: when block device enable bch proxy, fsync calling would be failed

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-08-25 20:37:38 +03:00