Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
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"
59 changes: 59 additions & 0 deletions libazureinit-kvp/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use std::fmt;
use std::io;

/// Errors returned by [`KvpStore`](crate::KvpStore) operations.
#[derive(Debug)]
pub enum KvpError {
/// The key was empty.
EmptyKey,
/// The key exceeds the store's maximum key size.
KeyTooLarge { max: usize, actual: usize },
/// The value exceeds the store's maximum value size.
ValueTooLarge { max: usize, actual: usize },
/// The store already has the maximum allowed number of unique keys.
MaxUniqueKeysExceeded { max: usize },
/// The key contains a null byte, which is incompatible with the
/// on-disk format (null-padded fixed-width fields).
KeyContainsNull,
/// An underlying I/O error.
Io(io::Error),
}

impl fmt::Display for KvpError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EmptyKey => write!(f, "KVP key must not be empty"),
Self::KeyTooLarge { max, actual } => {
write!(f, "KVP key length ({actual}) exceeds maximum ({max})")
}
Self::ValueTooLarge { max, actual } => {
write!(f, "KVP value length ({actual}) exceeds maximum ({max})")
}
Self::MaxUniqueKeysExceeded { max } => {
write!(f, "KVP unique key count exceeded maximum ({max})")
}
Self::KeyContainsNull => {
write!(f, "KVP key must not contain null bytes")
}
Self::Io(e) => write!(f, "{e}"),
}
}
}

impl std::error::Error for KvpError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(e) => Some(e),
_ => None,
}
}
}

impl From<io::Error> for KvpError {
fn from(err: io::Error) -> Self {
Self::Io(err)
}
}
15 changes: 15 additions & 0 deletions libazureinit-kvp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! `libazureinit-kvp` provides a storage trait and unified KVP pool
//! implementation for Hyper-V/Azure guests.
//!
//! - [`KvpStore`]: storage interface used by higher layers.
//! - [`KvpPoolStore`]: KVP pool file implementation with
//! [`PoolMode`]-based policy.

mod error;
mod store;

pub use error::KvpError;
pub use store::{KvpPool, KvpPoolStore, KvpStore, PoolMode};
Loading