fs/nilfs2/mdt.c
Source file repositories/reference/linux-study-clean/fs/nilfs2/mdt.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nilfs2/mdt.c- Extension
.c- Size
- 17088 bytes
- Lines
- 679
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/mpage.hlinux/mm.hlinux/writeback.hlinux/backing-dev.hlinux/swap.hlinux/slab.hnilfs.hbtnode.hsegment.hpage.hmdt.halloc.htrace/events/nilfs2.h
Detected Declarations
function Copyrightfunction nilfs_mdt_create_blockfunction nilfs_mdt_submit_blockfunction nilfs_mdt_read_blockfunction nilfs_mdt_get_blockfunction nilfs_mdt_find_blockfunction nilfs_mdt_delete_blockfunction nilfs_mdt_forget_blockfunction nilfs_mdt_fetch_dirtyfunction nilfs_mdt_write_foliofunction nilfs_mdt_writebackfunction nilfs_mdt_initfunction nilfs_mdt_clearfunction nilfs_mdt_destroyfunction nilfs_mdt_set_entry_sizefunction nilfs_mdt_setup_shadow_mapfunction nilfs_mdt_save_to_shadow_mapfunction nilfs_mdt_freeze_bufferfunction nilfs_mdt_get_frozen_bufferfunction nilfs_release_frozen_buffersfunction nilfs_mdt_restore_from_shadow_mapfunction nilfs_mdt_clear_shadow_map
Annotated Snippet
static const struct file_operations def_mdt_fops;
int nilfs_mdt_init(struct inode *inode, gfp_t gfp_mask, size_t objsz)
{
struct nilfs_mdt_info *mi;
mi = kzalloc(max(sizeof(*mi), objsz), GFP_NOFS);
if (!mi)
return -ENOMEM;
init_rwsem(&mi->mi_sem);
inode->i_private = mi;
inode->i_mode = S_IFREG;
mapping_set_gfp_mask(inode->i_mapping, gfp_mask);
inode->i_op = &def_mdt_iops;
inode->i_fop = &def_mdt_fops;
inode->i_mapping->a_ops = &def_mdt_aops;
return 0;
}
/**
* nilfs_mdt_clear - do cleanup for the metadata file
* @inode: inode of the metadata file
*/
void nilfs_mdt_clear(struct inode *inode)
{
struct nilfs_mdt_info *mdi = NILFS_MDT(inode);
struct nilfs_shadow_map *shadow = mdi->mi_shadow;
if (mdi->mi_palloc_cache)
nilfs_palloc_destroy_cache(inode);
if (shadow) {
struct inode *s_inode = shadow->inode;
shadow->inode = NULL;
iput(s_inode);
mdi->mi_shadow = NULL;
}
}
/**
* nilfs_mdt_destroy - release resources used by the metadata file
* @inode: inode of the metadata file
*/
void nilfs_mdt_destroy(struct inode *inode)
{
struct nilfs_mdt_info *mdi = NILFS_MDT(inode);
kfree(mdi->mi_bgl); /* kfree(NULL) is safe */
kfree(mdi);
}
void nilfs_mdt_set_entry_size(struct inode *inode, unsigned int entry_size,
unsigned int header_size)
{
struct nilfs_mdt_info *mi = NILFS_MDT(inode);
mi->mi_entry_size = entry_size;
mi->mi_entries_per_block = i_blocksize(inode) / entry_size;
mi->mi_first_entry_offset = DIV_ROUND_UP(header_size, entry_size);
}
/**
* nilfs_mdt_setup_shadow_map - setup shadow map and bind it to metadata file
* @inode: inode of the metadata file
* @shadow: shadow mapping
*
* Return: 0 on success, or a negative error code on failure.
*/
int nilfs_mdt_setup_shadow_map(struct inode *inode,
struct nilfs_shadow_map *shadow)
{
struct nilfs_mdt_info *mi = NILFS_MDT(inode);
struct inode *s_inode;
INIT_LIST_HEAD(&shadow->frozen_buffers);
s_inode = nilfs_iget_for_shadow(inode);
if (IS_ERR(s_inode))
return PTR_ERR(s_inode);
shadow->inode = s_inode;
mi->mi_shadow = shadow;
return 0;
}
Annotation
- Immediate include surface: `linux/buffer_head.h`, `linux/mpage.h`, `linux/mm.h`, `linux/writeback.h`, `linux/backing-dev.h`, `linux/swap.h`, `linux/slab.h`, `nilfs.h`.
- Detected declarations: `function Copyright`, `function nilfs_mdt_create_block`, `function nilfs_mdt_submit_block`, `function nilfs_mdt_read_block`, `function nilfs_mdt_get_block`, `function nilfs_mdt_find_block`, `function nilfs_mdt_delete_block`, `function nilfs_mdt_forget_block`, `function nilfs_mdt_fetch_dirty`, `function nilfs_mdt_write_folio`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern 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.