Skip to content

[Improvement] EROFS: Migrate from deprecated fscache on-demand read to fanotify pre-content hooks #1826

@gabrielstedman

Description

@gabrielstedman

Problem Summary

The Linux kernel is deprecating the fscache-based on-demand read feature in EROFS. This feature is marked as deprecated since Linux 6.12 and is scheduled for removal after fanotify pre-content hooks land in the kernel.

Currently, Nydus uses fscache (CONFIG_EROFS_FS_ONDEMAND) to handle on-demand loading of container image data. This requires:

  • Kernel fscache subsystem (CONFIG_FSCACHE)
  • Cachefiles driver (CONFIG_CACHEFILES_ONDEMAND)
  • Special device interface (/dev/cachefiles)

As the kernel moves away from this approach in favor of fanotify-based pre-content hooks, Nydus must migrate to remain compatible with future Linux versions.

Why This Matters

Current State

Nydus currently implements on-demand read via fscache in:

  • service/src/fs_cache.rs - FsCacheHandler
  • storage/src/cache/fscache/mod.rs - FsCacheMgr
  • Requires kernel config: CONFIG_FSCACHE, CONFIG_CACHEFILES, CONFIG_CACHEFILES_ONDEMAND, CONFIG_EROFS_FS_ONDEMAND

What Needs to Happen

Nydus needs to implement fanotify pre-content hook support as an alternative or replacement to the fscache backend, allowing it to:

  • Work with future Linux kernels after fscache on demand is removed
  • Reduce kernel dependency footprint (fanotify is lighter weight)
  • Support both old (fscache) and new (fanotify) systems during transition period

Related Issues

Resources

Proposed Improvement

Implement a new fanotify-based cache backend driver alongside the existing fscache driver:

  1. Create service/src/fs_fanotify.rs - New FanotifyHandler that:

    • Listens for fanotify permission events (FAN_PRE_ACCESS, FAN_OPEN_PERM, FAN_ACCESS_PERM)
    • Fetches chunks from backend when needed
    • Writes data to file via pwrite() to populate page cache
    • Responds with FAN_ALLOW to unblock access
  2. Update service/src/fs_service.rs - Route cache backend based on config:

    • cache_type = "fscache" → FsCacheHandler (existing)
    • cache_type = "fanotify" → FanotifyHandler (new)
  3. Configuration - Simplify kernel requirements:

    • Remove: CONFIG_FSCACHE, CONFIG_CACHEFILES, CONFIG_CACHEFILES_ONDEMAND, CONFIG_EROFS_FS_ONDEMAND
    • Keep: CONFIG_EROFS_FS, CONFIG_FANOTIFY

This allows Nydus to support both backends during the transition, with fanotify as the new standard for future Linux versions.

Additional Context

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions