Skip to content
Draft
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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ schemars = "0.8.10"
semver = "1.0"
serde = "1.0"
serde_arrays = "0.1"
serde_human_bytes = { git = "https://github.com/oxidecomputer/serde_human_bytes", branch = "main", features = ["schemars08"] }
serde_derive = "1.0"
serde_json = "1.0"
serde_test = "1.0.138"
Expand Down
1 change: 1 addition & 0 deletions bin/mock-server/src/lib/api_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ progenitor::generate_api!(
spec = "../../openapi/propolis-server/propolis-server-latest.json",
derives = [schemars::JsonSchema],
replace = {
NvmeDisk = propolis_api_types_versions::latest::components::devices::NvmeDisk,
SpecKey = propolis_api_types_versions::latest::instance_spec::SpecKey,
},
patch = {
Expand Down
20 changes: 13 additions & 7 deletions bin/propolis-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fn add_component_to_spec(
use std::collections::btree_map::Entry;
match spec.components.entry(id) {
Entry::Vacant(vacant_entry) => {
vacant_entry.insert(component);
vacant_entry.insert(component.into());
Ok(())
}
Entry::Occupied(occupied_entry) => Err(anyhow::anyhow!(
Expand Down Expand Up @@ -259,11 +259,16 @@ impl DiskRequest {
backend_id: backend_id.clone(),
pci_path,
}),
"nvme" => ComponentV0::NvmeDisk(NvmeDisk {
backend_id: backend_id.clone(),
pci_path,
serial_number: nvme_serial_from_str(&self.name, b' '),
}),
"nvme" => {
let nvme = NvmeDisk {
backend_id: backend_id.clone(),
pci_path,
serial_number: nvme_serial_from_str(&self.name, b' '),
// TODO: populate model_number
model_number: [0u8; 40],
};
ComponentV0::NvmeDisk(nvme.into())
}
_ => anyhow::bail!(
"invalid device type in disk request: {:?}",
self.device
Expand Down Expand Up @@ -420,10 +425,11 @@ impl VmConfig {
}

// If there are no SoftNPU devices, also enable COM4.
use propolis_client::instance_spec::Component;
if !spec
.components
.iter()
.any(|(_, c)| matches!(c, ComponentV0::SoftNpuPort(_)))
.any(|(_, c)| matches!(c, Component::SoftNpuPort(_)))
{
add_component_to_spec(
&mut spec,
Expand Down
10 changes: 8 additions & 2 deletions bin/propolis-server/src/lib/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ impl From<Spec> for InstanceSpec {
let smbios = val.smbios_type1_input.clone();
let v1::instance_spec::InstanceSpec { board, components } =
v1::instance_spec::InstanceSpec::from(val);
let components =
components.into_iter().map(|(k, v)| (k, v.into())).collect();
InstanceSpec { board, components, smbios }
}
}
Expand All @@ -65,6 +67,8 @@ impl TryFrom<InstanceSpec> for Spec {

fn try_from(value: InstanceSpec) -> Result<Self, Self::Error> {
let InstanceSpec { board, components, smbios } = value;
let components =
components.into_iter().map(|(k, v)| (k, v.into())).collect();
let v0 = v1::instance_spec::InstanceSpec { board, components };
let mut spec: Spec = v0.try_into()?;
spec.smbios_type1_input = smbios;
Expand Down Expand Up @@ -207,7 +211,7 @@ impl From<StorageDevice> for v1::instance_spec::Component {
fn from(value: StorageDevice) -> Self {
match value {
StorageDevice::Virtio(d) => Self::VirtioDisk(d),
StorageDevice::Nvme(d) => Self::NvmeDisk(d),
StorageDevice::Nvme(d) => Self::NvmeDisk(d.into()),
}
}
}
Expand All @@ -220,7 +224,9 @@ impl TryFrom<v1::instance_spec::Component> for StorageDevice {
) -> Result<Self, Self::Error> {
match value {
v1::instance_spec::Component::VirtioDisk(d) => Ok(Self::Virtio(d)),
v1::instance_spec::Component::NvmeDisk(d) => Ok(Self::Nvme(d)),
v1::instance_spec::Component::NvmeDisk(d) => {
Ok(Self::Nvme(d.into()))
}
_ => Err(ComponentTypeMismatch),
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/propolis-api-types-versions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ crucible-client-types.workspace = true
propolis_types.workspace = true
schemars.workspace = true
serde.workspace = true
serde_human_bytes.workspace = true
thiserror.workspace = true
uuid.workspace = true

Expand Down
16 changes: 9 additions & 7 deletions crates/propolis-api-types-versions/src/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub mod components {
pub use crate::v1::components::devices::BootOrderEntry;
pub use crate::v1::components::devices::BootSettings;
pub use crate::v1::components::devices::MigrationFailureInjector;
pub use crate::v1::components::devices::NvmeDisk;
pub use crate::v1::components::devices::P9fs;
pub use crate::v1::components::devices::PciPciBridge;
pub use crate::v1::components::devices::QemuPvpanic;
Expand All @@ -41,6 +40,8 @@ pub mod components {
pub use crate::v1::components::devices::SoftNpuPort;
pub use crate::v1::components::devices::VirtioDisk;
pub use crate::v1::components::devices::VirtioNic;

pub use crate::v3::components::devices::NvmeDisk;
}
}

Expand Down Expand Up @@ -68,23 +69,24 @@ pub mod instance {
pub use crate::v1::instance::InstanceStateRequested;
pub use crate::v1::instance::ReplacementComponent;

pub use crate::v2::api::InstanceEnsureRequest;
pub use crate::v2::api::InstanceInitializationMethod;
pub use crate::v3::api::InstanceEnsureRequest;
pub use crate::v3::api::InstanceInitializationMethod;
}

pub mod instance_spec {
pub use crate::v1::instance_spec::Component;
pub use crate::v1::instance_spec::CpuidIdent;
pub use crate::v1::instance_spec::CpuidValues;
pub use crate::v1::instance_spec::CpuidVendor;
pub use crate::v1::instance_spec::PciPath;
pub use crate::v1::instance_spec::SpecKey;
pub use crate::v1::instance_spec::VersionedInstanceSpec;

pub use crate::v2::instance_spec::InstanceSpec;
pub use crate::v2::instance_spec::InstanceSpecGetResponse;
pub use crate::v2::instance_spec::InstanceSpecStatus;
pub use crate::v2::instance_spec::SmbiosType1Input;

pub use crate::v3::instance_spec::Component;
pub use crate::v3::instance_spec::InstanceSpec;
pub use crate::v3::instance_spec::InstanceSpecGetResponse;
pub use crate::v3::instance_spec::InstanceSpecStatus;
}

pub mod migration {
Expand Down
2 changes: 2 additions & 0 deletions crates/propolis-api-types-versions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ pub mod latest;
pub mod v1;
#[path = "programmable_smbios/mod.rs"]
pub mod v2;
#[path = "nvme_model_number/mod.rs"]
pub mod v3;
62 changes: 62 additions & 0 deletions crates/propolis-api-types-versions/src/nvme_model_number/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! API request and response types for the NVME_MODEL_NUMBER API version.

use std::{collections::BTreeMap, net::SocketAddr};

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::instance_spec::InstanceSpec;
use crate::v1::instance::{InstanceProperties, ReplacementComponent};
use crate::v1::instance_spec::SpecKey;
use crate::v2;

#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "method", content = "value")]
pub enum InstanceInitializationMethod {
Spec {
spec: InstanceSpec,
},
MigrationTarget {
migration_id: Uuid,
src_addr: SocketAddr,
replace_components: BTreeMap<SpecKey, ReplacementComponent>,
},
}

#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct InstanceEnsureRequest {
pub properties: InstanceProperties,
pub init: InstanceInitializationMethod,
}

impl From<v2::api::InstanceInitializationMethod>
for InstanceInitializationMethod
{
fn from(old: v2::api::InstanceInitializationMethod) -> Self {
match old {
v2::api::InstanceInitializationMethod::Spec { spec } => {
Self::Spec { spec: spec.into() }
}
v2::api::InstanceInitializationMethod::MigrationTarget {
migration_id,
src_addr,
replace_components,
} => Self::MigrationTarget {
migration_id,
src_addr,
replace_components,
},
}
}
}

impl From<v2::api::InstanceEnsureRequest> for InstanceEnsureRequest {
fn from(old: v2::api::InstanceEnsureRequest) -> Self {
Self { properties: old.properties, init: old.init.into() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Device configuration data for the NVME_MODEL_NUMBER API version.

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::v1;
use crate::v1::instance_spec::{PciPath, SpecKey};

/// A disk that presents an NVMe interface to the guest.
#[derive(Clone, Deserialize, Serialize, Debug, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct NvmeDisk {
/// The name of the disk's backend component.
pub backend_id: SpecKey,

/// The PCI bus/device/function at which this disk should be attached.
pub pci_path: PciPath,

/// The serial number to return in response to an NVMe Identify Controller
/// command.
#[serde(with = "serde_human_bytes::HexArray::<20>")]
pub serial_number: [u8; 20],

/// The model number to return in response to an NVMe Identify Controller
/// command.
#[serde(with = "serde_human_bytes::HexArray::<40>")]
pub model_number: [u8; 40],
}

impl From<v1::components::devices::NvmeDisk> for NvmeDisk {
fn from(old: v1::components::devices::NvmeDisk) -> Self {
Self {
backend_id: old.backend_id,
pci_path: old.pci_path,
serial_number: old.serial_number,
model_number: [0u8; 40],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this -- not sure what to do here.

}
}
}

impl From<NvmeDisk> for v1::components::devices::NvmeDisk {
fn from(new: NvmeDisk) -> Self {
Self {
backend_id: new.backend_id,
pci_path: new.pci_path,
serial_number: new.serial_number,
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Component types for the NVME_MODEL_NUMBER API version.

pub mod devices;
Loading