diff options
Diffstat (limited to '')
-rw-r--r-- | tvix/castore/src/fs/file_attr.rs (renamed from tvix/store/src/fs/file_attr.rs) | 0 | ||||
-rw-r--r-- | tvix/castore/src/fs/fuse.rs (renamed from tvix/store/src/fs/fuse.rs) | 0 | ||||
-rw-r--r-- | tvix/castore/src/fs/inode_tracker.rs (renamed from tvix/store/src/fs/inode_tracker.rs) | 4 | ||||
-rw-r--r-- | tvix/castore/src/fs/inodes.rs (renamed from tvix/store/src/fs/inodes.rs) | 6 | ||||
-rw-r--r-- | tvix/castore/src/fs/mod.rs (renamed from tvix/store/src/fs/mod.rs) | 20 | ||||
-rw-r--r-- | tvix/castore/src/fs/virtiofs.rs (renamed from tvix/store/src/fs/virtiofs.rs) | 0 | ||||
-rw-r--r-- | tvix/store/Cargo.toml | 51 | ||||
-rw-r--r-- | tvix/store/src/bin/tvix-store.rs | 14 | ||||
-rw-r--r-- | tvix/store/src/fs/root_nodes.rs | 61 | ||||
-rw-r--r-- | tvix/store/src/lib.rs | 3 | ||||
-rw-r--r-- | tvix/store/src/pathinfoservice/fs/mod.rs | 84 | ||||
-rw-r--r-- | tvix/store/src/pathinfoservice/fs/tests.rs (renamed from tvix/store/src/fs/tests.rs) | 18 | ||||
-rw-r--r-- | tvix/store/src/pathinfoservice/mod.rs | 6 |
13 files changed, 125 insertions, 142 deletions
diff --git a/tvix/store/src/fs/file_attr.rs b/tvix/castore/src/fs/file_attr.rs index ad41f036a253..ad41f036a253 100644 --- a/tvix/store/src/fs/file_attr.rs +++ b/tvix/castore/src/fs/file_attr.rs diff --git a/tvix/store/src/fs/fuse.rs b/tvix/castore/src/fs/fuse.rs index 98793bf47d58..98793bf47d58 100644 --- a/tvix/store/src/fs/fuse.rs +++ b/tvix/castore/src/fs/fuse.rs diff --git a/tvix/store/src/fs/inode_tracker.rs b/tvix/castore/src/fs/inode_tracker.rs index 3cabbbd247b5..4a8283b6b144 100644 --- a/tvix/store/src/fs/inode_tracker.rs +++ b/tvix/castore/src/fs/inode_tracker.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, sync::Arc}; use super::inodes::{DirectoryInodeData, InodeData}; -use tvix_castore::B3Digest; +use crate::B3Digest; /// InodeTracker keeps track of inodes, stores data being these inodes and deals /// with inode allocation. @@ -132,7 +132,7 @@ impl InodeTracker { #[cfg(test)] mod tests { - use crate::tests::fixtures; + use crate::fixtures; use super::InodeData; use super::InodeTracker; diff --git a/tvix/store/src/fs/inodes.rs b/tvix/castore/src/fs/inodes.rs index 4047199982b2..9131b703bae0 100644 --- a/tvix/store/src/fs/inodes.rs +++ b/tvix/castore/src/fs/inodes.rs @@ -1,7 +1,7 @@ //! This module contains all the data structures used to track information -//! about inodes, which present tvix-store nodes in a filesystem. -use tvix_castore::proto as castorepb; -use tvix_castore::B3Digest; +//! about inodes, which present tvix-castore nodes in a filesystem. +use crate::proto as castorepb; +use crate::B3Digest; #[derive(Clone, Debug)] pub enum InodeData { diff --git a/tvix/store/src/fs/mod.rs b/tvix/castore/src/fs/mod.rs index c11bd0a44c7e..9bd021cb09fe 100644 --- a/tvix/store/src/fs/mod.rs +++ b/tvix/castore/src/fs/mod.rs @@ -9,9 +9,13 @@ pub mod fuse; #[cfg(feature = "virtiofs")] pub mod virtiofs; -#[cfg(test)] -mod tests; - +use crate::proto as castorepb; +use crate::{ + blobservice::{BlobReader, BlobService}, + directoryservice::DirectoryService, + proto::{node::Node, NamedNode}, + B3Digest, +}; use fuse_backend_rs::abi::fuse_abi::stat64; use fuse_backend_rs::api::filesystem::{Context, FileSystem, FsOptions, ROOT_ID}; use futures::StreamExt; @@ -29,15 +33,8 @@ use tokio::{ sync::mpsc, }; use tracing::{debug, info_span, instrument, warn}; -use tvix_castore::proto as castorepb; -use tvix_castore::{ - blobservice::{BlobReader, BlobService}, - directoryservice::DirectoryService, - proto::{node::Node, NamedNode}, - B3Digest, -}; -use self::root_nodes::RootNodes; +pub use self::root_nodes::RootNodes; use self::{ file_attr::{gen_file_attr, ROOT_FILE_ATTR}, inode_tracker::InodeTracker, @@ -75,6 +72,7 @@ use self::{ /// merkle structure is a DAG, not a tree, this also means we can't do "bucketed /// allocation", aka reserve Directory.size inodes for each directory node we /// explore. +/// Tests for this live in the tvix-store crate. pub struct TvixStoreFs<BS, DS, RN> { blob_service: BS, directory_service: DS, diff --git a/tvix/store/src/fs/virtiofs.rs b/tvix/castore/src/fs/virtiofs.rs index 846270d28568..846270d28568 100644 --- a/tvix/store/src/fs/virtiofs.rs +++ b/tvix/castore/src/fs/virtiofs.rs diff --git a/tvix/store/Cargo.toml b/tvix/store/Cargo.toml index 044b305b96ae..0a8e690e8250 100644 --- a/tvix/store/Cargo.toml +++ b/tvix/store/Cargo.toml @@ -14,7 +14,6 @@ data-encoding = "2.3.3" futures = "0.3.28" lazy_static = "1.4.0" nix-compat = { path = "../nix-compat", features = ["async"] } -parking_lot = "0.12.1" pin-project-lite = "0.2.13" prost = "0.12.1" sha2 = "0.10.6" @@ -35,42 +34,10 @@ async-recursion = "1.0.5" reqwest = { version = "0.11.22", features = ["rustls-tls", "stream"], default-features = false } xz2 = "0.1.7" -[dependencies.fuse-backend-rs] -optional = true -version = "0.11.0" - -[dependencies.vhost] -optional = true -version = "0.6" - -[dependencies.vhost-user-backend] -optional = true -version = "0.8" - -[dependencies.virtio-queue] -optional = true -version = "0.7" - -[dependencies.vm-memory] -optional = true -version = "0.10" - -[dependencies.vmm-sys-util] -optional = true -version = "0.11" - -[dependencies.virtio-bindings] -optional = true -version = "0.2.1" - [dependencies.tonic-reflection] optional = true version = "0.10.2" -[dependencies.libc] -optional = true -version = "0.2.144" - [build-dependencies] prost-build = "0.12.1" tonic-build = "0.10.2" @@ -80,19 +47,11 @@ test-case = "2.2.2" tempfile = "3.3.0" tokio-retry = "0.3.0" +[dev-dependencies.libc] +version = "0.2.144" + [features] default = ["fuse", "tonic-reflection"] -fs = ["dep:libc", "dep:fuse-backend-rs"] -virtiofs = [ - "fs", - "dep:vhost", - "dep:vhost-user-backend", - "dep:virtio-queue", - "dep:vm-memory", - "dep:vmm-sys-util", - "dep:virtio-bindings", - "fuse-backend-rs?/vhost-user-fs", # impl FsCacheReqHandler for SlaveFsCacheReq - "fuse-backend-rs?/virtiofs", -] -fuse = ["fs"] +fuse = ["tvix-castore/fuse"] +virtiofs = ["tvix-castore/virtiofs"] tonic-reflection = ["dep:tonic-reflection", "tvix-castore/tonic-reflection"] diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs index e4f2e0801b81..bf59366eb34e 100644 --- a/tvix/store/src/bin/tvix-store.rs +++ b/tvix/store/src/bin/tvix-store.rs @@ -29,14 +29,14 @@ use tvix_store::proto::GRPCPathInfoServiceWrapper; use tvix_store::proto::NarInfo; use tvix_store::proto::PathInfo; -#[cfg(feature = "fs")] -use tvix_store::fs::TvixStoreFs; +#[cfg(any(feature = "fuse", feature = "virtiofs"))] +use tvix_store::pathinfoservice::make_fs; #[cfg(feature = "fuse")] -use tvix_store::fs::fuse::FuseDaemon; +use tvix_castore::fs::fuse::FuseDaemon; #[cfg(feature = "virtiofs")] -use tvix_store::fs::virtiofs::start_virtiofs_daemon; +use tvix_castore::fs::virtiofs::start_virtiofs_daemon; #[cfg(feature = "tonic-reflection")] use tvix_castore::proto::FILE_DESCRIPTOR_SET as CASTORE_FILE_DESCRIPTOR_SET; @@ -365,7 +365,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { let path_info_service: Arc<dyn PathInfoService> = path_info_service.into(); let mut fuse_daemon = tokio::task::spawn_blocking(move || { - let f = TvixStoreFs::new( + let fs = make_fs( blob_service, directory_service, path_info_service, @@ -373,7 +373,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { ); info!("mounting tvix-store on {:?}", &dest); - FuseDaemon::new(f, &dest, threads) + FuseDaemon::new(fs, &dest, threads) }) .await??; @@ -409,7 +409,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { let path_info_service: Arc<dyn PathInfoService> = path_info_service.into(); tokio::task::spawn_blocking(move || { - let fs = TvixStoreFs::new( + let fs = make_fs( blob_service, directory_service, path_info_service, diff --git a/tvix/store/src/fs/root_nodes.rs b/tvix/store/src/fs/root_nodes.rs deleted file mode 100644 index e672c6e647f3..000000000000 --- a/tvix/store/src/fs/root_nodes.rs +++ /dev/null @@ -1,61 +0,0 @@ -use std::{ops::Deref, pin::Pin}; - -use futures::{Stream, StreamExt}; -use nix_compat::store_path::StorePath; -use tonic::async_trait; -use tvix_castore::{proto::node::Node, Error}; - -use crate::pathinfoservice::PathInfoService; - -/// Provides an interface for looking up root nodes in tvix-castore by given -/// a lookup key (usually the basename), and optionally allow a listing. -/// -#[async_trait] -pub trait RootNodes: Send + Sync { - /// Looks up a root CA node based on the basename of the node in the root - /// directory of the filesystem. - async fn get_by_basename(&self, name: &[u8]) -> Result<Option<Node>, Error>; - - /// Lists all root CA nodes in the filesystem. An error can be returned - /// in case listing is not allowed - fn list(&self) -> Pin<Box<dyn Stream<Item = Result<Node, Error>> + Send>>; -} - -/// Implements root node lookup for any [PathInfoService]. This represents a flat -/// directory structure like /nix/store where each entry in the root filesystem -/// directory corresponds to a CA node. -#[async_trait] -impl<T> RootNodes for T -where - T: Deref<Target = dyn PathInfoService> + Send + Sync, -{ - async fn get_by_basename(&self, name: &[u8]) -> Result<Option<Node>, Error> { - let Ok(store_path) = StorePath::from_bytes(name) else { - return Ok(None); - }; - - Ok(self - .deref() - .get(*store_path.digest()) - .await? - .map(|path_info| { - path_info - .node - .expect("missing root node") - .node - .expect("empty node") - })) - } - - fn list(&self) -> Pin<Box<dyn Stream<Item = Result<Node, Error>> + Send>> { - Box::pin(self.deref().list().map(|result| { - result.map(|path_info| { - path_info - .node - .expect("missing root node") - .node - .expect("empty node") - }) - })) - } -} diff --git a/tvix/store/src/lib.rs b/tvix/store/src/lib.rs index c59121453352..5b57781c4dab 100644 --- a/tvix/store/src/lib.rs +++ b/tvix/store/src/lib.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "fs")] -pub mod fs; - pub mod nar; pub mod pathinfoservice; pub mod proto; diff --git a/tvix/store/src/pathinfoservice/fs/mod.rs b/tvix/store/src/pathinfoservice/fs/mod.rs new file mode 100644 index 000000000000..524aa10391f8 --- /dev/null +++ b/tvix/store/src/pathinfoservice/fs/mod.rs @@ -0,0 +1,84 @@ +use futures::Stream; +use futures::StreamExt; +use std::ops::Deref; +use std::pin::Pin; +use tonic::async_trait; +use tvix_castore::fs::{RootNodes, TvixStoreFs}; +use tvix_castore::proto as castorepb; +use tvix_castore::Error; +use tvix_castore::{blobservice::BlobService, directoryservice::DirectoryService}; + +use super::PathInfoService; + +#[cfg(test)] +mod tests; + +/// Helper to construct a [TvixStoreFs] from a [BlobService], [DirectoryService] +/// and [PathInfoService]. +/// This avoids users to have to interact with the wrapper struct directly, as +/// it leaks into the type signature of TvixStoreFS. +pub fn make_fs<BS, DS, PS>( + blob_service: BS, + directory_service: DS, + path_info_service: PS, + list_root: bool, +) -> TvixStoreFs<BS, DS, RootNodesWrapper<PS>> +where + BS: Deref<Target = dyn BlobService> + Send + Clone + 'static, + DS: Deref<Target = dyn DirectoryService> + Send + Clone + 'static, + PS: Deref<Target = dyn PathInfoService> + Send + Sync + Clone + 'static, +{ + TvixStoreFs::new( + blob_service, + directory_service, + RootNodesWrapper(path_info_service), + list_root, + ) +} + +/// Wrapper to satisfy Rust's orphan rules for trait implementations, as +/// RootNodes is coming from the [tvix-castore] crate. +#[doc(hidden)] +#[derive(Clone, Debug)] +pub struct RootNodesWrapper<T>(pub(crate) T); + +/// Implements root node lookup for any [PathInfoService]. This represents a flat +/// directory structure like /nix/store where each entry in the root filesystem +/// directory corresponds to a CA node. +#[cfg(any(feature = "fuse", feature = "virtiofs"))] +#[async_trait] +impl<T> RootNodes for RootNodesWrapper<T> +where + T: Deref<Target = dyn PathInfoService> + Send + Sync, +{ + async fn get_by_basename(&self, name: &[u8]) -> Result<Option<castorepb::node::Node>, Error> { + let Ok(store_path) = nix_compat::store_path::StorePath::from_bytes(name) else { + return Ok(None); + }; + + Ok(self + .0 + .deref() + .get(*store_path.digest()) + .await? + .map(|path_info| { + path_info + .node + .expect("missing root node") + .node + .expect("empty node") + })) + } + + fn list(&self) -> Pin<Box<dyn Stream<Item = Result<castorepb::node::Node, Error>> + Send>> { + Box::pin(self.0.deref().list().map(|result| { + result.map(|path_info| { + path_info + .node + .expect("missing root node") + .node + .expect("empty node") + }) + })) + } +} diff --git a/tvix/store/src/fs/tests.rs b/tvix/store/src/pathinfoservice/fs/tests.rs index a3977c727505..d12ee2f2a03e 100644 --- a/tvix/store/src/fs/tests.rs +++ b/tvix/store/src/pathinfoservice/fs/tests.rs @@ -1,22 +1,22 @@ +use crate::pathinfoservice::PathInfoService; +use crate::proto::PathInfo; +use crate::tests::fixtures; +use crate::tests::utils::{gen_blob_service, gen_directory_service, gen_pathinfo_service}; use futures::StreamExt; use std::io::Cursor; use std::os::unix::prelude::MetadataExt; use std::path::Path; use std::sync::Arc; +use tempfile::TempDir; use tokio::{fs, io}; use tokio_stream::wrappers::ReadDirStream; use tvix_castore::blobservice::BlobService; use tvix_castore::directoryservice::DirectoryService; - -use tempfile::TempDir; - -use crate::fs::{fuse::FuseDaemon, TvixStoreFs}; -use crate::pathinfoservice::PathInfoService; -use crate::proto::PathInfo; -use crate::tests::fixtures; -use crate::tests::utils::{gen_blob_service, gen_directory_service, gen_pathinfo_service}; +use tvix_castore::fs::fuse::FuseDaemon; use tvix_castore::proto as castorepb; +use super::make_fs; + const BLOB_A_NAME: &str = "00000000000000000000000000000000-test"; const BLOB_B_NAME: &str = "55555555555555555555555555555555-test"; const HELLOWORLD_BLOB_NAME: &str = "66666666666666666666666666666666-test"; @@ -44,7 +44,7 @@ fn do_mount<P: AsRef<Path>>( mountpoint: P, list_root: bool, ) -> io::Result<FuseDaemon> { - let fs = TvixStoreFs::new( + let fs = make_fs( blob_service, directory_service, path_info_service, diff --git a/tvix/store/src/pathinfoservice/mod.rs b/tvix/store/src/pathinfoservice/mod.rs index 5faa0900a0b0..3bd0ef206998 100644 --- a/tvix/store/src/pathinfoservice/mod.rs +++ b/tvix/store/src/pathinfoservice/mod.rs @@ -4,6 +4,9 @@ mod memory; mod nix_http; mod sled; +#[cfg(any(feature = "fuse", feature = "virtiofs"))] +mod fs; + use futures::Stream; use std::pin::Pin; use tonic::async_trait; @@ -18,6 +21,9 @@ pub use self::memory::MemoryPathInfoService; pub use self::nix_http::NixHTTPPathInfoService; pub use self::sled::SledPathInfoService; +#[cfg(any(feature = "fuse", feature = "virtiofs"))] +pub use self::fs::make_fs; + /// The base trait all PathInfo services need to implement. #[async_trait] pub trait PathInfoService: Send + Sync { |