Skip to content

Commit

Permalink
Add statfs implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hagemeier <chagem@amazon.com>
  • Loading branch information
c-hagem committed Nov 8, 2024
1 parent 50433e6 commit 89df80a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
54 changes: 54 additions & 0 deletions mountpoint-s3/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,42 @@ pub struct DirectoryEntry {
lookup: LookedUp,
}

#[derive(Debug)]
/// Reply to a 'statfs' call
pub struct StatFs {
/// Total number of blocks
pub total_blocks: u64,
/// Number of free blocks
pub free_blocks: u64,
/// Number of free blocks available to unprivileged user
pub available_blocks: u64,
/// Number of inodes in file system
pub total_inodes: u64,
/// Available inodes
pub free_inodes: u64,
/// Optimal transfer block size
pub block_size: u32,
/// Maximum name length
pub maximum_name_length: u32,
/// Fragement size
pub fragment_size: u32,
}

impl Default for StatFs {
fn default() -> Self {
Self {
total_blocks: 0,
free_blocks: 0,
available_blocks: 0,
total_inodes: 0,
free_inodes: 0,
block_size: 512,
maximum_name_length: 255,
fragment_size: 0,
}
}
}

impl<Client, Prefetcher> S3Filesystem<Client, Prefetcher>
where
Client: ObjectClient + Clone + Send + Sync + 'static,
Expand Down Expand Up @@ -789,6 +825,24 @@ where
}
Ok(self.superblock.unlink(&self.client, parent_ino, name).await?)
}

pub async fn statfs(&self, _ino: InodeNo) -> Result<StatFs, Error> {
const FREE_BLOCKS: u64 = u64::MAX / 2;
const FREE_INODES: u64 = u64::MAX / 2;
// According to https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html any S3 object name can be at most
// 1024 bytes.
const MAX_NAME_LENGTH: u32 = 1024;

let reply = StatFs {
free_blocks: FREE_BLOCKS,
available_blocks: FREE_BLOCKS,
free_inodes: FREE_INODES,
maximum_name_length: MAX_NAME_LENGTH,
total_blocks: FREE_BLOCKS,
..Default::default()
};
Ok(reply)
}
}

#[cfg(test)]
Expand Down
19 changes: 18 additions & 1 deletion mountpoint-s3/src/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::prefetch::Prefetch;
use fuser::ReplyXTimes;
use fuser::{
Filesystem, KernelConfig, ReplyAttr, ReplyBmap, ReplyCreate, ReplyData, ReplyEmpty, ReplyEntry, ReplyIoctl,
ReplyLock, ReplyLseek, ReplyOpen, ReplyWrite, ReplyXattr, Request, TimeOrNow,
ReplyLock, ReplyLseek, ReplyOpen, ReplyStatfs, ReplyWrite, ReplyXattr, Request, TimeOrNow,
};

pub mod session;
Expand Down Expand Up @@ -580,4 +580,21 @@ where
fn getxtimes(&self, _req: &Request<'_>, ino: u64, reply: ReplyXTimes) {
fuse_unsupported!("getxtimes", reply);
}

#[instrument(level="warn", skip_all, fields(req=_req.unique(), ino=ino))]
fn statfs(&self, _req: &Request<'_>, ino: u64, reply: ReplyStatfs) {
match block_on(self.fs.statfs(ino).in_current_span()) {
Ok(statfs) => reply.statfs(
statfs.total_blocks,
statfs.free_blocks,
statfs.available_blocks,
statfs.total_inodes,
statfs.free_inodes,
statfs.block_size,
statfs.maximum_name_length,
statfs.fragment_size,
),
Err(e) => fuse_error!("statfs", reply, e),
}
}
}

0 comments on commit 89df80a

Please sign in to comment.