fs/netfs/locking.c
Source file repositories/reference/linux-study-clean/fs/netfs/locking.c
File Facts
- System
- Linux kernel
- Corpus path
fs/netfs/locking.c- Extension
.c- Size
- 5883 bytes
- Lines
- 206
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/netfs.hinternal.h
Detected Declarations
function Copyrightfunction netfs_block_o_directfunction netfs_start_io_readfunction netfs_end_io_readfunction netfs_start_io_writefunction netfs_end_io_writefunction netfs_block_bufferedfunction netfs_start_io_directfunction netfs_end_io_directexport netfs_start_io_readexport netfs_end_io_readexport netfs_start_io_writeexport netfs_end_io_writeexport netfs_start_io_directexport netfs_end_io_direct
Annotated Snippet
if (inode->i_mapping->nrpages != 0) {
unmap_mapping_range(inode->i_mapping, 0, 0, 0);
ret = filemap_fdatawait(inode->i_mapping);
if (ret < 0) {
clear_bit(NETFS_ICTX_ODIRECT, &ictx->flags);
return ret;
}
}
}
return 0;
}
/**
* netfs_start_io_direct - declare the file is being used for direct i/o
* @inode: file inode
*
* Declare that a direct I/O operation is about to start, and ensure
* that we block all buffered I/O.
* On exit, the function ensures that the NETFS_ICTX_ODIRECT flag is set,
* and holds a shared lock on inode->i_rwsem to ensure that the flag
* cannot be changed.
* In practice, this means that direct I/O operations are allowed to
* execute in parallel, thanks to the shared lock, whereas buffered I/O
* operations need to wait to grab an exclusive lock in order to clear
* NETFS_ICTX_ODIRECT.
* Note that buffered writes and truncates both take a write lock on
* inode->i_rwsem, meaning that those are serialised w.r.t. O_DIRECT.
*/
int netfs_start_io_direct(struct inode *inode)
__acquires(inode->i_rwsem)
{
struct netfs_inode *ictx = netfs_inode(inode);
int ret;
/* Be an optimist! */
if (down_read_interruptible(&inode->i_rwsem) < 0)
return -ERESTARTSYS;
if (test_bit(NETFS_ICTX_ODIRECT, &ictx->flags) != 0)
return 0;
up_read(&inode->i_rwsem);
/* Slow path.... */
if (down_write_killable(&inode->i_rwsem) < 0)
return -ERESTARTSYS;
ret = netfs_block_buffered(inode);
if (ret < 0) {
up_write(&inode->i_rwsem);
return ret;
}
downgrade_write(&inode->i_rwsem);
return 0;
}
EXPORT_SYMBOL(netfs_start_io_direct);
/**
* netfs_end_io_direct - declare that the direct i/o operation is done
* @inode: file inode
*
* Declare that a direct I/O operation is done, and release the shared
* lock on inode->i_rwsem.
*/
void netfs_end_io_direct(struct inode *inode)
__releases(inode->i_rwsem)
{
up_read(&inode->i_rwsem);
}
EXPORT_SYMBOL(netfs_end_io_direct);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/netfs.h`, `internal.h`.
- Detected declarations: `function Copyright`, `function netfs_block_o_direct`, `function netfs_start_io_read`, `function netfs_end_io_read`, `function netfs_start_io_write`, `function netfs_end_io_write`, `function netfs_block_buffered`, `function netfs_start_io_direct`, `function netfs_end_io_direct`, `export netfs_start_io_read`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.