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:
2026-07-21 18:27:47 +02:00
parent e3ce950f01
commit 67c6056203
2 changed files with 81 additions and 10 deletions
+14 -10
View File
@@ -1701,6 +1701,13 @@ int FIO_rust_compressZstdFrame(
const char* srcFileName, U64 srcFileSize, int compressionLevel,
U64* readsize, U64* compressedSize, size_t* zstdResult);
/* Select the content size to pledge for the next zstd frame. Rust owns the
* source-size precedence policy; C retains the private CCtx call and error
* handling in FIO_rust_compressZstdCallback(). */
U64 FIO_rust_selectPledgedSrcSize(
U64 srcFileSize, U64 streamSrcSize,
U64 unknownSrcFileSize, U64 unknownPledgedSrcSize);
enum {
FIO_RUST_GZIP_OK = 0,
FIO_RUST_GZIP_INIT_ERROR = 1,
@@ -3128,16 +3135,13 @@ FIO_rust_compressZstdCallback(void* fCtx, void* prefs, void* ress,
DISPLAYLEVEL(6, "compression using zstd format \n");
/* Keep pledged-size and memory diagnostics in C while Rust owns the
* surrounding asynchronous stream loop. */
if (srcFileSize != UTIL_FILESIZE_UNKNOWN) {
pledgedSrcSize = srcFileSize;
CHECK(ZSTD_CCtx_setPledgedSrcSize(ressPtr->cctx, srcFileSize));
} else if (prefsPtr->streamSrcSize > 0) {
/* unknown source size; use the declared stream size */
pledgedSrcSize = prefsPtr->streamSrcSize;
CHECK(ZSTD_CCtx_setPledgedSrcSize(ressPtr->cctx, prefsPtr->streamSrcSize));
}
/* Rust selects the source-size precedence. C retains the private CCtx
* operation and its exact diagnostic path. */
pledgedSrcSize = FIO_rust_selectPledgedSrcSize(
srcFileSize, (U64)prefsPtr->streamSrcSize,
UTIL_FILESIZE_UNKNOWN, ZSTD_CONTENTSIZE_UNKNOWN);
if (pledgedSrcSize != ZSTD_CONTENTSIZE_UNKNOWN)
CHECK(ZSTD_CCtx_setPledgedSrcSize(ressPtr->cctx, pledgedSrcSize));
{ int windowLog;
UTIL_HumanReadableSize_t windowSize;