Storage/Crypto: capabilities needed by Forge M05 blob storage #53

Closed
opened 2026-12-03 20:41:35 +00:00 by faumaray · 3 comments
Owner

Context: Forge M05 (content-addressed blob storage) is planned against VoidLibrary main. Four gaps were identified while writing the contract:

  1. Crypto: Hasher state export/import. Void::Crypto::Hasher cannot serialize/restore its state, so resumable uploads cannot resume hashing across requests (v1 plans restart-only).
  2. System: open_file no-follow/exclusive flags. Beyond CreateNew, there is no no-follow/exclusive open; Forge pre-checks symlink_status (race-prone).
  3. System: FilePort free-space query. No API; Forge uses std::filesystem::space.
  4. System: rename_noreplace / hard-link. FilePort lacks an atomic no-replace rename or hard-link; Forge relies on a per-digest lock for identical-content overwrite.

Also: Storage is not yet in Forge's VoidLibrary module list; that is a Forge configuration change, not a library gap.

Expected: native primitives for at least (1) and (2), since both affect correctness/security; (3) and (4) are robustness improvements.

Context: Forge M05 (content-addressed blob storage) is planned against VoidLibrary main. Four gaps were identified while writing the contract: 1. **Crypto: Hasher state export/import.** `Void::Crypto::Hasher` cannot serialize/restore its state, so resumable uploads cannot resume hashing across requests (v1 plans restart-only). 2. **System: `open_file` no-follow/exclusive flags.** Beyond `CreateNew`, there is no no-follow/exclusive open; Forge pre-checks `symlink_status` (race-prone). 3. **System: `FilePort` free-space query.** No API; Forge uses `std::filesystem::space`. 4. **System: `rename_noreplace` / hard-link.** `FilePort` lacks an atomic no-replace rename or hard-link; Forge relies on a per-digest lock for identical-content overwrite. Also: `Storage` is not yet in Forge's VoidLibrary module list; that is a Forge configuration change, not a library gap. Expected: native primitives for at least (1) and (2), since both affect correctness/security; (3) and (4) are robustness improvements.
Author
Owner

Additional M05 detail: FilePort::lock_directory is a non-blocking flock(LOCK_EX|LOCK_NB). Forge M05 needs one exclusive per-upload session lock held across intake and seal; a second acquisition from the same process fails with EWOULDBLOCK. A blocking/reentrant lock option, or documented ownership semantics, would remove the workaround. Also, a bounded list_dir (or prefix iteration) would avoid unbounded vectors on large stores.

Additional M05 detail: `FilePort::lock_directory` is a non-blocking `flock(LOCK_EX|LOCK_NB)`. Forge M05 needs one exclusive per-upload session lock held across intake and seal; a second acquisition from the same process fails with EWOULDBLOCK. A blocking/reentrant lock option, or documented ownership semantics, would remove the workaround. Also, a bounded `list_dir` (or prefix iteration) would avoid unbounded vectors on large stores.
Author
Owner

Partial progress on main (merge 06e5bd5): Void::Storage::FilePort now exposes rename_noreplace() (atomic RENAME_NOREPLACE with a link+unlink fallback), hard_link(), and available_space() (statvfs), implemented by the POSIX port and the fault-injecting proxy, with tests covering no-replace semantics, hard links, free space and O_NOFOLLOW open rejection. Note open_file already applies O_NOFOLLOW and CreateNew is O_CREAT|O_EXCL, so the no-follow/exclusive open request is covered. Remaining from this issue: Crypto Hasher state export/import.

Partial progress on `main` (merge `06e5bd5`): `Void::Storage::FilePort` now exposes `rename_noreplace()` (atomic `RENAME_NOREPLACE` with a link+unlink fallback), `hard_link()`, and `available_space()` (statvfs), implemented by the POSIX port and the fault-injecting proxy, with tests covering no-replace semantics, hard links, free space and `O_NOFOLLOW` open rejection. Note `open_file` already applies `O_NOFOLLOW` and `CreateNew` is `O_CREAT|O_EXCL`, so the no-follow/exclusive open request is covered. Remaining from this issue: Crypto `Hasher` state export/import.
Author
Owner

All four capabilities are now on main: (1) Hasher::export_state()/import_state() for the built-in backend (versioned self-describing state covering SHA-1/256/512 and BLAKE2b-256/512, validated on import with fail-closed rejection of malformed input; the OpenSSL provider returns unsupported_algorithm since it has no portable state export); (2) open_file already applies O_NOFOLLOW and CreateNew is O_CREAT|O_EXCL; (3) FilePort::available_space() (statvfs); (4) FilePort::rename_noreplace() (atomic RENAME_NOREPLACE with link+unlink fallback) and hard_link(). Verified with the Storage and Crypto suites and the full -Werror regression (1920 tests, 1916 passed, 4 skipped). Closing as done.

All four capabilities are now on `main`: (1) `Hasher::export_state()`/`import_state()` for the built-in backend (versioned self-describing state covering SHA-1/256/512 and BLAKE2b-256/512, validated on import with fail-closed rejection of malformed input; the OpenSSL provider returns `unsupported_algorithm` since it has no portable state export); (2) `open_file` already applies `O_NOFOLLOW` and `CreateNew` is `O_CREAT|O_EXCL`; (3) `FilePort::available_space()` (statvfs); (4) `FilePort::rename_noreplace()` (atomic RENAME_NOREPLACE with link+unlink fallback) and `hard_link()`. Verified with the Storage and Crypto suites and the full `-Werror` regression (1920 tests, 1916 passed, 4 skipped). Closing as done.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Void/Library#53