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
This commit is contained in:
Wang Runji 2019-07-15 17:57:20 +08:00 committed by Tate, Hongliang Tian
parent 30265261cf
commit 29278db8f4
11 changed files with 76 additions and 25 deletions

2
deps/sefs vendored

@ -1 +1 @@
Subproject commit 4fc745c541dc32d2d674d8bd087e83d72a7e42db
Subproject commit 1be96ad39575361037b456f4e5c1eb7b4fbfacec

57
src/libos/Cargo.lock generated

@ -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"

@ -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"]

@ -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,
})
}

@ -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<INode> = {
// 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<FsError> 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, "")
}

@ -115,6 +115,7 @@ impl File for SocketFile {
nlinks: 0,
uid: 0,
gid: 0,
rdev: 0,
})
}

@ -78,6 +78,7 @@ impl File for UnixSocketFile {
nlinks: 0,
uid: 0,
gid: 0,
rdev: 0,
})
}

@ -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;

@ -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;
}
}

@ -40,8 +40,8 @@ pub fn do_spawn<P: AsRef<Path>>(
parent_ref: &ProcessRef,
) -> Result<u32, Error> {
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()?
};

@ -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) {