fs/xfs/scrub/scrub.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/scrub.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/scrub.c- Extension
.c- Size
- 28002 bytes
- Lines
- 1013
- 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
xfs_platform.hxfs_fs.hxfs_shared.hxfs_format.hxfs_trans_resv.hxfs_mount.hxfs_log_format.hxfs_trans.hxfs_inode.hxfs_quota.hxfs_qm.hxfs_scrub.hxfs_buf_mem.hxfs_rmap.hxfs_exchrange.hxfs_exchmaps.hxfs_dir2.hxfs_parent.hxfs_icache.hscrub/scrub.hscrub/common.hscrub/trace.hscrub/repair.hscrub/health.hscrub/stats.hscrub/xfile.hscrub/tempfile.hscrub/orphanage.h
Detected Declarations
function scrubfunction flagfunction xchk_fsgates_disablefunction xchk_scrub_free_subordfunction xchk_teardownfunction xchk_validate_inputsfunction xchk_postmortemfunction xchk_postmortemfunction xchk_scrub_create_subordfunction xfs_scrub_metadatafunction xfs_ioc_scrub_metadatafunction xfs_scrubv_check_barrierfunction xchk_scrubv_open_by_handlefunction xfs_ioc_scrubv_metadata
Annotated Snippet
if (xfs_has_rtgroups(mp)) {
/*
* On a rtgroups filesystem, there won't be an rtbitmap
* or rtsummary file for group 0 unless there's
* actually a realtime volume attached. However, older
* xfs_scrub always calls the rtbitmap/rtsummary
* scrubbers with sm_agno==0 so transform the error
* code to ENOENT.
*/
if (sm->sm_agno >= mp->m_sb.sb_rgcount) {
if (sm->sm_agno == 0)
error = -ENOENT;
goto out;
}
} else {
/*
* Prior to rtgroups, the rtbitmap/rtsummary scrubbers
* accepted sm_agno==0, so we still accept that for
* scrubbing pre-rtgroups filesystems.
*/
if (sm->sm_agno != 0)
goto out;
}
break;
default:
goto out;
}
/* No rebuild without repair. */
if ((sm->sm_flags & XFS_SCRUB_IFLAG_FORCE_REBUILD) &&
!(sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR))
return -EINVAL;
/*
* We only want to repair read-write v5+ filesystems. Defer the check
* for ops->repair until after our scrub confirms that we need to
* perform repairs so that we avoid failing due to not supporting
* repairing an object that doesn't need repairs.
*/
if (sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR) {
error = -EOPNOTSUPP;
if (!xfs_has_crc(mp))
goto out;
error = -EROFS;
if (xfs_is_readonly(mp))
goto out;
}
error = 0;
out:
return error;
}
#ifdef CONFIG_XFS_ONLINE_REPAIR
static inline void xchk_postmortem(struct xfs_scrub *sc)
{
/*
* Userspace asked us to repair something, we repaired it, rescanned
* it, and the rescan says it's still broken. Scream about this in
* the system logs.
*/
if ((sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR) &&
(sc->sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
XFS_SCRUB_OFLAG_XCORRUPT)))
xrep_failure(sc->mp);
}
#else
static inline void xchk_postmortem(struct xfs_scrub *sc)
{
/*
* Userspace asked us to scrub something, it's broken, and we have no
* way of fixing it. Scream in the logs.
*/
if (sc->sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
XFS_SCRUB_OFLAG_XCORRUPT))
xfs_alert_ratelimited(sc->mp,
"Corruption detected during scrub.");
}
#endif /* CONFIG_XFS_ONLINE_REPAIR */
/*
* Create a new scrub context from an existing one, but with a different scrub
* type.
*/
struct xfs_scrub_subord *
xchk_scrub_create_subord(
struct xfs_scrub *sc,
unsigned int subtype)
{
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_log_format.h`, `xfs_trans.h`.
- Detected declarations: `function scrub`, `function flag`, `function xchk_fsgates_disable`, `function xchk_scrub_free_subord`, `function xchk_teardown`, `function xchk_validate_inputs`, `function xchk_postmortem`, `function xchk_postmortem`, `function xchk_scrub_create_subord`, `function xfs_scrub_metadata`.
- 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.