Skip to content

Commit a8e63d2

Browse files
committed
propolis-standalone-config needn't be a crate
Since config extraction is not part of `savex` in propolis-utils anymore, the configuration definitions for propolis-standalone do not need to be exposed outside of the binary crate itself.
1 parent 13f8f9d commit a8e63d2

File tree

9 files changed

+96
-135
lines changed

9 files changed

+96
-135
lines changed

Cargo.lock

+1-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ bhyve_api_sys = { path = "crates/bhyve-api/sys" }
4646
cpuid_profile_config = { path = "crates/cpuid-profile-config" }
4747
dladm = { path = "crates/dladm" }
4848
propolis-server-config = { path = "crates/propolis-server-config" }
49-
propolis-standalone-config = { path = "crates/propolis-standalone-config" }
5049
propolis_api_types = { path = "crates/propolis-api-types" }
5150
propolis_types = { path = "crates/propolis-types" }
5251
viona_api = { path = "crates/viona-api" }

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ implementation details, consumed by Propolis components.
3737
- bhyve-api: API (ioctls & structs) for the illumos bhyve kernel VMM
3838
- dladm: Some thin wrappers around `dladm` queries
3939
- propolis-server-config: Type definitions for `propolis-server` config file
40-
- propolis-standalone-config: Type definitions for `propolis-standalone` config file
4140
- propolis-types: Publically exposed (via `propolis-server`) types, intergral
4241
to the `propolis` library
4342
- viona-api: API (ioctls & structs) for the illumos viona driver

bin/propolis-standalone/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tokio = { workspace = true, features = ["io-util", "rt-multi-thread"] }
2525
serde = { workspace = true, features = ["derive"] }
2626
propolis.workspace = true
2727
crucible-client-types = { workspace = true, optional = true }
28-
propolis-standalone-config = { workspace = true }
28+
cpuid_profile_config.workspace = true
2929
erased-serde.workspace = true
3030
serde_json.workspace = true
3131
slog.workspace = true

bin/propolis-standalone/src/cidata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use std::sync::Arc;
77

88
use anyhow::{bail, Context};
99
use fatfs::{FileSystem, FormatVolumeOptions, FsOptions};
10-
1110
use propolis::block;
12-
use propolis_standalone_config::Config;
11+
12+
use crate::config::Config;
1313

1414
const SECTOR_SZ: usize = 512;
1515
const VOLUME_LABEL: [u8; 11] = *b"cidata ";

bin/propolis-standalone/src/config.rs

+92-7
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,101 @@ use std::str::FromStr;
99
use std::sync::Arc;
1010

1111
use anyhow::Context;
12-
use serde::Deserialize;
12+
use serde::{Deserialize, Serialize};
1313

14+
use cpuid_profile_config::*;
1415
use propolis::block;
1516
use propolis::cpuid;
1617
use propolis::hw::pci::Bdf;
1718
use propolis::inventory::ChildRegister;
1819

1920
use crate::cidata::build_cidata_be;
20-
pub use propolis_standalone_config::Config;
21-
use propolis_standalone_config::{CpuVendor, CpuidEntry, Device};
21+
22+
#[derive(Clone, Debug, Deserialize, Serialize)]
23+
pub struct Config {
24+
pub main: Main,
25+
26+
#[serde(default, rename = "dev")]
27+
pub devices: BTreeMap<String, Device>,
28+
29+
#[serde(default, rename = "block_dev")]
30+
pub block_devs: BTreeMap<String, BlockDevice>,
31+
32+
#[serde(default, rename = "cpuid")]
33+
pub cpuid_profiles: BTreeMap<String, CpuidProfile>,
34+
35+
pub cloudinit: Option<CloudInit>,
36+
}
37+
impl Config {
38+
pub fn cpuid_profile(&self) -> Option<&CpuidProfile> {
39+
match self.main.cpuid_profile.as_ref() {
40+
Some(name) => self.cpuid_profiles.get(name),
41+
None => None,
42+
}
43+
}
44+
}
45+
46+
#[derive(Clone, Debug, Deserialize, Serialize)]
47+
pub struct Main {
48+
pub name: String,
49+
pub cpus: u8,
50+
pub bootrom: String,
51+
pub memory: usize,
52+
pub use_reservoir: Option<bool>,
53+
pub cpuid_profile: Option<String>,
54+
/// Process exitcode to emit if/when instance halts
55+
///
56+
/// Default: 0
57+
#[serde(default)]
58+
pub exit_on_halt: u8,
59+
/// Process exitcode to emit if/when instance reboots
60+
///
61+
/// Default: None, does not exit on reboot
62+
#[serde(default)]
63+
pub exit_on_reboot: Option<u8>,
64+
}
65+
66+
/// A hard-coded device, either enabled by default or accessible locally
67+
/// on a machine.
68+
#[derive(Clone, Debug, Deserialize, Serialize)]
69+
pub struct Device {
70+
pub driver: String,
71+
72+
#[serde(flatten, default)]
73+
pub options: BTreeMap<String, toml::Value>,
74+
}
75+
76+
#[derive(Clone, Debug, Deserialize, Serialize)]
77+
pub struct BlockOpts {
78+
pub block_size: Option<u32>,
79+
pub read_only: Option<bool>,
80+
pub skip_flush: Option<bool>,
81+
}
82+
83+
#[derive(Clone, Debug, Deserialize, Serialize)]
84+
pub struct BlockDevice {
85+
#[serde(default, rename = "type")]
86+
pub bdtype: String,
87+
88+
#[serde(flatten)]
89+
pub block_opts: BlockOpts,
90+
91+
#[serde(flatten, default)]
92+
pub options: BTreeMap<String, toml::Value>,
93+
}
94+
95+
#[derive(Clone, Debug, Deserialize, Serialize)]
96+
#[serde(rename_all = "kebab-case")]
97+
pub struct CloudInit {
98+
pub user_data: Option<String>,
99+
pub meta_data: Option<String>,
100+
pub network_config: Option<String>,
101+
102+
// allow path-style contents as well
103+
pub user_data_path: Option<String>,
104+
pub meta_data_path: Option<String>,
105+
pub network_config_path: Option<String>,
106+
}
22107

23108
#[derive(Deserialize)]
24109
struct FileConfig {
@@ -165,7 +250,7 @@ pub fn parse_cpuid(config: &Config) -> anyhow::Result<Option<cpuid::Set>> {
165250

166251
#[cfg(feature = "crucible")]
167252
fn create_crucible_backend(
168-
be: &propolis_standalone_config::BlockDevice,
253+
be: &BlockDevice,
169254
opts: block::BackendOpts,
170255
log: &slog::Logger,
171256
) -> (Arc<dyn block::Backend>, ChildRegister) {
@@ -259,7 +344,7 @@ fn create_crucible_backend(
259344

260345
#[cfg(feature = "crucible")]
261346
fn create_crucible_mem_backend(
262-
be: &propolis_standalone_config::BlockDevice,
347+
be: &BlockDevice,
263348
opts: block::BackendOpts,
264349
log: &slog::Logger,
265350
) -> (Arc<dyn block::Backend>, ChildRegister) {
@@ -278,7 +363,7 @@ fn create_crucible_mem_backend(
278363

279364
#[cfg(not(feature = "crucible"))]
280365
fn create_crucible_backend(
281-
_be: &propolis_standalone_config::BlockDevice,
366+
_be: &BlockDevice,
282367
_opts: block::BackendOpts,
283368
_log: &slog::Logger,
284369
) -> (Arc<dyn block::Backend>, ChildRegister) {
@@ -290,7 +375,7 @@ fn create_crucible_backend(
290375

291376
#[cfg(not(feature = "crucible"))]
292377
fn create_crucible_mem_backend(
293-
_be: &propolis_standalone_config::BlockDevice,
378+
_be: &BlockDevice,
294379
_opts: block::BackendOpts,
295380
_log: &slog::Logger,
296381
) -> (Arc<dyn block::Backend>, ChildRegister) {

bin/propolis-utils/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ propolis = { workspace = true, default-features = false }
2222
bhyve_api = { workspace = true }
2323
libc = { workspace = true }
2424
serde_json.workspace = true
25-
propolis-standalone-config = { workspace = true }

crates/propolis-standalone-config/Cargo.toml

-15
This file was deleted.

crates/propolis-standalone-config/src/lib.rs

-95
This file was deleted.

0 commit comments

Comments
 (0)