Skip to content

RFC Rust abstractions for VFS

Wedson Almeida Filho linux-fsdevel lkml rust-for-linux 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest30 patches 4 repliesIn review
  2. v1 RFC19 patches 105 repliesSuperseded

Changes in v2 from the cover letter · 19 lines

- Rebased to latest rust-next tree
- Removed buffer heads
- Added iomap support
- Removed _pin field from Registration as it's not needed anymore
- Renamed sample filesystem to match the module's name
- Using typestate instead of a separate type for superblock/new-superblock
- Created separate submodules for superblocks, inodes, dentries, and files
- Split out operations from FileSystem to inode/file/address_space ops, similar to how C does it
- Removed usages of folio_set_error
- Removed UniqueFolio, for now reading blocks from devices via the pagecache
- Changed map() to return the entire folio if not in highmem
- Added support for unlocking the folio asynchronously
- Added from_raw to all new ref-counted types
- Added explicit types in calls to cast()
- Added typestate to folio
- Added support for implementing get_link
- Fixed data race when reading inode->i_state
- Added nofs scope support during allocation
- Link to v1: https://lore.kernel.org/rust-for-linux/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/30rust: fs: add registration/unregistration of file systemsrust/kernel/error.rs rust/kernel/fs.rs rust/kernel/lib.rs+76 -20 replies
2/30rust: fs: introduce the `module_fs` macrorust/kernel/fs.rs+55 -10 replies
3/30samples: rust: add initial ro file system samplesamples/rust/Kconfig samples/rust/Makefile samples/rust/rust_rofs.rs+30 -00 replies
4/30rust: fs: introduce `FileSystem::fill_super`rust/bindings/bindings_helper.h rust/kernel/fs.rs rust/kernel/fs/sb.rs +1 more+202 -61 reply
5/30rust: fs: introduce `INode<T>`rust/helpers.c rust/kernel/block.rs rust/kernel/fs.rs +2 more+128 -10 replies
6/30rust: fs: introduce `DEntry<T>`rust/helpers.c rust/kernel/error.rs rust/kernel/fs.rs +1 more+144 -20 replies
7/30rust: fs: introduce `FileSystem::init_root`rust/helpers.c rust/kernel/fs.rs rust/kernel/fs/inode.rs +2 more+211 -400 replies
8/30rust: file: move `kernel::file` to `kernel::fs::file`rust/kernel/fs.rs rust/kernel/fs/file.rs rust/kernel/lib.rs+2 -20 replies
9/30rust: fs: generalise `File` for different file systemsrust/kernel/fs/file.rs rust/kernel/fs/inode.rs+36 -180 replies
10/30rust: fs: add empty file operationsrust/kernel/fs/file.rs+57 -00 replies
11/30rust: fs: introduce `file::Operations::read_dir`rust/helpers.c rust/kernel/fs/file.rs rust/kernel/fs/inode.rs +1 more+279 -250 replies
12/30rust: fs: introduce `file::Operations::seek`rust/kernel/fs/file.rs samples/rust/rust_rofs.rs+77 -20 replies
13/30rust: fs: introduce `file::Operations::read`rust/kernel/fs/file.rs rust/kernel/user.rs samples/rust/rust_rofs.rs+39 -30 replies
14/30rust: fs: add empty inode operationsrust/kernel/fs/inode.rs+48 -00 replies
15/30rust: fs: introduce `inode::Operations::lookup`rust/kernel/error.rs rust/kernel/fs/dentry.rs rust/kernel/fs/inode.rs +1 more+105 -320 replies
16/30rust: folio: introduce basic support for foliosrust/bindings/bindings_helper.h rust/helpers.c rust/kernel/folio.rs +1 more+404 -00 replies
17/30rust: fs: add empty address space operationsrust/kernel/fs.rs rust/kernel/fs/address_space.rs+59 -00 replies
18/30rust: fs: introduce `address_space::Operations::read_folio`rust/helpers.c rust/kernel/folio.rs rust/kernel/fs/address_space.rs +3 more+122 -190 replies
19/30rust: fs: introduce `FileSystem::read_xattr`rust/bindings/bindings_helper.h rust/kernel/error.rs rust/kernel/fs.rs+62 -00 replies
20/30rust: fs: introduce `FileSystem::statfs`rust/bindings/bindings_helper.h rust/kernel/error.rs rust/kernel/fs.rs+48 -10 replies
21/30rust: fs: introduce more inode typesrust/helpers.c rust/kernel/fs/file.rs rust/kernel/fs/inode.rs +1 more+187 -50 replies
22/30rust: fs: add per-superblock datarust/kernel/fs.rs rust/kernel/fs/sb.rs samples/rust/rust_rofs.rs+81 -160 replies
23/30rust: fs: allow file systems backed by a block devicerust/helpers.c rust/kernel/block.rs rust/kernel/fs.rs +3 more+328 -190 replies
24/30rust: fs: allow per-inode datarust/helpers.c rust/kernel/fs.rs rust/kernel/fs/inode.rs +2 more+143 -210 replies
25/30rust: fs: export file type from mode constantsrust/kernel/fs.rs+27 -00 replies
26/30rust: fs: allow populating i_lnkrust/kernel/fs/file.rs rust/kernel/fs/inode.rs samples/rust/rust_rofs.rs+45 -430 replies
27/30rust: fs: add `iomap` modulerust/bindings/bindings_helper.h rust/kernel/fs.rs rust/kernel/fs/iomap.rs+283 -01 reply
28/30rust: fs: add memalloc_nofs supportrust/helpers.c rust/kernel/fs.rs+24 -00 replies
29/30tarfs: introduce tar fsfs/Kconfig fs/Makefile fs/tarfs/Kconfig +4 more+500 -10 replies
30/30WIP: fs: ext2: add rust ro ext2 implementationfs/Kconfig fs/Makefile fs/rust-ext2/Kconfig +4 more+750 -01 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [RFC PATCH v2 00/30] Rust abstractions for VFS

This series introduces Rust abstractions that allow read-only file systems to be written in Rust.

There are three file systems implementations using these abstractions
abstractions: ext2, tarfs, and puzzlefs. The first two are part of this series.

Rust file system modules can be declared with the module_fs macro and are required to implement the following functions (which are part of the FileSystem trait):

    fn fill_super(
        sb: &mut SuperBlock<Self, sb::New>,
        mapper: Option<inode::Mapper>,
    ) -> Result<Self::Data>;

    fn init_root(sb: &SuperBlock<Self>) -> Result<dentry::Root<Self>>;

They can optionally implement the following:

    fn read_xattr(
        _dentry: &DEntry<Self>,
        _inode: &INode<Self>,
        _name: &CStr,
        _outbuf: &mut [u8],
    ) -> Result<usize>;

    fn statfs(_dentry: &DEntry<Self>) -> Result<Stat>;

They may also choose the type of the data they can attach to superblocks and/or inodes.

Lastly, file systems can implement inode, file, and address space operations and attach them to inodes when they're created, similar to how C does it. They can get a ro address space operations table from an implementation of iomap operations, to be used with generic ro file operations.

A git tree is available here:
git://github.com/wedsonaf/linux.git vfs-v2

Web:
https://github.com/wedsonaf/linux/commits/vfs-v2

---

Changes in v2:

- Rebased to latest rust-next tree
- Removed buffer heads
- Added iomap support
- Removed _pin field from Registration as it's not needed anymore
- Renamed sample filesystem to match the module's name
- Using typestate instead of a separate type for superblock/new-superblock
- Created separate submodules for superblocks, inodes, dentries, and files
- Split out operations from FileSystem to inode/file/address_space ops, similar to how C does it
- Removed usages of folio_set_error
- Removed UniqueFolio, for now reading blocks from devices via the pagecache
- Changed map() to return the entire folio if not in highmem
- Added support for unlocking the folio asynchronously
- Added from_raw to all new ref-counted types
- Added explicit types in calls to cast()
- Added typestate to folio
- Added support for implementing get_link
- Fixed data race when reading inode->i_state
- Added nofs scope support during allocation
- Link to v1: https://lore.kernel.org/rust-for-linux/[email protected]/

---

Wedson Almeida Filho (30):
rust: fs: add registration/unregistration of file systems
rust: fs: introduce the module_fs macro
samples: rust: add initial ro file system sample
rust: fs: introduce FileSystem::fill_super
rust: fs: introduce INode<T>
rust: fs: introduce DEntry<T>
rust: fs: introduce FileSystem::init_root
rust: file: move kernel::file to kernel::fs::file
rust: fs: generalise File for different file systems
rust: fs: add empty file operations
rust: fs: introduce file::Operations::read_dir
rust: fs: introduce file::Operations::seek
rust: fs: introduce file::Operations::read
rust: fs: add empty inode operations
rust: fs: introduce inode::Operations::lookup
rust: folio: introduce basic support for folios
rust: fs: add empty address space operations
rust: fs: introduce address_space::Operations::read_folio
rust: fs: introduce FileSystem::read_xattr
rust: fs: introduce FileSystem::statfs
rust: fs: introduce more inode types
rust: fs: add per-superblock data
rust: fs: allow file systems backed by a block device
rust: fs: allow per-inode data
rust: fs: export file type from mode constants
rust: fs: allow populating i_lnk
rust: fs: add iomap module
rust: fs: add memalloc_nofs support
tarfs: introduce tar fs
WIP: fs: ext2: add rust ro ext2 implementation

 fs/Kconfig                        |   2 +
 fs/Makefile                       |   2 +
 fs/rust-ext2/Kconfig              |  13 +
 fs/rust-ext2/Makefile             |   8 +
 fs/rust-ext2/defs.rs              | 173 +++++++
 fs/rust-ext2/ext2.rs              | 551 +++++++++++++++++++++
 fs/tarfs/Kconfig                  |  15 +
 fs/tarfs/Makefile                 |   8 +
 fs/tarfs/defs.rs                  |  80 +++
 fs/tarfs/tar.rs                   | 394 +++++++++++++++
 rust/bindings/bindings_helper.h   |  11 +
 rust/helpers.c                    | 182 +++++++
 rust/kernel/block.rs              |  10 +-
 rust/kernel/error.rs              |   8 +-
 rust/kernel/file.rs               | 251 ----------
 rust/kernel/folio.rs              | 305 ++++++++++++
 rust/kernel/fs.rs                 | 492 +++++++++++++++++++
 rust/kernel/fs/address_space.rs   |  90 ++++
 rust/kernel/fs/dentry.rs          | 136 ++++++
 rust/kernel/fs/file.rs            | 607 +++++++++++++++++++++++
 rust/kernel/fs/inode.rs           | 780 ++++++++++++++++++++++++++++++
 rust/kernel/fs/iomap.rs           | 281 +++++++++++
 rust/kernel/fs/sb.rs              | 194 ++++++++
 rust/kernel/lib.rs                |   6 +-
 rust/kernel/mem_cache.rs          |   2 -
 rust/kernel/user.rs               |   1 -
 samples/rust/Kconfig              |  10 +
 samples/rust/Makefile             |   1 +
 samples/rust/rust_rofs.rs         | 202 ++++++++
 scripts/generate_rust_analyzer.py |   2 +-
 30 files changed, 4555 insertions(+), 262 deletions(-)
 create mode 100644 fs/rust-ext2/Kconfig
 create mode 100644 fs/rust-ext2/Makefile
 create mode 100644 fs/rust-ext2/defs.rs
 create mode 100644 fs/rust-ext2/ext2.rs
 create mode 100644 fs/tarfs/Kconfig
 create mode 100644 fs/tarfs/Makefile
 create mode 100644 fs/tarfs/defs.rs
 create mode 100644 fs/tarfs/tar.rs
 delete mode 100644 rust/kernel/file.rs
 create mode 100644 rust/kernel/folio.rs
 create mode 100644 rust/kernel/fs.rs
 create mode 100644 rust/kernel/fs/address_space.rs
 create mode 100644 rust/kernel/fs/dentry.rs
 create mode 100644 rust/kernel/fs/file.rs
 create mode 100644 rust/kernel/fs/inode.rs
 create mode 100644 rust/kernel/fs/iomap.rs
 create mode 100644 rust/kernel/fs/sb.rs
 create mode 100644 samples/rust/rust_rofs.rs

base-commit: 183ea65d1fcd71039cf4d111a22d69c337bfd344

Signature · 1 line
2.34.1