fs/nilfs2/inode.c
Source file repositories/reference/linux-study-clean/fs/nilfs2/inode.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nilfs2/inode.c- Extension
.c- Size
- 32791 bytes
- Lines
- 1232
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/buffer_head.hlinux/gfp.hlinux/mpage.hlinux/pagemap.hlinux/writeback.hlinux/uio.hlinux/fiemap.hlinux/random.hnilfs.hbtnode.hsegment.hpage.hmdt.hcpfile.hifile.h
Detected Declarations
struct nilfs_iget_argsfunction nilfs_inode_add_blocksfunction nilfs_inode_sub_blocksfunction nilfs_get_blockfunction nilfs_read_foliofunction nilfs_readaheadfunction nilfs_writepagesfunction nilfs_dirty_foliofunction nilfs_write_failedfunction nilfs_write_beginfunction nilfs_write_endfunction nilfs_direct_IOfunction nilfs_insert_inode_lockedfunction nilfs_set_inode_flagsfunction nilfs_read_inode_commonfunction __nilfs_read_inodefunction S_ISFIFOfunction nilfs_iget_testfunction nilfs_iget_setfunction nilfs_attach_btree_node_cachefunction nilfs_detach_btree_node_cachefunction nilfs_iget_for_shadowfunction nilfs_write_inode_commonfunction nilfs_update_inodefunction nilfs_truncate_bmapfunction nilfs_truncatefunction nilfs_clear_inodefunction nilfs_evict_inodefunction nilfs_setattrfunction nilfs_permissionfunction nilfs_load_inode_blockfunction nilfs_inode_dirtyfunction nilfs_set_file_dirtyfunction nilfs_dispose_listfunction __nilfs_mark_inode_dirtyfunction nilfs_dirty_inodefunction nilfs_fiemap
Annotated Snippet
struct nilfs_iget_args {
u64 ino;
__u64 cno;
struct nilfs_root *root;
unsigned int type;
};
static int nilfs_iget_test(struct inode *inode, void *opaque);
void nilfs_inode_add_blocks(struct inode *inode, int n)
{
struct nilfs_root *root = NILFS_I(inode)->i_root;
inode_add_bytes(inode, i_blocksize(inode) * n);
if (root)
atomic64_add(n, &root->blocks_count);
}
void nilfs_inode_sub_blocks(struct inode *inode, int n)
{
struct nilfs_root *root = NILFS_I(inode)->i_root;
inode_sub_bytes(inode, i_blocksize(inode) * n);
if (root)
atomic64_sub(n, &root->blocks_count);
}
/**
* nilfs_get_block() - get a file block on the filesystem (callback function)
* @inode: inode struct of the target file
* @blkoff: file block number
* @bh_result: buffer head to be mapped on
* @create: indicate whether allocating the block or not when it has not
* been allocated yet.
*
* This function does not issue actual read request of the specified data
* block. It is done by VFS.
*
* Return: 0 on success, or a negative error code on failure.
*/
int nilfs_get_block(struct inode *inode, sector_t blkoff,
struct buffer_head *bh_result, int create)
{
struct nilfs_inode_info *ii = NILFS_I(inode);
struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
__u64 blknum = 0;
int err = 0, ret;
unsigned int maxblocks = bh_result->b_size >> inode->i_blkbits;
down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
ret = nilfs_bmap_lookup_contig(ii->i_bmap, blkoff, &blknum, maxblocks);
up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
if (ret >= 0) { /* found */
map_bh(bh_result, inode->i_sb, blknum);
if (ret > 0)
bh_result->b_size = (ret << inode->i_blkbits);
goto out;
}
/* data block was not found */
if (ret == -ENOENT && create) {
struct nilfs_transaction_info ti;
bh_result->b_blocknr = 0;
err = nilfs_transaction_begin(inode->i_sb, &ti, 1);
if (unlikely(err))
goto out;
err = nilfs_bmap_insert(ii->i_bmap, blkoff,
(unsigned long)bh_result);
if (unlikely(err != 0)) {
if (err == -EEXIST) {
/*
* The get_block() function could be called
* from multiple callers for an inode.
* However, the page having this block must
* be locked in this case.
*/
nilfs_warn(inode->i_sb,
"%s (ino=%llu): a race condition while inserting a data block at offset=%llu",
__func__, inode->i_ino,
(unsigned long long)blkoff);
err = -EAGAIN;
}
nilfs_transaction_abort(inode->i_sb);
goto out;
}
nilfs_mark_inode_dirty_sync(inode);
nilfs_transaction_commit(inode->i_sb); /* never fails */
/* Error handling should be detailed */
set_buffer_new(bh_result);
set_buffer_delay(bh_result);
Annotation
- Immediate include surface: `linux/buffer_head.h`, `linux/gfp.h`, `linux/mpage.h`, `linux/pagemap.h`, `linux/writeback.h`, `linux/uio.h`, `linux/fiemap.h`, `linux/random.h`.
- Detected declarations: `struct nilfs_iget_args`, `function nilfs_inode_add_blocks`, `function nilfs_inode_sub_blocks`, `function nilfs_get_block`, `function nilfs_read_folio`, `function nilfs_readahead`, `function nilfs_writepages`, `function nilfs_dirty_folio`, `function nilfs_write_failed`, `function nilfs_write_begin`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.