Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the UnionFileSystem and mem_fs::FileSystem don't allow mounting overlapping directories #3678

Open
Michael-F-Bryan opened this issue Mar 14, 2023 · 2 comments
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs priority-medium Medium priority issue
Milestone

Comments

@Michael-F-Bryan
Copy link
Contributor

Describe the bug

As part of #3677, I wanted to mount different folders from the host system to overlapping folders in the guest (e.g. /tmp/first/ goes to /mapped/ and /home/michael/ goes to /mapped/nested/). It doesn't look like this use case is supported by either UnionFileSystem or mem_fs::FileSystem at the moment.

Steps to reproduce

Here are some tests we can add to the wasmer-vfs crate.

// lib/vfs/src/union_fs.rs

use crate::{FileSystem, FileSystemExt, unionFileSystem, mem_fs};

#[test]
fn mount_to_overlapping_directories() {
    let top_level = mem_fs::FileSystem::default();
    top_level.touch("/file.txt").unwrap();
    let nested = mem_fs::FileSystem::default();
    nested.touch("/another-file.txt").unwrap();

    let mut fs = UnionFileSystem::default();
    fs.mount(
        "top-level",
        "/",
        false,
        Box::new(top_level),
        Some("/top-level"),
    );
    fs.mount(
        "nested",
        "/",
        false,
        Box::new(nested),
        Some("/top-level/nested"),
    );

    assert!(fs.is_dir("/top-level"));
    assert!(fs.is_file("/top-level/file.txt"));
    assert!(fs.is_dir("/top-level/nested"));
    assert!(fs.is_file("/top-level/nested/another-file.txt"));
}
// lib/vfs/src/mem_fs/filesystem.rs

#[test]
fn mount_to_overlapping_directories() {
    let top_level = FileSystem::default();
    top_level.touch("/file.txt").unwrap();
    let nested = FileSystem::default();
    nested.touch("/another-file.txt").unwrap();
    let top_level: Arc<dyn crate::FileSystem + Send + Sync> = Arc::new(top_level);
    let nested: Arc<dyn crate::FileSystem + Send + Sync> = Arc::new(nested);

    let fs = FileSystem::default();
    fs.mount("/top-level".into(), &top_level, "/".into())
        .unwrap();
    fs.mount("/top-level/nested".into(), &nested, "/".into())
        .unwrap();

    assert!(fs.is_dir("/top-level"));
    assert!(fs.is_file("/top-level/file.txt"));
    assert!(fs.is_dir("/top-level/nested"));
    assert!(fs.is_file("/top-level/nested/another-file.txt"));
}

Expected behavior

The above test should pass.

Actual behavior

---- union_fs::tests::mount_to_overlapping_directories stdout ----
thread 'union_fs::tests::mount_to_overlapping_directories' panicked at 'assertion failed: fs.is_dir(\"/top-level\")', lib/vfs/src/union_fs.rs:1101:9

---- mem_fs::filesystem::test_filesystem::mount_to_overlapping_directories stdout ----
thread 'mem_fs::filesystem::test_filesystem::mount_to_overlapping_directories' panicked at 'called `Result::unwrap()` on an `Err` value: UnknownError', lib/vfs/src/mem_fs/filesystem.rs:1719:14

The mem_fs test fails because we don't know how to handle Some(Node::ArcDirectory(..)) in this match statement:

pub(super) fn add_child_to_node(&mut self, inode: Inode, new_child: Inode) -> Result<()> {
match self.storage.get_mut(inode) {
Some(Node::Directory(DirectoryNode {
children,
metadata: Metadata { modified, .. },
..
})) => {
children.push(new_child);
*modified = time();
Ok(())
}
_ => Err(FsError::UnknownError),
}
}

@Michael-F-Bryan Michael-F-Bryan added bug Something isn't working 📦 lib-vfs About wasmer-vfs labels Mar 14, 2023
Michael-F-Bryan pushed a commit that referenced this issue Mar 14, 2023
Michael-F-Bryan pushed a commit that referenced this issue Mar 14, 2023
Michael-F-Bryan pushed a commit that referenced this issue Mar 14, 2023
@syrusakbary
Copy link
Member

Thanks for creating this issue with a way to reproduce it, super clear to start the discussion later in time!

@ptitSeb
Copy link
Contributor

ptitSeb commented Apr 3, 2023

Following #3737 the test now do

thread 'mem_fs::filesystem::test_filesystem::mount_to_overlapping_directories' panicked at 'called `Result::unwrap()` on an `Err` value: AlreadyExists', lib/vfs/src/mem_fs/filesystem.rs:1719:14

Wich does not really add support, but at least this is coherent behavior.

Some testing for ArcDirectory support should be written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs priority-medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants