fs/fserror.c
Source file repositories/reference/linux-study-clean/fs/fserror.c
File Facts
- System
- Linux kernel
- Corpus path
fs/fserror.c- Extension
.c- Size
- 5692 bytes
- Lines
- 195
- 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.
- 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/fsnotify.hlinux/mempool.hlinux/fserror.h
Detected Declarations
function fserror_mountfunction fserror_unmountfunction fserror_pending_decfunction fserror_free_eventfunction fserror_workerfunction fserror_reportfunction fserror_initmodule init fserror_initexport fserror_report
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2025 Oracle. All Rights Reserved.
* Author: Darrick J. Wong <djwong@kernel.org>
*/
#include <linux/fs.h>
#include <linux/fsnotify.h>
#include <linux/mempool.h>
#include <linux/fserror.h>
#define FSERROR_DEFAULT_EVENT_POOL_SIZE (32)
static struct mempool fserror_events_pool;
void fserror_mount(struct super_block *sb)
{
/*
* The pending error counter is biased by 1 so that we don't wake_var
* until we're actually trying to unmount.
*/
refcount_set(&sb->s_pending_errors, 1);
}
void fserror_unmount(struct super_block *sb)
{
/*
* If we don't drop the pending error count to zero, then wait for it
* to drop below 1, which means that the pending errors cleared and
* hopefully we didn't saturate with 1 billion+ concurrent events.
*/
if (!refcount_dec_and_test(&sb->s_pending_errors))
wait_var_event(&sb->s_pending_errors,
refcount_read(&sb->s_pending_errors) < 1);
}
static inline void fserror_pending_dec(struct super_block *sb)
{
if (refcount_dec_and_test(&sb->s_pending_errors))
wake_up_var(&sb->s_pending_errors);
}
static inline void fserror_free_event(struct fserror_event *event)
{
fserror_pending_dec(event->sb);
mempool_free(event, &fserror_events_pool);
}
static void fserror_worker(struct work_struct *work)
{
struct fserror_event *event =
container_of(work, struct fserror_event, work);
struct super_block *sb = event->sb;
if (sb->s_flags & SB_ACTIVE) {
struct fs_error_report report = {
/* send positive error number to userspace */
.error = -event->error,
.inode = event->inode,
.sb = event->sb,
};
if (sb->s_op->report_error)
sb->s_op->report_error(event);
fsnotify(FS_ERROR, &report, FSNOTIFY_EVENT_ERROR, NULL, NULL,
NULL, 0);
}
iput(event->inode);
fserror_free_event(event);
}
static inline struct fserror_event *fserror_alloc_event(struct super_block *sb,
gfp_t gfp_flags)
{
struct fserror_event *event = NULL;
/*
* If pending_errors already reached zero or is no longer active,
* the superblock is being deactivated so there's no point in
* continuing.
*
* The order of the check of s_pending_errors and SB_ACTIVE are
* mandated by order of accesses in generic_shutdown_super and
* fserror_unmount. Barriers are implicitly provided by the refcount
* manipulations in this function and fserror_unmount.
*/
if (!refcount_inc_not_zero(&sb->s_pending_errors))
return NULL;
if (!(sb->s_flags & SB_ACTIVE))
Annotation
- Immediate include surface: `linux/fs.h`, `linux/fsnotify.h`, `linux/mempool.h`, `linux/fserror.h`.
- Detected declarations: `function fserror_mount`, `function fserror_unmount`, `function fserror_pending_dec`, `function fserror_free_event`, `function fserror_worker`, `function fserror_report`, `function fserror_init`, `module init fserror_init`, `export fserror_report`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.