Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set max_background FUSE config to 64 by default. #1137

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions mountpoint-s3/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,58 @@ where
self.next_handle.fetch_add(1, Ordering::SeqCst)
}

/// Helper to return the u16 value in an environment variable, or panic. Useful for unstable overrides.
fn parse_env_var_to_u16(var_name: &str, var_value: std::ffi::OsString) -> u16 {
var_value.to_string_lossy().parse::<u16>().unwrap_or_else(|_| {
panic!(
"Invalid value for environment variable {}. Must be positive integer.",
var_name
)
})
}

pub async fn init(&self, config: &mut KernelConfig) -> Result<(), libc::c_int> {
const ENV_VAR_KEY_MAX_BACKGROUND: &str = "UNSTABLE_MOUNTPOINT_MAX_BACKGROUND";
const ENV_VAR_KEY_CONGESTION_THRESHOLD: &str = "UNSTABLE_MOUNTPOINT_CONGESTION_THRESHOLD";
let _ = config.add_capabilities(fuser::consts::FUSE_DO_READDIRPLUS);
// Set max_background FUSE parameter to 64 by default, or override with environment variable.
// NOTE: Support for this environment variable may be removed in future without notice.
if let Some(user_max_background) = std::env::var_os(ENV_VAR_KEY_MAX_BACKGROUND) {
let max_background = Self::parse_env_var_to_u16(ENV_VAR_KEY_MAX_BACKGROUND, user_max_background);
let old = config
.set_max_background(max_background)
.unwrap_or_else(|_| panic!("Unable to set FUSE max_background configuration to {}", max_background));
tracing::warn!(
"Successfully overridden FUSE max_background configuration to {} (was {}) from unstable environment variable.",
max_background,
old
);
} else {
const DEFAULT_MAX_BACKGROUND: u16 = 64;
let max_background_result = config.set_max_background(DEFAULT_MAX_BACKGROUND);
if max_background_result.is_err() {
tracing::warn!(
"failed to set FUSE max_background to {}, using Kernel default",
DEFAULT_MAX_BACKGROUND
);
}
}

// Override FUSE congestion threshold if environment variable is present.
// NOTE: Support for this environment variable may be removed in future without notice.
if let Some(user_congestion_threshold) = std::env::var_os(ENV_VAR_KEY_CONGESTION_THRESHOLD) {
let congestion_threshold =
Self::parse_env_var_to_u16(ENV_VAR_KEY_CONGESTION_THRESHOLD, user_congestion_threshold);
let old = config
.set_congestion_threshold(congestion_threshold)
.unwrap_or_else(|_| panic!("unable to set FUSE congestion_threshold to {}", congestion_threshold));
tracing::warn!(
"Successfully overridden FUSE congestion_threshold configuration to {} (was {}) from unstable environment variable.",
congestion_threshold,
old
);
}

if self.config.allow_overwrite {
// Overwrites require FUSE_ATOMIC_O_TRUNC capability on the host, so we will panic if the
// host doesn't support it.
Expand Down
Loading