-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement statfs with synthetic values (#1118)
## Description of change This PR adds support for calling `statfs` on virtual file system created using mountpoint. Some applications depend on the filesystem reporting non-zero available space; currently mountpoint reports 0 as number of available blocks, which can cause these applications to not work as expected. This PR (building on #871) implements statfs with synthetic values (4611686018427387904 free blocks). For example, the DF output now is: ``` mountpoint-s3 4611686018427387904 0 4611686018427387904 0% /local/home/chagem/mnt/bucket ``` Thus, checks for available space should no longer fail. Relevant issues: #710. ### Does this change impact existing behavior? This change impacts existing behaviour, as Mountpoint will report non-zero value for total blocks, free blocks, free inodes and maximum file name length. ### Does this change need a changelog entry? Yes, addressed. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I agree to the terms of the [Developer Certificate of Origin (DCO)](https://developercertificate.org/). --------- Signed-off-by: Christian Hagemeier <chagem@amazon.com>
- Loading branch information
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::common::fuse::{self, TestSessionCreator}; | ||
use test_case::test_case; | ||
|
||
/// Tests that static values we set are reported correctly. | ||
fn statfs_test_static_values(creator_fn: impl TestSessionCreator, prefix: &str) { | ||
let test_session = creator_fn(prefix, Default::default()); | ||
let mount_dir = test_session.mount_path(); | ||
let stats = nix::sys::statvfs::statvfs(mount_dir).unwrap(); | ||
// Asserts that we report free space, we don't care about actual values here | ||
assert_ne!(stats.blocks(), 0); | ||
assert_ne!(stats.blocks_free(), 0); | ||
assert_ne!(stats.blocks_available(), 0); | ||
// These two are values set by us | ||
assert_eq!(stats.files(), u64::MAX / 1024); | ||
assert_eq!(stats.files_available(), u64::MAX / 1024); | ||
// These are default values from the Default implementation | ||
assert_eq!(stats.block_size(), 512); | ||
assert_eq!(stats.name_max(), 255); | ||
// This may be a bit surprising, however as we set fsize to 0, | ||
// it will be automatically set to the block_size, if it is not available | ||
// c.f. https://stackoverflow.com/questions/54823541/what-do-f-bsize-and-f-frsize-in-struct-statvfs-stand-for | ||
assert_eq!(stats.fragment_size(), 512); | ||
} | ||
|
||
/// Test that total blocks >= blocks_free, | ||
/// as some tools rely on calculations with these values to determine percentage of blocks available | ||
fn statfs_test_block_arithmetic(creator_fn: impl TestSessionCreator, prefix: &str) { | ||
let test_session = creator_fn(prefix, Default::default()); | ||
let mount_dir = test_session.mount_path(); | ||
let stats = nix::sys::statvfs::statvfs(mount_dir).unwrap(); | ||
assert!(stats.blocks() >= stats.blocks_available()); | ||
} | ||
|
||
#[test_case(""; "no prefix")] | ||
#[test_case("statfs_static_values_test"; "prefix")] | ||
fn statfs_report_static_values_mock(prefix: &str) { | ||
statfs_test_static_values(fuse::mock_session::new, prefix); | ||
} | ||
|
||
#[cfg(feature = "s3_tests")] | ||
#[test_case(""; "no prefix")] | ||
#[test_case("statfs_static_values_test"; "prefix")] | ||
fn statfs_report_static_values_s3(prefix: &str) { | ||
statfs_test_static_values(fuse::s3_session::new, prefix); | ||
} | ||
|
||
#[test_case(""; "no prefix")] | ||
#[test_case("statfs_block_arithmetic_test"; "prefix")] | ||
fn statfs_block_arithmetic_mock(prefix: &str) { | ||
statfs_test_block_arithmetic(fuse::mock_session::new, prefix); | ||
} | ||
|
||
#[cfg(feature = "s3_tests")] | ||
#[test_case(""; "no prefix")] | ||
#[test_case("statfs_block_arithmetic_test"; "prefix")] | ||
fn statfs_block_arithmetic_s3(prefix: &str) { | ||
statfs_test_block_arithmetic(fuse::s3_session::new, prefix); | ||
} |