refactor(cli): move zstd status classification into Rust

The zstd compression stream already runs its scheduling and accounting loop in
Rust, but the C callback still owned the result-status switch that selected
success, codec failure, incomplete input, or invalid projection handling. Move
that status-to-diagnostic policy into the Rust ABI module, matching the
existing LZMA and LZ4 diagnostic seams. C keeps the zstd-specific error-name
lookup, display text, and exception construction, so private codec details and
CLI diagnostics remain on the C side and the observable error behavior is
unchanged. Unknown statuses retain the projection-error fallback.

Test Plan:
- `rustfmt +nightly --edition 2021 --check rust/src/fileio_asyncio.rs` -- passed.
- `git diff --check` and `git diff --cached --check` -- passed.
- Capped GCC syntax-only check of `programs/fileio.c` with all CLI format
  feature defines -- passed.
- Cargo, make, native builds, and large tests were not run per worker OOM rules.
This commit is contained in:
2026-07-20 16:20:16 +02:00
parent 2b703ae2a1
commit 81805bf643
2 changed files with 66 additions and 5 deletions
+47
View File
@@ -822,6 +822,25 @@ pub const FIO_RUST_ZSTD_COMPRESS_ERROR: c_int = 1;
pub const FIO_RUST_ZSTD_INCOMPLETE_INPUT: c_int = 2;
pub const FIO_RUST_ZSTD_INVALID_PROJECTION: c_int = 3;
pub const FIO_RUST_ZSTD_DIAGNOSTIC_OK: c_int = 0;
pub const FIO_RUST_ZSTD_DIAGNOSTIC_COMPRESS_ERROR: c_int = 1;
pub const FIO_RUST_ZSTD_DIAGNOSTIC_INCOMPLETE_INPUT: c_int = 2;
pub const FIO_RUST_ZSTD_DIAGNOSTIC_INVALID_PROJECTION: c_int = 3;
pub const FIO_RUST_ZSTD_DIAGNOSTIC_UNKNOWN: c_int = 4;
/// Classifies zstd compression results while leaving zstd-specific error
/// names and CLI exception text in the C callback.
#[no_mangle]
pub extern "C" fn FIO_rust_zstdCompressionDiagnostic(status: c_int) -> c_int {
match status {
FIO_RUST_ZSTD_OK => FIO_RUST_ZSTD_DIAGNOSTIC_OK,
FIO_RUST_ZSTD_COMPRESS_ERROR => FIO_RUST_ZSTD_DIAGNOSTIC_COMPRESS_ERROR,
FIO_RUST_ZSTD_INCOMPLETE_INPUT => FIO_RUST_ZSTD_DIAGNOSTIC_INCOMPLETE_INPUT,
FIO_RUST_ZSTD_INVALID_PROJECTION => FIO_RUST_ZSTD_DIAGNOSTIC_INVALID_PROJECTION,
_ => FIO_RUST_ZSTD_DIAGNOSTIC_UNKNOWN,
}
}
const FIO_RUST_ZSTD_E_CONTINUE: c_int = 0;
const FIO_RUST_ZSTD_E_END: c_int = 2;
const UTIL_FILESIZE_UNKNOWN: u64 = u64::MAX;
@@ -5321,6 +5340,34 @@ mod tests {
}
}
#[test]
fn zstd_compression_status_diagnostic_preserves_cli_mapping() {
for (status, diagnostic) in [
(FIO_RUST_ZSTD_OK, FIO_RUST_ZSTD_DIAGNOSTIC_OK),
(
FIO_RUST_ZSTD_COMPRESS_ERROR,
FIO_RUST_ZSTD_DIAGNOSTIC_COMPRESS_ERROR,
),
(
FIO_RUST_ZSTD_INCOMPLETE_INPUT,
FIO_RUST_ZSTD_DIAGNOSTIC_INCOMPLETE_INPUT,
),
(
FIO_RUST_ZSTD_INVALID_PROJECTION,
FIO_RUST_ZSTD_DIAGNOSTIC_INVALID_PROJECTION,
),
] {
assert_eq!(FIO_rust_zstdCompressionDiagnostic(status), diagnostic);
}
for status in [-1, 99] {
assert_eq!(
FIO_rust_zstdCompressionDiagnostic(status),
FIO_RUST_ZSTD_DIAGNOSTIC_UNKNOWN
);
}
}
const SOURCE_POLICY_STAT: u8 = 1;
const SOURCE_POLICY_EXCLUDED: u8 = 2;
const SOURCE_POLICY_OPEN: u8 = 3;