Skip to main content

opendal_service_hf3fs/
config.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use opendal_core::{Configurator, OperatorUri, Result};
19use serde::{Deserialize, Serialize};
20
21use crate::Hf3fs;
22
23/// Configuration for DeepSeek's 3FS (Fire-Flyer File System) USRBIO access on Linux.
24#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
25#[serde(default)]
26#[non_exhaustive]
27pub struct Hf3fsConfig {
28    /// Existing absolute directory on a mounted DeepSeek 3FS (Fire-Flyer File System) instance. Required.
29    pub root: Option<String>,
30    /// USRBIO shared library path. Defaults to `libhf3fs_api_shared.so`.
31    pub library_path: Option<String>,
32    /// Maximum in-flight requests per read or write ring. Defaults to 32.
33    pub queue_depth: Option<usize>,
34    /// Maximum bytes per request. Defaults to 1 MiB.
35    /// Shared memory usage is approximately `3 * queue_depth * block_size`.
36    pub block_size: Option<usize>,
37}
38
39impl Configurator for Hf3fsConfig {
40    type Builder = Hf3fs;
41
42    fn from_uri(uri: &OperatorUri) -> Result<Self> {
43        let mut options = uri.options().clone();
44        if let Some(root) = uri.root().filter(|v| !v.is_empty()) {
45            options
46                .entry("root".into())
47                .or_insert_with(|| format!("/{root}"));
48        }
49        Self::from_iter(options)
50    }
51
52    fn into_builder(self) -> Self::Builder {
53        Hf3fs { config: self }
54    }
55}