fuchsia_storage_benchmarks/filesystems/
fxblob.rs1use crate::filesystems::{BlobFilesystem, FsManagementFilesystemInstance};
6use async_trait::async_trait;
7use fidl_fuchsia_fxfs::{BlobCreatorMarker, BlobCreatorProxy, BlobReaderMarker, BlobReaderProxy};
8use fidl_fuchsia_io as fio;
9use fuchsia_component::client::connect_to_protocol_at_dir_svc;
10use std::path::Path;
11use storage_benchmarks::{
12 BlockDeviceConfig, BlockDeviceFactory, CacheClearableFilesystem, Filesystem, FilesystemConfig,
13};
14
15#[derive(Clone)]
17pub struct Fxblob;
18
19#[async_trait]
20impl FilesystemConfig for Fxblob {
21 type Filesystem = FxblobInstance;
22
23 async fn start_filesystem(
24 &self,
25 block_device_factory: &dyn BlockDeviceFactory,
26 ) -> FxblobInstance {
27 let block_device = block_device_factory
28 .create_block_device(&BlockDeviceConfig {
29 requires_fvm: false,
30 use_zxcrypt: false,
31 volume_size: Some(104 * 1024 * 1024),
32 })
33 .await;
34 let fxblob = FsManagementFilesystemInstance::new(
35 fs_management::Fxfs::default,
36 block_device,
37 None,
38 true,
39 )
40 .await;
41 let blob_creator =
42 connect_to_protocol_at_dir_svc::<BlobCreatorMarker>(fxblob.exposed_dir())
43 .expect("failed to connect to the BlobCreator protocol");
44 let blob_reader = connect_to_protocol_at_dir_svc::<BlobReaderMarker>(fxblob.exposed_dir())
45 .expect("failed to connect to the BlobReader protocol");
46 FxblobInstance { blob_creator, blob_reader, fxblob }
47 }
48
49 fn name(&self) -> String {
50 "fxblob".to_owned()
51 }
52}
53
54pub struct FxblobInstance {
55 blob_creator: BlobCreatorProxy,
56 blob_reader: BlobReaderProxy,
57 fxblob: FsManagementFilesystemInstance,
58}
59
60#[async_trait]
61impl Filesystem for FxblobInstance {
62 async fn shutdown(self) {
63 self.fxblob.shutdown().await
64 }
65
66 fn benchmark_dir(&self) -> &Path {
67 self.fxblob.benchmark_dir()
68 }
69}
70
71#[async_trait]
72impl CacheClearableFilesystem for FxblobInstance {
73 async fn clear_cache(&mut self) {
74 let () = self.fxblob.clear_cache().await;
75 self.blob_creator =
76 connect_to_protocol_at_dir_svc::<BlobCreatorMarker>(self.fxblob.exposed_dir())
77 .expect("failed to connect to the BlobCreator protocol");
78 self.blob_reader =
79 connect_to_protocol_at_dir_svc::<BlobReaderMarker>(self.fxblob.exposed_dir())
80 .expect("failed to connect to the BlobReader protocol");
81 }
82}
83
84#[async_trait]
85impl BlobFilesystem for FxblobInstance {
86 fn blob_creator(&self) -> &BlobCreatorProxy {
87 &self.blob_creator
88 }
89
90 fn blob_reader(&self) -> &BlobReaderProxy {
91 &self.blob_reader
92 }
93
94 fn exposed_dir(&self) -> &fio::DirectoryProxy {
95 self.fxblob.exposed_dir()
96 }
97}
98
99#[cfg(test)]
100mod tests {
101 use super::Fxblob;
102 use crate::filesystems::testing::check_blob_filesystem;
103
104 #[fuchsia::test]
105 async fn start_fxblob_new() {
106 check_blob_filesystem(Fxblob).await;
107 }
108}