fs/ocfs2/move_extents.c
Source file repositories/reference/linux-study-clean/fs/ocfs2/move_extents.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ocfs2/move_extents.c- Extension
.c- Size
- 26097 bytes
- Lines
- 1095
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/fs.hlinux/types.hlinux/mount.hlinux/swap.hcluster/masklog.hocfs2.hocfs2_ioctl.halloc.hlocalalloc.haops.hdlmglue.hextent_map.hinode.hjournal.hsuballoc.huptodate.hsuper.hdir.hbuffer_head_io.hsysfile.hrefcounttree.hmove_extents.h
Detected Declarations
struct ocfs2_move_extents_contextfunction __ocfs2_move_extentfunction ocfs2_lock_meta_allocator_move_extentsfunction ocfs2_defrag_extentfunction ocfs2_find_victim_alloc_groupfunction ocfs2_validate_and_adjust_move_goalfunction ocfs2_probe_alloc_groupfunction ocfs2_move_extentfunction ocfs2_calc_extent_defrag_lenfunction __ocfs2_move_extents_rangefunction ocfs2_move_extentsfunction ocfs2_ioctl_move_extents
Annotated Snippet
struct ocfs2_move_extents_context {
struct inode *inode;
struct file *file;
int auto_defrag;
int partial;
int credits;
u32 new_phys_cpos;
u32 clusters_moved;
u64 refcount_loc;
struct ocfs2_move_extents *range;
struct ocfs2_extent_tree et;
struct ocfs2_alloc_context *meta_ac;
struct ocfs2_alloc_context *data_ac;
struct ocfs2_cached_dealloc_ctxt dealloc;
};
static int __ocfs2_move_extent(handle_t *handle,
struct ocfs2_move_extents_context *context,
u32 cpos, u32 len, u32 p_cpos, u32 new_p_cpos,
int ext_flags)
{
int ret = 0, index;
struct inode *inode = context->inode;
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
struct ocfs2_extent_rec *rec, replace_rec;
struct ocfs2_path *path = NULL;
struct ocfs2_extent_list *el;
u64 ino = ocfs2_metadata_cache_owner(context->et.et_ci);
u64 old_blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cpos);
ret = ocfs2_duplicate_clusters_by_page(handle, inode, cpos,
p_cpos, new_p_cpos, len);
if (ret) {
mlog_errno(ret);
goto out;
}
memset(&replace_rec, 0, sizeof(replace_rec));
replace_rec.e_cpos = cpu_to_le32(cpos);
replace_rec.e_leaf_clusters = cpu_to_le16(len);
replace_rec.e_blkno = cpu_to_le64(ocfs2_clusters_to_blocks(inode->i_sb,
new_p_cpos));
path = ocfs2_new_path_from_et(&context->et);
if (!path) {
ret = -ENOMEM;
mlog_errno(ret);
goto out;
}
ret = ocfs2_find_path(INODE_CACHE(inode), path, cpos);
if (ret) {
mlog_errno(ret);
goto out;
}
el = path_leaf_el(path);
index = ocfs2_search_extent_list(el, cpos);
if (index == -1) {
ret = ocfs2_error(inode->i_sb,
"Inode %llu has an extent at cpos %u which can no longer be found\n",
(unsigned long long)ino, cpos);
goto out;
}
rec = &el->l_recs[index];
if (ext_flags != rec->e_flags) {
ret = ocfs2_error(inode->i_sb,
"Inode %llu has corrupted extent %d with flags 0x%x at cpos %u\n",
(unsigned long long)ino, index, rec->e_flags, cpos);
goto out;
}
/*
* after moving/defraging to new location, the extent is not going
* to be refcounted anymore.
*/
replace_rec.e_flags = ext_flags & ~OCFS2_EXT_REFCOUNTED;
ret = ocfs2_split_extent(handle, &context->et, path, index,
&replace_rec, context->meta_ac,
&context->dealloc);
if (ret) {
mlog_errno(ret);
goto out;
}
context->new_phys_cpos = new_p_cpos;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/types.h`, `linux/mount.h`, `linux/swap.h`, `cluster/masklog.h`, `ocfs2.h`, `ocfs2_ioctl.h`, `alloc.h`.
- Detected declarations: `struct ocfs2_move_extents_context`, `function __ocfs2_move_extent`, `function ocfs2_lock_meta_allocator_move_extents`, `function ocfs2_defrag_extent`, `function ocfs2_find_victim_alloc_group`, `function ocfs2_validate_and_adjust_move_goal`, `function ocfs2_probe_alloc_group`, `function ocfs2_move_extent`, `function ocfs2_calc_extent_defrag_len`, `function __ocfs2_move_extents_range`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.