feat(cli): move pledged source-size selection to Rust
Move the fileio source-size precedence policy into the Rust backend while keeping the private CCtx pledge call, error handling, and diagnostics in the C adapter. A known statted source size, including zero, remains authoritative; when it is unavailable, a positive declared stream size is used, otherwise the zstd unknown-content sentinel is preserved. The Rust policy accepts both sentinels explicitly so the bridge does not couple their representations. Test Plan: - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo check --manifest-path rust/Cargo.toml --tests - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings - ulimit -v 41943040; CARGO_BUILD_JOBS=1 make -j1 - ulimit -v 41943040; make -j1 -C tests test
This commit is contained in:
@@ -1051,6 +1051,46 @@ const FIO_MMAP_DICT: c_int = 1;
|
||||
const FIO_MMAP_POLICY_ENABLE: c_int = 1;
|
||||
const FIO_MMAP_POLICY_DISABLE: c_int = 2;
|
||||
|
||||
/// Chooses the source size to pledge for a zstd frame.
|
||||
///
|
||||
/// A statted source size has precedence over the user-declared stream size.
|
||||
/// The stream size is useful only when the source size is unknown and is
|
||||
/// positive; otherwise the caller's unknown-content sentinel is preserved.
|
||||
/// The sentinels are parameters so this policy does not assume that the CLI's
|
||||
/// file-size marker and zstd's content-size marker are represented by the
|
||||
/// same constant.
|
||||
#[inline]
|
||||
fn select_pledged_src_size(
|
||||
src_file_size: u64,
|
||||
stream_src_size: u64,
|
||||
unknown_src_file_size: u64,
|
||||
unknown_pledged_src_size: u64,
|
||||
) -> u64 {
|
||||
if src_file_size != unknown_src_file_size {
|
||||
src_file_size
|
||||
} else if stream_src_size > 0 {
|
||||
stream_src_size
|
||||
} else {
|
||||
unknown_pledged_src_size
|
||||
}
|
||||
}
|
||||
|
||||
/// Exposes the CLI source-size precedence policy to its C adapter.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn FIO_rust_selectPledgedSrcSize(
|
||||
src_file_size: u64,
|
||||
stream_src_size: u64,
|
||||
unknown_src_file_size: u64,
|
||||
unknown_pledged_src_size: u64,
|
||||
) -> u64 {
|
||||
select_pledged_src_size(
|
||||
src_file_size,
|
||||
stream_src_size,
|
||||
unknown_src_file_size,
|
||||
unknown_pledged_src_size,
|
||||
)
|
||||
}
|
||||
|
||||
/// Selects the dictionary backing store without performing any filesystem I/O.
|
||||
///
|
||||
/// Explicit mmap enable wins for ordinary dictionaries, patch mode requests a
|
||||
@@ -1170,6 +1210,33 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pledged_source_size_prefers_known_source_then_positive_stream_size() {
|
||||
let unknown_source = u64::MAX;
|
||||
let unknown_pledged = u64::MAX - 1;
|
||||
|
||||
assert_eq!(
|
||||
FIO_rust_selectPledgedSrcSize(123, 456, unknown_source, unknown_pledged),
|
||||
123
|
||||
);
|
||||
assert_eq!(
|
||||
FIO_rust_selectPledgedSrcSize(0, 456, unknown_source, unknown_pledged),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
FIO_rust_selectPledgedSrcSize(unknown_source, 456, unknown_source, unknown_pledged,),
|
||||
456
|
||||
);
|
||||
assert_eq!(
|
||||
FIO_rust_selectPledgedSrcSize(unknown_source, 0, unknown_source, unknown_pledged,),
|
||||
unknown_pledged
|
||||
);
|
||||
assert_eq!(
|
||||
FIO_rust_selectPledgedSrcSize(unknown_source, 456, 123, unknown_pledged),
|
||||
unknown_pledged
|
||||
);
|
||||
}
|
||||
|
||||
fn open_source(path: &Path) -> (c_int, *mut c_void) {
|
||||
let path = c_path(path);
|
||||
let mut stat_buf = MaybeUninit::<libc::stat>::uninit();
|
||||
|
||||
Reference in New Issue
Block a user