Chapter 17: Data Synchronization
The methods provided forfile_operations->fsyncare very similar for most filesystems. Figure 17-13
shows the code flow diagram for a generalized method.
{fs}_sync_inode
{fs}_sync_file
sync_mapping_buffers
fsync_buffers_list
ll_rw_block
osync_buffers_list
datasync set and Inode
in state l_DIRTY_DATASYNC?
Figure 17-13: Code flow diagram forf_op->fsync.
The code performs two tasks:
- sync_mapping_bufferswrites back all private inode buffers in theprivate_listof the
mappinginstance. These normally hold indirection blocks or other internal filesystem data
that arenotpart of the inode management data but are used to manage the data themselves.
This function delegates work tofsync_mapping_buffers, which iterates over all buffers. The
buffer data are written to the block layer by thell_rw_blockfunction with which you are
familiar from Chapter 6. With the help ofosync_buffers_list, the kernel then waits until
the write operations have been completed (the block layer also buffers write accesses) and
then ensures that synchronization of the associated metadata outsidesync_buffers_list
appears as a synchronous operation. - fs_sync_inodewrites back the inode management data (i.e., the data held directly in the
filesystem-specific inode structure). Note that thedatasyncargument offsyncmust be
set to (0) to invoke the method. This is the one and only difference betweenfdatasyncand
fsync.
Since writeback of inode management data is filesystem-specific, see Chapter 9.
17.15.3 Synchronization of Memory Mappings
The kernel provides themsyncsystem call implemented insys_msyncto synchronize memory mappings
in part or in total:
mm/msync.c
asmlinkage long sys_msync(unsigned long start, size_t len, int flags)
startandlenselect an area in the user address space of a process whose mapped data are to be syn-
chronized with the underlying file.