From 29278db8f415ddb832d998a95918e82633c83e3c Mon Sep 17 00:00:00 2001 From: Wang Runji Date: Mon, 15 Jul 2019 17:57:20 +0800 Subject: [PATCH] support multiple fs - use RamFS as rootfs, mount SEFS at /test - for testing convenience, set default cwd to /test - fix spawn path and change_cwd --- deps/sefs | 2 +- src/libos/Cargo.lock | 57 +++++++++++++++++++++--------- src/libos/Cargo.toml | 2 ++ src/libos/src/fs/file.rs | 2 ++ src/libos/src/fs/inode_file.rs | 21 ++++++++++- src/libos/src/fs/socket_file.rs | 1 + src/libos/src/fs/unix_socket.rs | 1 + src/libos/src/lib.rs | 2 ++ src/libos/src/process/process.rs | 3 +- src/libos/src/process/spawn/mod.rs | 4 +-- test/mkdir/main.c | 6 ++-- 11 files changed, 76 insertions(+), 25 deletions(-) diff --git a/deps/sefs b/deps/sefs index 4fc745c5..1be96ad3 160000 --- a/deps/sefs +++ b/deps/sefs @@ -1 +1 @@ -Subproject commit 4fc745c541dc32d2d674d8bd087e83d72a7e42db +Subproject commit 1be96ad39575361037b456f4e5c1eb7b4fbfacec diff --git a/src/libos/Cargo.lock b/src/libos/Cargo.lock index 2858f387..b26f7646 100644 --- a/src/libos/Cargo.lock +++ b/src/libos/Cargo.lock @@ -6,9 +6,11 @@ version = "0.0.1" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "derive_builder 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rcore-fs 0.1.0", + "rcore-fs-mountfs 0.1.0", + "rcore-fs-ramfs 0.1.0", "rcore-fs-sefs 0.1.0", "sgx_trts 1.0.6", "sgx_tstd 1.0.6", @@ -50,7 +52,7 @@ dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.38 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -60,7 +62,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "darling_core 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.38 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -72,7 +74,7 @@ dependencies = [ "derive_builder_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.38 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -83,7 +85,7 @@ dependencies = [ "darling 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.38 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -98,11 +100,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -132,6 +133,28 @@ dependencies = [ [[package]] name = "rcore-fs" version = "0.1.0" +dependencies = [ + "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rcore-fs-mountfs" +version = "0.1.0" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rcore-fs 0.1.0", + "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rcore-fs-ramfs" +version = "0.1.0" +dependencies = [ + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rcore-fs 0.1.0", + "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "rcore-fs-sefs" @@ -207,6 +230,11 @@ name = "spin" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "spin" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "static_assertions" version = "0.3.1" @@ -219,7 +247,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.38" +version = "0.15.39" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", @@ -232,11 +260,6 @@ name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "version_check" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "xmas-elf" version = "0.6.2" @@ -260,14 +283,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum derive_builder_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0288a23da9333c246bb18c143426074a6ae96747995c5819d2947b64cd942b37" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum ident_case 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" "checksum spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "37b5646825922b96b5d7d676b5bb3458a54498e96ed7b0ce09dc43a07038fea4" +"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" "checksum static_assertions 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "389ce475f424f267dbed6479cbd8f126c5e1afb053b0acdaa019c74305fc65d1" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" -"checksum syn 0.15.38 (registry+https://github.com/rust-lang/crates.io-index)" = "37ea458a750f59ab679b47fef9b6722c586c5742f4cfe18a120bbc807e5e01fd" +"checksum syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d960b829a55e56db167e861ddb43602c003c7be0bee1d345021703fac2fb7c" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051" "checksum zero 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5" diff --git a/src/libos/Cargo.toml b/src/libos/Cargo.toml index 2ad5e878..61b8afd1 100644 --- a/src/libos/Cargo.toml +++ b/src/libos/Cargo.toml @@ -13,6 +13,8 @@ lazy_static = { version = "1.1.0", features = ["spin_no_std"] } # Implies nightl derive_builder = "0.7.2" rcore-fs = { path = "../../deps/sefs/rcore-fs" } rcore-fs-sefs = { path = "../../deps/sefs/rcore-fs-sefs" } +rcore-fs-ramfs = { path = "../../deps/sefs/rcore-fs-ramfs" } +rcore-fs-mountfs = { path = "../../deps/sefs/rcore-fs-mountfs" } [features] default = ["integrity_only_opt", "sgx_file_cache"] diff --git a/src/libos/src/fs/file.rs b/src/libos/src/fs/file.rs index a45a0e24..62c52762 100644 --- a/src/libos/src/fs/file.rs +++ b/src/libos/src/fs/file.rs @@ -378,6 +378,7 @@ impl File for StdoutFile { nlinks: 0, uid: 0, gid: 0, + rdev: 0, }) } @@ -494,6 +495,7 @@ impl File for StdinFile { nlinks: 0, uid: 0, gid: 0, + rdev: 0, }) } diff --git a/src/libos/src/fs/inode_file.rs b/src/libos/src/fs/inode_file.rs index eb17984a..60414c88 100644 --- a/src/libos/src/fs/inode_file.rs +++ b/src/libos/src/fs/inode_file.rs @@ -1,5 +1,7 @@ use rcore_fs::vfs::{FileSystem, FsError, INode}; use rcore_fs_sefs::SEFS; +use rcore_fs_ramfs::RamFS; +use rcore_fs_mountfs::MountFS; use std::fmt; use super::sgx_impl::SgxStorage; @@ -8,10 +10,22 @@ use super::*; lazy_static! { /// The root of file system pub static ref ROOT_INODE: Arc = { + // ramfs as rootfs + let rootfs = MountFS::new(RamFS::new()); + let root = rootfs.root_inode(); + let bin = root.create("test", FileType::Dir, 0o777) + .expect("failed to mkdir: /test"); + + // sefs let device = Box::new(SgxStorage::new("sefs")); let sefs = SEFS::open(device, &time::OcclumTimeProvider) .expect("failed to open SEFS"); - sefs.root_inode() + + // mount sefs at /test + bin.mount(sefs) + .expect("failed to mount SEFS"); + + root }; } @@ -187,6 +201,11 @@ impl From for Error { FsError::DirNotEmpty => ENOTEMPTY, FsError::WrongFs => EINVAL, FsError::DeviceError => EIO, + FsError::SymLoop => ELOOP, + FsError::NoDevice => ENXIO, + FsError::IOCTLError => EINVAL, + FsError::Again => EAGAIN, + FsError::Busy => EBUSY, }; Error::new(errno, "") } diff --git a/src/libos/src/fs/socket_file.rs b/src/libos/src/fs/socket_file.rs index 7e9cbaa7..52a79b15 100644 --- a/src/libos/src/fs/socket_file.rs +++ b/src/libos/src/fs/socket_file.rs @@ -115,6 +115,7 @@ impl File for SocketFile { nlinks: 0, uid: 0, gid: 0, + rdev: 0, }) } diff --git a/src/libos/src/fs/unix_socket.rs b/src/libos/src/fs/unix_socket.rs index 81b50c17..eb20731a 100644 --- a/src/libos/src/fs/unix_socket.rs +++ b/src/libos/src/fs/unix_socket.rs @@ -78,6 +78,7 @@ impl File for UnixSocketFile { nlinks: 0, uid: 0, gid: 0, + rdev: 0, }) } diff --git a/src/libos/src/lib.rs b/src/libos/src/lib.rs index fdb192e2..ec8b50e8 100644 --- a/src/libos/src/lib.rs +++ b/src/libos/src/lib.rs @@ -24,6 +24,8 @@ extern crate lazy_static; extern crate log; extern crate rcore_fs; extern crate rcore_fs_sefs; +extern crate rcore_fs_ramfs; +extern crate rcore_fs_mountfs; #[macro_use] extern crate derive_builder; diff --git a/src/libos/src/process/process.rs b/src/libos/src/process/process.rs index a01c8255..7eed7c04 100644 --- a/src/libos/src/process/process.rs +++ b/src/libos/src/process/process.rs @@ -13,7 +13,7 @@ lazy_static! { pgid: 1, tgid: 0, exit_status: 0, - cwd: "/".to_owned(), + cwd: "/test".to_owned(), // FIXME: hack for test clear_child_tid: None, parent: None, children: Vec::new(), @@ -99,6 +99,7 @@ impl Process { self.cwd = path.to_owned(); } else { // relative + self.cwd += "/"; self.cwd += path; } } diff --git a/src/libos/src/process/spawn/mod.rs b/src/libos/src/process/spawn/mod.rs index dca781b8..e29d2ae2 100644 --- a/src/libos/src/process/spawn/mod.rs +++ b/src/libos/src/process/spawn/mod.rs @@ -40,8 +40,8 @@ pub fn do_spawn>( parent_ref: &ProcessRef, ) -> Result { let mut elf_buf = { - let path = elf_path.as_ref().to_str().unwrap().trim_start_matches('/'); - let inode = ROOT_INODE.lookup(path)?; + let path = elf_path.as_ref().to_str().unwrap(); + let inode = parent_ref.lock().unwrap().lookup_inode(path)?; inode.read_as_vec()? }; diff --git a/test/mkdir/main.c b/test/mkdir/main.c index a5c83b8d..8239e0e6 100644 --- a/test/mkdir/main.c +++ b/test/mkdir/main.c @@ -7,7 +7,7 @@ int main(int argc, const char* argv[]) { - const int BUF_SIZE = 10; + const int BUF_SIZE = 20; char buf[10]; int ret; @@ -17,14 +17,14 @@ int main(int argc, const char* argv[]) { return -1; } - const char expect_cwd[] = "/"; + const char expect_cwd[] = "/test"; if(strcmp(buf, expect_cwd)) { printf("incorrect cwd \"%s\". expect \"%s\".\n", buf, expect_cwd); return -1; } const char DIR_NAME[] = "test_dir"; - const char DIR_PATH[] = "/test_dir"; + const char DIR_PATH[] = "/test/test_dir"; const int DIR_MODE = 0664; ret = mkdir(DIR_NAME, DIR_MODE); if(ret < 0) {