fs/xfs/xfs_healthmon.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_healthmon.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_healthmon.c- Extension
.c- Size
- 31142 bytes
- Lines
- 1261
- 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.
- 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
xfs_platform.hxfs_fs.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_mount.hxfs_inode.hxfs_trace.hxfs_ag.hxfs_btree.hxfs_da_format.hxfs_da_btree.hxfs_quota_defs.hxfs_rtgroup.hxfs_health.hxfs_healthmon.hxfs_fsops.hxfs_notify_failure.hxfs_file.hxfs_ioctl.hlinux/anon_inodes.hlinux/eventpoll.hlinux/poll.hlinux/fserror.h
Detected Declarations
struct flags_mapfunction xfs_healthmon_getfunction xfs_healthmon_putfunction xfs_healthmon_attachfunction xfs_healthmon_detachfunction xfs_healthmon_bump_eventsfunction xfs_healthmon_bump_lostfunction xfs_healthmon_merge_eventsfunction __xfs_healthmon_insertfunction __xfs_healthmon_pushfunction xfs_healthmon_clear_lost_prevfunction xfs_healthmon_pushfunction xfs_healthmon_unmountfunction metadata_event_maskfunction xfs_healthmon_report_fsfunction xfs_healthmon_report_groupfunction xfs_healthmon_report_inodefunction xfs_healthmon_report_shutdownfunction media_error_domainfunction xfs_healthmon_report_mediafunction file_ioerr_typefunction xfs_healthmon_report_file_ioerrorfunction xfs_healthmon_reset_outbuffunction __map_flagsfunction shutdown_maskfunction xfs_healthmon_format_v0function xfs_healthmon_outbuf_bytesfunction xfs_healthmon_has_eventdatafunction xfs_healthmon_copybuffunction xfs_healthmon_format_popfunction xfs_healthmon_alloc_outbuffunction xfs_healthmon_read_iterfunction xfs_healthmon_pollfunction xfs_healthmon_releasefunction xfs_healthmon_validatefunction xfs_healthmon_show_fdinfofunction xfs_healthmon_reconfigurefunction xfs_healthmon_file_on_monitored_fsfunction xfs_healthmon_ioctlfunction xfs_ioc_health_monitor
Annotated Snippet
static const struct file_operations xfs_healthmon_fops = {
.owner = THIS_MODULE,
.show_fdinfo = xfs_healthmon_show_fdinfo,
.read_iter = xfs_healthmon_read_iter,
.poll = xfs_healthmon_poll,
.release = xfs_healthmon_release,
.unlocked_ioctl = xfs_healthmon_ioctl,
};
/*
* Create a health monitoring file. Returns an index to the fd table or a
* negative errno.
*/
long
xfs_ioc_health_monitor(
struct file *file,
struct xfs_health_monitor __user *arg)
{
struct xfs_health_monitor hmo;
struct xfs_healthmon_event *running_event;
struct xfs_healthmon *hm;
struct xfs_inode *ip = XFS_I(file_inode(file));
struct xfs_mount *mp = ip->i_mount;
int ret;
/*
* The only intended user of the health monitoring system should be the
* xfs_healer daemon running on behalf of the whole filesystem in the
* initial user namespace. IOWs, we don't allow unprivileged userspace
* (they can use fsnotify) nor do we allow containers.
*/
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
if (I_INO(ip) != mp->m_sb.sb_rootino)
return -EPERM;
if (current_user_ns() != &init_user_ns)
return -EPERM;
if (copy_from_user(&hmo, arg, sizeof(hmo)))
return -EFAULT;
if (!xfs_healthmon_validate(&hmo))
return -EINVAL;
hm = kzalloc_obj(*hm);
if (!hm)
return -ENOMEM;
hm->dev = mp->m_super->s_dev;
refcount_set(&hm->ref, 1);
mutex_init(&hm->lock);
init_waitqueue_head(&hm->wait);
if (hmo.flags & XFS_HEALTH_MONITOR_VERBOSE)
hm->verbose = true;
/* Queue up the first event that lets the client know we're running. */
running_event = kzalloc_obj(struct xfs_healthmon_event, GFP_NOFS);
if (!running_event) {
ret = -ENOMEM;
goto out_hm;
}
running_event->type = XFS_HEALTHMON_RUNNING;
running_event->domain = XFS_HEALTHMON_MOUNT;
__xfs_healthmon_insert(hm, running_event);
/*
* Preallocate the unmount event so that we can't fail to notify the
* filesystem later. This is key for triggering fast exit of the
* xfs_healer daemon.
*/
hm->unmount_event = kzalloc_obj(struct xfs_healthmon_event, GFP_NOFS);
if (!hm->unmount_event) {
ret = -ENOMEM;
goto out_hm;
}
hm->unmount_event->type = XFS_HEALTHMON_UNMOUNT;
hm->unmount_event->domain = XFS_HEALTHMON_MOUNT;
/*
* Try to attach this health monitor to the xfs_mount. The monitor is
* considered live and will receive events if this succeeds.
*/
ret = xfs_healthmon_attach(mp, hm);
if (ret)
goto out_hm;
/*
* Create the anonymous file and install a fd for it. If it succeeds,
* the file owns hm and can go away at any time, so we must not access
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_inode.h`.
- Detected declarations: `struct flags_map`, `function xfs_healthmon_get`, `function xfs_healthmon_put`, `function xfs_healthmon_attach`, `function xfs_healthmon_detach`, `function xfs_healthmon_bump_events`, `function xfs_healthmon_bump_lost`, `function xfs_healthmon_merge_events`, `function __xfs_healthmon_insert`, `function __xfs_healthmon_push`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern 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.