fs/super.c
Source file repositories/reference/linux-study-clean/fs/super.c
File Facts
- System
- Linux kernel
- Corpus path
fs/super.c- Extension
.c- Size
- 60803 bytes
- Lines
- 2213
- 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.
- 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.
- 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/export.hlinux/slab.hlinux/blkdev.hlinux/mount.hlinux/security.hlinux/writeback.hlinux/idr.hlinux/mutex.hlinux/backing-dev.hlinux/rculist_bl.hlinux/fscrypt.hlinux/fsnotify.hlinux/lockdep.hlinux/user_namespace.hlinux/fs_context.hlinux/fserror.huapi/linux/mount.hinternal.h
Detected Declarations
enum super_iter_flags_tfunction __super_lockfunction super_unlockfunction __super_lock_exclfunction super_unlock_exclfunction super_unlock_sharedfunction super_flagsfunction vfs_get_treefunction generic_shutdown_superfunction super_lock_sharedfunction super_lock_exclfunction super_wakefunction super_cache_scanfunction super_cache_countfunction destroy_super_workfunction destroy_super_rcufunction destroy_unused_superfunction __put_superfunction put_superfunction kill_super_notifyfunction deactivate_locked_superfunction deactivate_locked_superfunction grab_superfunction get_superfunction generic_shutdown_superfunction generic_shutdown_superfunction list_for_each_entryfunction mount_capablefunction performedfunction hlist_for_each_entryfunction drop_superfunction drop_super_exclusivefunction __iterate_supersfunction iterate_supersfunction iterate_supers_typefunction reconfigure_superfunction do_emergency_remount_callbackfunction do_emergency_remountfunction emergency_remountfunction do_thaw_all_callbackfunction do_thaw_allfunction emergency_thaw_allfunction get_active_superfunction filesystems_freeze_callbackfunction filesystems_freezefunction filesystems_thaw_callbackfunction filesystems_thawfunction get_anon_bdev
Annotated Snippet
if (atomic_inc_not_zero(&sb->s_active)) {
put_super(sb);
return true;
}
super_unlock_excl(sb);
}
wait_var_event(&sb->s_flags, super_flags(sb, SB_DEAD));
put_super(sb);
return false;
}
/*
* super_trylock_shared - try to grab ->s_umount shared
* @sb: reference we are trying to grab
*
* Try to prevent fs shutdown. This is used in places where we
* cannot take an active reference but we need to ensure that the
* filesystem is not shut down while we are working on it. It returns
* false if we cannot acquire s_umount or if we lose the race and
* filesystem already got into shutdown, and returns true with the s_umount
* lock held in read mode in case of success. On successful return,
* the caller must drop the s_umount lock when done.
*
* Note that unlike get_super() et.al. this one does *not* bump ->s_count.
* The reason why it's safe is that we are OK with doing trylock instead
* of down_read(). There's a couple of places that are OK with that, but
* it's very much not a general-purpose interface.
*/
bool super_trylock_shared(struct super_block *sb)
{
if (down_read_trylock(&sb->s_umount)) {
if (!(sb->s_flags & SB_DYING) && sb->s_root &&
(sb->s_flags & SB_BORN))
return true;
super_unlock_shared(sb);
}
return false;
}
/**
* retire_super - prevents superblock from being reused
* @sb: superblock to retire
*
* The function marks superblock to be ignored in superblock test, which
* prevents it from being reused for any new mounts. If the superblock has
* a private bdi, it also unregisters it, but doesn't reduce the refcount
* of the superblock to prevent potential races. The refcount is reduced
* by generic_shutdown_super(). The function can not be called
* concurrently with generic_shutdown_super(). It is safe to call the
* function multiple times, subsequent calls have no effect.
*
* The marker will affect the re-use only for block-device-based
* superblocks. Other superblocks will still get marked if this function
* is used, but that will not affect their reusability.
*/
void retire_super(struct super_block *sb)
{
WARN_ON(!sb->s_bdev);
__super_lock_excl(sb);
if (sb->s_iflags & SB_I_PERSB_BDI) {
bdi_unregister(sb->s_bdi);
sb->s_iflags &= ~SB_I_PERSB_BDI;
}
sb->s_iflags |= SB_I_RETIRED;
super_unlock_excl(sb);
}
EXPORT_SYMBOL(retire_super);
/**
* generic_shutdown_super - common helper for ->kill_sb()
* @sb: superblock to kill
*
* generic_shutdown_super() does all fs-independent work on superblock
* shutdown. Typical ->kill_sb() should pick all fs-specific objects
* that need destruction out of superblock, call generic_shutdown_super()
* and release aforementioned objects. Note: dentries and inodes _are_
* taken care of and do not need specific handling.
*
* Upon calling this function, the filesystem may no longer alter or
* rearrange the set of dentries belonging to this super_block, nor may it
* change the attachments of dentries to inodes.
*/
void generic_shutdown_super(struct super_block *sb)
{
const struct super_operations *sop = sb->s_op;
if (sb->s_root) {
fsnotify_sb_delete(sb);
shrink_dcache_for_umount(sb);
Annotation
- Immediate include surface: `linux/export.h`, `linux/slab.h`, `linux/blkdev.h`, `linux/mount.h`, `linux/security.h`, `linux/writeback.h`, `linux/idr.h`, `linux/mutex.h`.
- Detected declarations: `enum super_iter_flags_t`, `function __super_lock`, `function super_unlock`, `function __super_lock_excl`, `function super_unlock_excl`, `function super_unlock_shared`, `function super_flags`, `function vfs_get_tree`, `function generic_shutdown_super`, `function super_lock_shared`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.