fs/xfs/xfs_inode.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_inode.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_inode.c- Extension
.c- Size
- 84161 bytes
- Lines
- 3079
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/iversion.hxfs_platform.hxfs_fs.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_mount.hxfs_defer.hxfs_inode.hxfs_dir2.hxfs_attr.hxfs_bit.hxfs_trans_space.hxfs_trans.hxfs_buf_item.hxfs_inode_item.hxfs_iunlink_item.hxfs_ialloc.hxfs_bmap.hxfs_bmap_util.hxfs_errortag.hxfs_error.hxfs_quota.hxfs_filestream.hxfs_trace.hxfs_icache.hxfs_symlink.hxfs_trans_priv.hxfs_log.hxfs_bmap_btree.hxfs_reflink.h
Detected Declarations
function xfs_ilockfunction xfs_ilock_attr_map_sharedfunction xfs_lock_flags_assertfunction readfunction xfs_ilockfunction xfs_iunlockfunction xfs_ilock_demotefunction xfs_assert_ilockedfunction xfs_lockdep_subclass_okfunction xfs_lock_inodesfunction transactionfunction xfs_lock_two_inodesfunction xfs_lookupfunction xfs_icreatefunction xfs_icreate_dqallocfunction xfs_createfunction xfs_create_tmpfilefunction xfs_projid_differfunction xfs_linkfunction xfs_itruncate_clear_reflink_flagsfunction xfs_itruncate_extents_flagsfunction xfs_inactive_dirfunction xfs_inactive_truncatefunction xfs_inactive_ifreefunction xfs_inode_needs_inactivefunction xfs_inactive_healthfunction xfs_inactivefunction xfs_iunlink_lookupfunction xfs_iunlink_reload_nextfunction xfs_ifree_mark_inode_stalefunction xfs_ifree_clusterfunction xfs_ifreefunction xfs_iunpinfunction __xfs_iunpin_waitfunction xfs_iunpin_waitfunction AGFfunction xfs_iunlock_renamefunction xfs_sort_inodesfunction xfs_rename_alloc_whiteoutfunction xfs_renamefunction xfs_iflushfunction XFS_TEST_ERRORfunction XFS_TEST_ERRORfunction xfs_iflush_clusterfunction xfs_iflush_abortfunction xfs_irelefunction xfs_log_force_inodefunction order
Annotated Snippet
if (!try_lock) {
for (j = (i - 1); j >= 0 && !try_lock; j--) {
lp = &ips[j]->i_itemp->ili_item;
if (lp && test_bit(XFS_LI_IN_AIL, &lp->li_flags))
try_lock = true;
}
}
/*
* If any of the previous locks we have locked is in the AIL,
* we must TRY to get the second and subsequent locks. If
* we can't get any, we must release all we have
* and try again.
*/
if (!try_lock) {
xfs_ilock(ips[i], xfs_lock_inumorder(lock_mode, i));
continue;
}
/* try_lock means we have an inode locked that is in the AIL. */
ASSERT(i != 0);
if (xfs_ilock_nowait(ips[i], xfs_lock_inumorder(lock_mode, i)))
continue;
/*
* Unlock all previous guys and try again. xfs_iunlock will try
* to push the tail if the inode is in the AIL.
*/
attempts++;
for (j = i - 1; j >= 0; j--) {
/*
* Check to see if we've already unlocked this one. Not
* the first one going back, and the inode ptr is the
* same.
*/
if (j != (i - 1) && ips[j] == ips[j + 1])
continue;
xfs_iunlock(ips[j], lock_mode);
}
if ((attempts % 5) == 0) {
delay(1); /* Don't just spin the CPU */
}
goto again;
}
}
/*
* xfs_lock_two_inodes() can only be used to lock ilock. The iolock and
* mmaplock must be double-locked separately since we use i_rwsem and
* invalidate_lock for that. We now support taking one lock EXCL and the
* other SHARED.
*/
void
xfs_lock_two_inodes(
struct xfs_inode *ip0,
uint ip0_mode,
struct xfs_inode *ip1,
uint ip1_mode)
{
int attempts = 0;
struct xfs_log_item *lp;
ASSERT(hweight32(ip0_mode) == 1);
ASSERT(hweight32(ip1_mode) == 1);
ASSERT(!(ip0_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)));
ASSERT(!(ip1_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)));
ASSERT(!(ip0_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)));
ASSERT(!(ip1_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)));
ASSERT(I_INO(ip0) != I_INO(ip1));
if (I_INO(ip0) > I_INO(ip1)) {
swap(ip0, ip1);
swap(ip0_mode, ip1_mode);
}
again:
xfs_ilock(ip0, xfs_lock_inumorder(ip0_mode, 0));
/*
* If the first lock we have locked is in the AIL, we must TRY to get
* the second lock. If we can't get it, we must release the first one
* and try again.
*/
lp = &ip0->i_itemp->ili_item;
if (lp && test_bit(XFS_LI_IN_AIL, &lp->li_flags)) {
if (!xfs_ilock_nowait(ip1, xfs_lock_inumorder(ip1_mode, 1))) {
xfs_iunlock(ip0, ip0_mode);
if ((++attempts % 5) == 0)
Annotation
- Immediate include surface: `linux/iversion.h`, `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`.
- Detected declarations: `function xfs_ilock`, `function xfs_ilock_attr_map_shared`, `function xfs_lock_flags_assert`, `function read`, `function xfs_ilock`, `function xfs_iunlock`, `function xfs_ilock_demote`, `function xfs_assert_ilocked`, `function xfs_lockdep_subclass_ok`, `function xfs_lock_inodes`.
- 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.
- 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.