feat(tvix/store): add mount command to entrypoint and fuse mod

`tvix-store mount PATH` will mount the tvix-store to the given path.

Change-Id: Icb82a6b3cb8a22eec856c375a28ae5580403833f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8665
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
Florian Klink 2023-05-28 09:32:21 +02:00 committed by flokli
parent 365937cd08
commit b3ca1a78eb
3 changed files with 55 additions and 0 deletions

View file

@ -25,6 +25,7 @@ use tvix_store::proto::GRPCBlobServiceWrapper;
use tvix_store::proto::GRPCDirectoryServiceWrapper; use tvix_store::proto::GRPCDirectoryServiceWrapper;
use tvix_store::proto::GRPCPathInfoServiceWrapper; use tvix_store::proto::GRPCPathInfoServiceWrapper;
use tvix_store::TvixStoreIO; use tvix_store::TvixStoreIO;
use tvix_store::FUSE;
#[cfg(feature = "reflection")] #[cfg(feature = "reflection")]
use tvix_store::proto::FILE_DESCRIPTOR_SET; use tvix_store::proto::FILE_DESCRIPTOR_SET;
@ -59,6 +60,12 @@ enum Commands {
#[clap(value_name = "PATH")] #[clap(value_name = "PATH")]
paths: Vec<PathBuf>, paths: Vec<PathBuf>,
}, },
/// Mounts a tvix-store at the given mountpoint
#[cfg(feature = "fuse")]
Mount {
#[clap(value_name = "PATH")]
dest: PathBuf,
},
} }
#[tokio::main] #[tokio::main]
@ -172,6 +179,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
try_join_all(tasks).await?; try_join_all(tasks).await?;
} }
#[cfg(feature = "fuse")]
Commands::Mount { dest } => {
let blob_service = GRPCBlobService::from_client(
BlobServiceClient::connect("http://[::1]:8000").await?,
);
let directory_service = GRPCDirectoryService::from_client(
DirectoryServiceClient::connect("http://[::1]:8000").await?,
);
let path_info_service_client =
PathInfoServiceClient::connect("http://[::1]:8000").await?;
let path_info_service =
GRPCPathInfoService::from_client(path_info_service_client.clone());
tokio::task::spawn_blocking(move || {
let f = FUSE::new(path_info_service, directory_service, blob_service);
fuser::mount2(f, &dest, &[])
})
.await??
}
}; };
Ok(()) Ok(())
} }

View file

@ -0,0 +1,24 @@
use crate::{
blobservice::BlobService, directoryservice::DirectoryService, pathinfoservice::PathInfoService,
};
pub struct FUSE<BS: BlobService, DS: DirectoryService, PS: PathInfoService> {
blob_service: BS,
directory_service: DS,
path_info_service: PS,
}
impl<BS: BlobService, DS: DirectoryService, PS: PathInfoService> FUSE<BS, DS, PS> {
pub fn new(path_info_service: PS, directory_service: DS, blob_service: BS) -> Self {
Self {
blob_service,
path_info_service,
directory_service,
}
}
}
impl<BS: BlobService, DS: DirectoryService, PS: PathInfoService> fuser::Filesystem
for FUSE<BS, DS, PS>
{
}

View file

@ -1,5 +1,7 @@
mod digests; mod digests;
mod errors; mod errors;
#[cfg(feature = "fuse")]
mod fuse;
mod store_io; mod store_io;
pub mod blobservice; pub mod blobservice;
@ -13,5 +15,8 @@ pub use digests::B3Digest;
pub use errors::Error; pub use errors::Error;
pub use store_io::TvixStoreIO; pub use store_io::TvixStoreIO;
#[cfg(feature = "fuse")]
pub use fuse::FUSE;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;