Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ path = "tests/functional_tests.rs"
[workspace]
members = [
"libazureinit",
"libazureinit-kvp",
]

[features]
Expand Down
74 changes: 74 additions & 0 deletions doc/kvp_pr_description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# PR: Add `libazureinit-kvp` with unified KVP pool store
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file seems out of date - is it going to be deleted?


## Summary

- Adds workspace member `libazureinit-kvp` in root `Cargo.toml`
- Adds `libazureinit-kvp/Cargo.toml`
- Adds `libazureinit-kvp/src/lib.rs` and `libazureinit-kvp/src/kvp_pool.rs`

## Crate Design

- One trait: `KvpStore`
- One implementation: `KvpPoolStore`

`KvpStore` splits each operation into a `backend_*` 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 to `backend_write`/`backend_read`)
- `entries`, `entries_raw`
- `delete`, `clear`
- `is_stale`

Validation is centralized in trait default methods and policy-aware via:

- `max_key_size(&self)`
- `max_value_size(&self)`

`KvpPoolStore` is 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 bytes
- `Full`: key <= 512 bytes, value <= 2048 bytes

Behavior:

- Default path when `None`: `/var/lib/hyperv/.kvp_pool_1`
- Unique key cap: 1024
- new key beyond cap is rejected
- overwrite of existing key at cap is allowed
- `clear()` truncates the store
- `truncate_on_stale` keeps truncation caller-controlled

## Errors

`KvpError` includes explicit variants:

- `EmptyKey`
- `KeyContainsNull`
- `KeyTooLarge { max, actual }`
- `ValueTooLarge { max, actual }`
- `MaxUniqueKeysExceeded { max }`
- `Io(io::Error)`

## Testing

17 tests covering:

- restricted/full key/value boundary checks
- default and explicit path behavior
- mode getter
- unique-key cap behavior (including overwrite-at-cap and add-after-delete)
- `entries` last-write-wins and `entries_raw` duplicate preservation
- `delete`, `clear`, and stale checks
- key validation (empty and null-byte)
126 changes: 0 additions & 126 deletions doc/libazurekvp.md

This file was deleted.

22 changes: 22 additions & 0 deletions libazureinit-kvp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "libazureinit-kvp"
version = "0.1.0"
edition = "2021"
rust-version = "1.88"
repository = "https://github.com/Azure/azure-init/"
homepage = "https://github.com/Azure/azure-init/"
license = "MIT"
description = "Hyper-V KVP (Key-Value Pair) storage library for azure-init."

[dependencies]
libc = "0.2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sysinfo = "0.38"

[dev-dependencies]
tempfile = "3"

[lib]
name = "libazureinit_kvp"
path = "src/lib.rs"
Loading