Skip to content

Commit

Permalink
mshv-ioctls: Add TryFrom implementation for VmType
Browse files Browse the repository at this point in the history
This is required to convert a u64 to VmType. On the cloud hypervisor
side, we would have a u64 as vm type which needs to be converted to
VmType when invoking create_vm from MSHV crate.

Signed-off-by: Jinank Jain <[email protected]>
  • Loading branch information
Jinank Jain committed Jun 30, 2023
1 parent a55f084 commit c424366
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mshv-ioctls/src/ioctls/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,21 @@ pub enum IoEventAddress {
#[derive(Eq, PartialEq, Hash, Clone, Debug, Copy)]
pub enum VmType {
/// Normal VM with no support for confidential computing
Normal,
Normal = 0,
/// AMD's SEV-SNP
Snp,
Snp = 1,
}

impl TryFrom<u64> for VmType {
type Error = ();

fn try_from(v: u64) -> std::result::Result<Self, Self::Error> {
match v {
x if x == VmType::Normal as u64 => Ok(VmType::Normal),
x if x == VmType::Snp as u64 => Ok(VmType::Snp),
_ => Err(()),
}
}
}

/// Helper structure for disabling datamatch.
Expand Down

0 comments on commit c424366

Please sign in to comment.