Skip to content

Commit 9fd40a0

Browse files
committed
Use multi-threaded FuseSession in tests
Signed-off-by: Alessandro Passaro <[email protected]>
1 parent dcbbcc1 commit 9fd40a0

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

mountpoint-s3-fs/src/fuse/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct FuseSession {
2424
on_close: Vec<OnClose>,
2525
}
2626

27-
type OnClose = Box<dyn FnOnce()>;
27+
type OnClose = Box<dyn FnOnce() + Send>;
2828

2929
impl FuseSession {
3030
/// Create a new multi-threaded FUSE session.
@@ -47,7 +47,7 @@ impl FuseSession {
4747
}
4848

4949
/// Create worker threads to dispatch requests for a FUSE session.
50-
fn from_session<FS: Filesystem + Send + Sync + 'static>(
50+
pub fn from_session<FS: Filesystem + Send + Sync + 'static>(
5151
mut session: Session<FS>,
5252
max_worker_threads: usize,
5353
) -> anyhow::Result<Self> {

mountpoint-s3-fs/tests/common/fuse.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use std::os::fd::{AsFd, AsRawFd};
44
use std::path::Path;
55
use std::sync::Arc;
66

7-
use fuser::{BackgroundSession, Mount, MountOption, Session};
7+
use fuser::{Mount, MountOption, Session};
88
use mountpoint_s3_client::ObjectClient;
99
use mountpoint_s3_client::checksums::crc32c;
1010
use mountpoint_s3_client::config::S3ClientAuthConfig;
1111
use mountpoint_s3_client::types::{Checksum, PutObjectSingleParams, UploadChecksum};
1212
use mountpoint_s3_fs::data_cache::DataCache;
13+
use mountpoint_s3_fs::fuse::session::FuseSession;
1314
use mountpoint_s3_fs::fuse::{ErrorLogger, S3FuseFilesystem};
1415
#[cfg(feature = "manifest")]
1516
use mountpoint_s3_fs::manifest::{Manifest, ManifestMetablock};
@@ -68,6 +69,7 @@ pub struct TestSessionConfig {
6869
// If true, the test session will be created by opening and passing
6970
// FUSE device using `Session::from_fd`, otherwise `Session::new` will be used.
7071
pub pass_fuse_fd: bool,
72+
pub max_worker_threads: usize,
7173
pub error_logger: Option<Box<dyn ErrorLogger + Send + Sync>>,
7274
pub cache_block_size: usize,
7375
#[cfg(feature = "manifest")]
@@ -84,6 +86,7 @@ impl Default for TestSessionConfig {
8486
filesystem_config: Default::default(),
8587
auth_config: Default::default(),
8688
pass_fuse_fd: false,
89+
max_worker_threads: 16,
8790
error_logger: None,
8891
cache_block_size,
8992
#[cfg(feature = "manifest")]
@@ -110,15 +113,15 @@ pub struct TestSession {
110113
test_client: Box<dyn TestClient>,
111114
prefix: String,
112115
// Option so we can explicitly unmount
113-
session: Option<BackgroundSession>,
116+
session: Option<FuseSession>,
114117
// Only set if `pass_fuse_fd` is true, will unmount the filesystem on drop.
115118
mount: Option<Mount>,
116119
}
117120

118121
impl TestSession {
119122
pub fn new(
120123
mount_dir: TempDir,
121-
session: BackgroundSession,
124+
session: FuseSession,
122125
test_client: impl TestClient + 'static,
123126
prefix: String,
124127
mount: Option<Mount>,
@@ -150,8 +153,13 @@ impl Drop for TestSession {
150153
// If the session created with a pre-existing mount (e.g., with `pass_fuse_fd`),
151154
// this will unmount it explicitly...
152155
drop(self.mount.take());
153-
// ...if not, the background session will have a mount here, and dropping it will unmount it.
154-
self.session.take();
156+
// ...if not, the fuse session will unmount on shutdown.
157+
if let Some(session) = self.session.take() {
158+
session.shutdown_fn()();
159+
if let Err(error) = session.join() {
160+
tracing::warn!(?error, "error while unmounting");
161+
}
162+
}
155163
}
156164
}
157165

@@ -213,7 +221,7 @@ pub fn create_fuse_session<Client>(
213221
s3_path: S3Path,
214222
mount_dir: &Path,
215223
test_config: TestSessionConfig,
216-
) -> (BackgroundSession, Option<Mount>)
224+
) -> (FuseSession, Option<Mount>)
217225
where
218226
Client: ObjectClient + Clone + Send + Sync + 'static,
219227
{
@@ -245,7 +253,10 @@ where
245253
(Session::new(fs, mount_dir, &options).unwrap(), None)
246254
};
247255

248-
(BackgroundSession::new(session).unwrap(), mount)
256+
(
257+
FuseSession::from_session(session, test_config.max_worker_threads).unwrap(),
258+
mount,
259+
)
249260
}
250261

251262
/// Open `/dev/fuse` and call `mount` syscall with given `mount_point`.

mountpoint-s3-fs/tests/fuse_tests/cache_test.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use crate::common::s3::{get_test_prefix, get_test_s3_path};
66
use mountpoint_s3_client::S3CrtClient;
77
use mountpoint_s3_fs::Runtime;
88
use mountpoint_s3_fs::data_cache::{DataCache, DiskDataCache, DiskDataCacheConfig};
9+
use mountpoint_s3_fs::fuse::session::FuseSession;
910
use mountpoint_s3_fs::memory::PagedPool;
1011
use mountpoint_s3_fs::object::ObjectId;
1112
use mountpoint_s3_fs::prefetch::Prefetcher;
1213
use mountpoint_s3_fs::s3::S3Path;
1314

14-
use fuser::BackgroundSession;
1515
use rand::{Rng, RngCore, SeedableRng};
1616
use rand_chacha::ChaChaRng;
1717
use std::fs;
@@ -409,12 +409,7 @@ fn get_random_key(key_prefix: &str, key_suffix: &str, min_size_in_bytes: usize)
409409
format!("{last_key_part}{padding}")
410410
}
411411

412-
fn mount_bucket<Cache>(
413-
client: S3CrtClient,
414-
cache: Cache,
415-
pool: PagedPool,
416-
s3_path: S3Path,
417-
) -> (TempDir, BackgroundSession)
412+
fn mount_bucket<Cache>(client: S3CrtClient, cache: Cache, pool: PagedPool, s3_path: S3Path) -> (TempDir, FuseSession)
418413
where
419414
Cache: DataCache + Send + Sync + 'static,
420415
{

mountpoint-s3-fs/tests/fuse_tests/write_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ fn overwrite_truncate_test(creator_fn: impl TestSessionCreator, prefix: &str, rw
10891089
};
10901090
let test_config = TestSessionConfig {
10911091
filesystem_config,
1092+
max_worker_threads: 1, // avoid concurrency issues with read after write.
10921093
..Default::default()
10931094
};
10941095
let test_session = creator_fn(prefix, test_config);

0 commit comments

Comments
 (0)