feat(kvp): add store trait and Hyper-V KVP storage crate#288
feat(kvp): add store trait and Hyper-V KVP storage crate#288peytonr18 wants to merge 7 commits intoAzure:mainfrom
Conversation
b134a98 to
f435f70
Compare
libazureinit-kvp/src/lib.rs
Outdated
| pub const HYPERV_MAX_VALUE_BYTES: usize = 2048; | ||
| /// Azure key limit in bytes (policy/default preset). | ||
| pub const AZURE_MAX_KEY_BYTES: usize = 512; | ||
| /// Azure value limit in bytes (UTF-16: 511 characters + null terminator). |
There was a problem hiding this comment.
Do you have a reference for the null termination of this? I opened up that link in the previous file, but did not see a reference to null termination
There was a problem hiding this comment.
I was basing this off of what we have in our existing kvp.rs --
const HV_KVP_EXCHANGE_MAX_KEY_SIZE: usize = 512;
const HV_KVP_EXCHANGE_MAX_VALUE_SIZE: usize = 2048;
const HV_KVP_AZURE_MAX_VALUE_SIZE: usize = 1022;
and my old notes from that KVP process, but I'll look for the official documentation where it says that!
There was a problem hiding this comment.
Pull request overview
Adds a new standalone workspace crate (libazureinit-kvp) that defines a storage abstraction (KvpStore) and a production Hyper-V pool-file implementation (HyperVKvpStore), along with updated technical reference documentation.
Changes:
- Introduces
libazureinit-kvpcrate withKvpStoreandKvpLimits(Hyper-V/Azure presets). - Implements Hyper-V binary pool-file backend with flock-based concurrency and stale-file truncation support.
- Rewrites
doc/libazurekvp.mdas a technical reference for the new crate/API.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
Cargo.toml |
Adds libazureinit-kvp to the workspace members. |
libazureinit-kvp/Cargo.toml |
Defines the new crate and its dependencies (fs2, sysinfo). |
libazureinit-kvp/src/lib.rs |
Defines KvpStore, KvpLimits, and exports HyperVKvpStore plus size constants. |
libazureinit-kvp/src/hyperv.rs |
Implements Hyper-V pool-file encoding/decoding and the KvpStore backend, plus unit tests. |
doc/libazurekvp.md |
Updates documentation to describe the new crate’s record format, semantics, truncation behavior, and limits. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ation; add PoolMode to handle size limits
Summary
libazureinit-kvpin rootCargo.tomllibazureinit-kvp/Cargo.tomllibazureinit-kvp/src/lib.rsandlibazureinit-kvp/src/kvp_pool.rsCrate Design
KvpStoreKvpPoolStoreKvpStoresplits each operation into abackend_*method (raw I/O,provided by the implementor) and a public method (
write,read,clear) that validates inputs then delegates to the backend.Public API:
write,read(validate then delegate tobackend_write/backend_read)entries,entries_rawdelete,clearis_staleValidation is centralized in trait default methods and policy-aware via:
max_key_size(&self)max_value_size(&self)KvpPoolStoreis file-backed using Hyper-V KVP wire format(fixed-size 512-byte key + 2048-byte value records), with lock-based concurrency.
Policy and Limits
Constructor:
new(path: Option<PathBuf>, mode: PoolMode, truncate_on_stale: bool)PoolMode:Restricted(default): key <= 254 bytes, value <= 1022 bytesFull: key <= 512 bytes, value <= 2048 bytesBehavior:
None:/var/lib/hyperv/.kvp_pool_1clear()truncates the storetruncate_on_stalekeeps truncation caller-controlledErrors
KvpErrorincludes explicit variants:EmptyKeyKeyContainsNullKeyTooLarge { max, actual }ValueTooLarge { max, actual }MaxUniqueKeysExceeded { max }Io(io::Error)Testing
17 tests covering:
entrieslast-write-wins andentries_rawduplicate preservationdelete,clear, and stale checks