On 23/10/18 09:24AM, Wedson Almeida Filho wrote: > From: Wedson Almeida Filho <walmeida@xxxxxxxxxxxxx> > > This series introduces Rust abstractions that allow page-cache-backed read-only > file systems to be written in Rust. > > There are two file systems that are built on top of these abstractions: tarfs > and puzzlefs. The former has zero unsafe blocks and is included as a patch in > this series; the latter is described elsewhere [1]. We limit the functionality > to the bare minimum needed to implement them. > > 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): > > impl FileSystem for MyFS { > fn super_params(sb: &NewSuperBlock<Self>) -> Result<SuperParams<Self::Data>>; > fn init_root(sb: &SuperBlock<Self>) -> Result<ARef<INode<Self>>>; > fn read_dir(inode: &INode<Self>, emitter: &mut DirEmitter) -> Result; > fn lookup(parent: &INode<Self>, name: &[u8]) -> Result<ARef<INode<Self>>>; > fn read_folio(inode: &INode<Self>, folio: LockedFolio<'_>) -> Result; > } > > They can optionally implement the following: > > fn read_xattr(inode: &INode<Self>, name: &CStr, outbuf: &mut [u8]) -> Result<usize>; > fn statfs(sb: &SuperBlock<Self>) -> Result<Stat>; > > They may also choose the type of the data they can attach to superblocks and/or > inodes. > > There a couple of issues that are likely to lead to unsoundness that have to do > with the unregistration of file systems. I will send separate emails about > them. > > A git tree is available here: > git://github.com/wedsonaf/linux.git vfs > > Web: > https://github.com/wedsonaf/linux/commits/vfs I've checked out your branch and but it doesn't compile: ``` $ make LLVM=1 -j4 DESCEND objtool CALL scripts/checksyscalls.sh make[4]: 'install_headers' is up to date. RUSTC L rust/kernel.o error[E0425]: cannot find function `folio_alloc` in crate `bindings` --> rust/kernel/folio.rs:43:54 | 43 | let f = ptr::NonNull::new(unsafe { bindings::folio_alloc(bindings::GFP_KERNEL, order) }) | ^^^^^^^^^^^ help: a function with a similar name exists: `__folio_alloc` | ::: /home/amiculas/work/linux/rust/bindings/bindings_generated.rs:17311:5 | 17311 | / pub fn __folio_alloc( 17312 | | gfp: gfp_t, 17313 | | order: core::ffi::c_uint, 17314 | | preferred_nid: core::ffi::c_int, 17315 | | nodemask: *mut nodemask_t, 17316 | | ) -> *mut folio; | |___________________- similarly named function `__folio_alloc` defined here error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. make[2]: *** [rust/Makefile:460: rust/kernel.o] Error 1 make[1]: *** [/home/amiculas/work/linux/Makefile:1208: prepare] Error 2 make: *** [Makefile:234: __sub-make] Error 2 ``` I'm missing `CONFIG_NUMA`, which seems to guard `folio_alloc` (include/linux/gfp.h): ``` #ifdef CONFIG_NUMA struct page *alloc_pages(gfp_t gfp, unsigned int order); struct folio *folio_alloc(gfp_t gfp, unsigned order); struct folio *vma_alloc_folio(gfp_t gfp, int order, struct vm_area_struct *vma, unsigned long addr, bool hugepage); #else ``` > > [1]: The PuzzleFS container filesystem: https://lwn.net/Articles/945320/ > > Wedson Almeida Filho (19): > 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::super_params` > rust: fs: introduce `INode<T>` > rust: fs: introduce `FileSystem::init_root` > rust: fs: introduce `FileSystem::read_dir` > rust: fs: introduce `FileSystem::lookup` > rust: folio: introduce basic support for folios > rust: fs: introduce `FileSystem::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: add basic support for fs buffer heads > rust: fs: allow file systems backed by a block device > rust: fs: allow per-inode data > rust: fs: export file type from mode constants > tarfs: introduce tar fs > > fs/Kconfig | 1 + > fs/Makefile | 1 + > fs/tarfs/Kconfig | 16 + > fs/tarfs/Makefile | 8 + > fs/tarfs/defs.rs | 80 ++ > fs/tarfs/tar.rs | 322 +++++++ > rust/bindings/bindings_helper.h | 13 + > rust/bindings/lib.rs | 6 + > rust/helpers.c | 142 ++++ > rust/kernel/error.rs | 6 +- > rust/kernel/folio.rs | 214 +++++ > rust/kernel/fs.rs | 1290 +++++++++++++++++++++++++++++ > rust/kernel/fs/buffer.rs | 60 ++ > rust/kernel/lib.rs | 2 + > rust/kernel/mem_cache.rs | 2 - > samples/rust/Kconfig | 10 + > samples/rust/Makefile | 1 + > samples/rust/rust_rofs.rs | 154 ++++ > scripts/generate_rust_analyzer.py | 2 +- > 19 files changed, 2324 insertions(+), 6 deletions(-) > 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 > create mode 100644 rust/kernel/folio.rs > create mode 100644 rust/kernel/fs.rs > create mode 100644 rust/kernel/fs/buffer.rs > create mode 100644 samples/rust/rust_rofs.rs > > > base-commit: b0bc357ef7a98904600826dea3de79c0c67eb0a7 > -- > 2.34.1 >