Repository navigation
fs/vfs: sync mounted filesystems in sync() - #21999
Conversation
|
sync() only fsync'd open descriptors, so filesystem-level state that no open fd carries (e.g. a file the kernel opened for a loop device) was never persisted. Move sync() into fs_sync.c and have it also syncfs() every mountpoint. Signed-off-by: jingfei <[email protected]>
aa0b5f0 to
fbbff87
Compare
|
@xiaoxiang781216 @jingfei195887 @GUIDINGLI This change pulls the whole
Measured on
In the minimal image: So a minimal image grows by a quarter, to walk mountpoints that don't exist. Could the path in |
|
@raiden00pl Thanks for measuring this, I reproduced it. The fix is in #22166.
The growth is larger than in your numbers because with these compilers the printf engine also pulls in #22166 builds the path in Note that in images that register any driver or open a file, printf is already linked by |
Summary
fs/vfs: sync mounted filesystems in sync().
sync()only calledfile_fsync()on the open descriptors of each task,so state that no task descriptor refers to was never flushed. For
example, the backing file of a loop device on hostfs is opened by the
kernel with
file_open(), sosync()never flushed it to the host.Move
sync()and itstask_fssync()helper fromfs/inode/fs_files.cinto a new
fs/vfs/fs_sync.c, next tofs_syncfs.c. After the per-taskfsync,
sync()now walks the inode tree withforeach_inode()and callsthe
syncfsmethod of every mountpoint that has one (today tmpfs andhostfs).
task_fssync()now uses the publicfdlist_count()andfdlist_get()instead of the private
fdlist_get_by_index(). WithCONFIG_FDCHECK,fdcheck_restore()returns a bare descriptor (belowOPEN_MAX, at most255) unchanged, so the walk visits the same slots as before.
The
syncfsmethods run with the inode tree read lock held byforeach_inode(), asstatfsalready does for the mount listing inprocfs; mount and umount wait until the walk ends.
Impact
sync()now also flushes everymounted filesystem that implements
syncfs.fs/vfs/fs_sync.c, added to both Make and CMake.Testing
Host: Ubuntu 22.04 x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0.
sim:nsh(hostfs, loop device and FAT are already enabled there) with asmall test app whose
synccommand callssync(). A FAT image on thehost is attached as a loop device through hostfs, so its host descriptor
is held by the loop driver, not by any task:
sync()runs twice in this script: thesynccommand and the rebootnotifier at
poweroff. The simulator was run understrace -f -e trace=openat,fsync,fdatasyncto count hostfsync()callson the image descriptor.
Testing logs before change (master 8a282a5):
Testing logs after change:
The branch was then rebased onto master fc8d354 (no conflicts, patch
unchanged) and the build checks below were rerun there.
./tools/checkpatch.sh -g master..HEAD: all checks pass.sim:nshwithCONFIG_FS_HOSTFSandCONFIG_FS_TMPFS: Make and CMakebuilds pass with no new warnings in the changed files;
ostestexitswith status 0.
PR verification Self-Check