Skip to content

Commit

Permalink
Add vmsa show command
Browse files Browse the repository at this point in the history
Prints an existing VMSA binary file as json.

Using json for output lets us use existing json processing tools
for any diff or analysis or reformatting. The downside is the json
pretty printer is not too pretty with our big reserved* arrays.

The json field names match the internal Vmsa stuct field names, so
any change there will change the `show` output. I think this is fine,
since the kernel Vmsa structure can change on us anyways, so `vmsa show`
may not be stable across sevctl versions anyways.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
  • Loading branch information
crobinso authored and tylerfanelli committed May 27, 2022
1 parent 503756b commit f11015f
Show file tree
Hide file tree
Showing 7 changed files with 1,290 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,12 @@ Update an existing VMSA binary file in place, with the passed options.
$ sevctl vmsa build EXISTING-VMSA0.bin --userspace qemu --family 25 --stepping 1 --model 1 --firmware /path/to/OVMF.amdsev.fd --cpu 0
```

### vmsa show

Print an existing VMSA binary file as JSON

```console
$ sevctl vmsa show EXISTING-VMSA0.bin
```

License: Apache-2.0
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@
//! ```console
//! $ sevctl vmsa build EXISTING-VMSA0.bin --userspace qemu --family 25 --stepping 1 --model 1 --firmware /path/to/OVMF.amdsev.fd --cpu 0
//! ```
//!
//! ## vmsa show
//!
//! Print an existing VMSA binary file as JSON
//!
//! ```console
//! $ sevctl vmsa show EXISTING-VMSA0.bin
//! ```
#![deny(clippy::all)]
#![deny(missing_docs)]
Expand Down Expand Up @@ -345,6 +353,7 @@ fn main() {
SevctlCmd::Verify { sev, oca, ca } => verify::cmd(sevctl.quiet, sev, oca, ca),
SevctlCmd::Vmsa(option) => match option {
VmsaCmd::Build(args) => vmsa::build::cmd(args),
VmsaCmd::Show(args) => vmsa::show::cmd(args),
VmsaCmd::Update(args) => vmsa::update::cmd(args),
},
};
Expand Down
8 changes: 8 additions & 0 deletions src/vmsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![allow(dead_code)]

pub mod build;
pub mod show;
pub mod update;

use super::*;
Expand All @@ -25,9 +26,16 @@ use uuid::{uuid, Uuid};
#[derive(StructOpt)]
pub enum VmsaCmd {
Build(BuildUpdateCmdArgs),
Show(VmsaShowCmdArgs),
Update(BuildUpdateCmdArgs),
}

#[derive(StructOpt, Debug)]
pub struct VmsaShowCmdArgs {
#[structopt(help = "VMSA binary file to print as JSON")]
pub filename: String,
}

// cmdline arguments for the "build" and "update" subcommands.
#[derive(StructOpt, fmt::Debug)]
pub struct BuildUpdateCmdArgs {
Expand Down
11 changes: 11 additions & 0 deletions src/vmsa/show.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{Vmsa, VmsaShowCmdArgs};

pub fn cmd(args: VmsaShowCmdArgs) -> super::Result<()> {
let vmsa = Vmsa::from_file(&args.filename)?;

println!("{}", serde_json::to_string_pretty(&vmsa).unwrap());

Ok(())
}
Loading

0 comments on commit f11015f

Please sign in to comment.