-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5251 from systeminit/si-fs
feat: a fuse filesystem for si
- Loading branch information
Showing
24 changed files
with
4,235 additions
and
2,339 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
load( | ||
"@prelude-si//:macros.bzl", | ||
"docker_image", | ||
"nix_omnibus_pkg", | ||
"rust_binary", | ||
) | ||
|
||
rust_binary( | ||
name = "si-fs", | ||
deps = [ | ||
"//lib/si-filesystem:si-filesystem", | ||
"//third-party/rust:clap", | ||
"//third-party/rust:color-eyre", | ||
"//third-party/rust:nix", | ||
"//third-party/rust:tokio", | ||
], | ||
srcs = glob(["src/**/*.rs"]), | ||
env = {"CARGO_BIN_NAME": "si-fs"}, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "si-fs" | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
publish.workspace = true | ||
|
||
[dependencies] | ||
clap = { workspace = true } | ||
color-eyre = { workspace = true } | ||
si-filesystem = { path = "../../lib/si-filesystem" } | ||
tokio = { workspace = true } | ||
nix = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use std::str::FromStr; | ||
|
||
use clap::Parser; | ||
use color_eyre::Result; | ||
use nix::{fcntl::OFlag, sys::stat::Mode, unistd::ForkResult}; | ||
use si_filesystem::{mount, WorkspaceId}; | ||
use tokio::runtime::Runtime; | ||
|
||
#[derive(Parser, Debug)] | ||
struct Args { | ||
#[arg(long, short = 'w')] | ||
workspace_id: String, | ||
#[arg(long, short = 'e')] | ||
endpoint: String, | ||
#[arg(long, short = 't', env = "SI_BEARER_TOKEN")] | ||
token: String, | ||
#[arg(long, short = 'f')] | ||
foreground: bool, | ||
#[arg(value_name = "MOUNTPOINT")] | ||
mount_point: String, | ||
} | ||
|
||
fn redirect_to_dev_null() -> Result<()> { | ||
let dev_null_fd = nix::fcntl::open("/dev/null", OFlag::O_RDWR, Mode::empty())?; | ||
|
||
nix::unistd::dup2(dev_null_fd, nix::libc::STDOUT_FILENO)?; | ||
nix::unistd::dup2(dev_null_fd, nix::libc::STDIN_FILENO)?; | ||
nix::unistd::dup2(dev_null_fd, nix::libc::STDERR_FILENO)?; | ||
|
||
nix::unistd::close(dev_null_fd)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn daemonize() -> Result<()> { | ||
match unsafe { nix::unistd::fork() }? { | ||
ForkResult::Parent { .. } => { | ||
std::process::exit(0); | ||
} | ||
ForkResult::Child => { | ||
nix::unistd::setsid()?; | ||
|
||
match unsafe { nix::unistd::fork() }? { | ||
ForkResult::Parent { .. } => { | ||
std::process::exit(0); | ||
} | ||
ForkResult::Child => { | ||
redirect_to_dev_null()?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn main() -> Result<()> { | ||
color_eyre::install()?; | ||
let args = Args::parse(); | ||
let workspace_id = WorkspaceId::from_str(&args.workspace_id)?; | ||
|
||
if !args.foreground { | ||
daemonize()?; | ||
} | ||
|
||
let rt = Runtime::new()?; | ||
|
||
mount( | ||
args.token.clone(), | ||
args.endpoint.clone(), | ||
workspace_id, | ||
&args.mount_point, | ||
rt.handle().clone(), | ||
None, | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load("@prelude-si//:macros.bzl", "rust_library") | ||
|
||
rust_library( | ||
name = "si-filesystem", | ||
deps = [ | ||
"//lib/si-id:si-id", | ||
"//lib/si-frontend-types-rs:si-frontend-types", | ||
|
||
"//third-party/rust:fuser", | ||
"//third-party/rust:nix", | ||
"//third-party/rust:reqwest", | ||
"//third-party/rust:thiserror", | ||
"//third-party/rust:tokio", | ||
], | ||
srcs = glob([ | ||
"src/**/*.rs", | ||
]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "si-filesystem" | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
publish.workspace = true | ||
|
||
[dependencies] | ||
si-id = { path = "../si-id" } | ||
si-frontend-types = { path = "../si-frontend-types-rs" } | ||
|
||
fuser = { workspace = true } | ||
nix = { workspace = true } | ||
reqwest = { workspace = true } | ||
thiserror = { workspace = true } | ||
tokio = { workspace = true } |
Oops, something went wrong.