From 6f39f115b7bf3b2c273e04a595150dd0673f76e8 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Fri, 21 Jun 2024 01:10:45 -0700 Subject: [PATCH] chore(xen): split platform support into separate crate (#195) --- Cargo.lock | 32 +++++++++++--- Cargo.toml | 2 + crates/ctl/src/cli/mod.rs | 5 +-- crates/runtime/Cargo.toml | 1 + crates/runtime/src/lib.rs | 4 +- crates/xen/xencall/Cargo.toml | 2 +- crates/xen/xenclient/Cargo.toml | 10 +---- crates/xen/xenclient/examples/boot.rs | 4 +- crates/xen/xenclient/src/error.rs | 8 +--- crates/xen/xenclient/src/lib.rs | 15 ++----- crates/xen/xenevtchn/Cargo.toml | 2 +- crates/xen/xengnt/Cargo.toml | 2 +- crates/xen/xenplatform/Cargo.toml | 34 +++++++++++++++ .../{xenclient => xenplatform}/src/boot.rs | 0 .../src/elfloader.rs | 0 crates/xen/xenplatform/src/error.rs | 43 +++++++++++++++++++ crates/xen/xenplatform/src/lib.rs | 11 +++++ .../xen/{xenclient => xenplatform}/src/mem.rs | 0 .../xen/{xenclient => xenplatform}/src/sys.rs | 0 .../src/unsupported.rs | 0 .../{xenclient => xenplatform}/src/x86pv.rs | 0 crates/xen/xenstore/Cargo.toml | 2 +- release-plz.toml | 4 ++ 23 files changed, 136 insertions(+), 45 deletions(-) create mode 100644 crates/xen/xenplatform/Cargo.toml rename crates/xen/{xenclient => xenplatform}/src/boot.rs (100%) rename crates/xen/{xenclient => xenplatform}/src/elfloader.rs (100%) create mode 100644 crates/xen/xenplatform/src/error.rs create mode 100644 crates/xen/xenplatform/src/lib.rs rename crates/xen/{xenclient => xenplatform}/src/mem.rs (100%) rename crates/xen/{xenclient => xenplatform}/src/sys.rs (100%) rename crates/xen/{xenclient => xenplatform}/src/unsupported.rs (100%) rename crates/xen/{xenclient => xenplatform}/src/x86pv.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 9b58d15..a3e607a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1584,6 +1584,7 @@ dependencies = [ "krata-xenclient", "krata-xenevtchn", "krata-xengnt", + "krata-xenplatform", "krata-xenstore", "log", "loopdev-3", @@ -1626,23 +1627,17 @@ name = "krata-xenclient" version = "0.0.10" dependencies = [ "async-trait", - "c2rust-bitfields", - "elf", "env_logger", - "flate2", "indexmap 2.2.6", "krata-xencall", + "krata-xenplatform", "krata-xenstore", "libc", "log", - "memchr", - "nix 0.28.0", "regex", - "slice-copy", "thiserror", "tokio", "uuid", - "xz2", ] [[package]] @@ -1665,6 +1660,29 @@ dependencies = [ "thiserror", ] +[[package]] +name = "krata-xenplatform" +version = "0.0.10" +dependencies = [ + "async-trait", + "c2rust-bitfields", + "elf", + "env_logger", + "flate2", + "indexmap 2.2.6", + "krata-xencall", + "libc", + "log", + "memchr", + "nix 0.28.0", + "regex", + "slice-copy", + "thiserror", + "tokio", + "uuid", + "xz2", +] + [[package]] name = "krata-xenstore" version = "0.0.10" diff --git a/Cargo.toml b/Cargo.toml index a321d74..86f392c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ members = [ "crates/xen/xenclient", "crates/xen/xenevtchn", "crates/xen/xengnt", + "crates/xen/xenplatform", "crates/xen/xenstore", ] resolver = "2" @@ -32,6 +33,7 @@ backhand = "0.15.0" base64 = "0.22.1" byteorder = "1" bytes = "1.5.0" +c2rust-bitfields = "0.18.0" cgroups-rs = "0.3.4" circular-buffer = "0.1.7" comfy-table = "7.1.1" diff --git a/crates/ctl/src/cli/mod.rs b/crates/ctl/src/cli/mod.rs index 371fca2..2f13db5 100644 --- a/crates/ctl/src/cli/mod.rs +++ b/crates/ctl/src/cli/mod.rs @@ -31,10 +31,7 @@ use self::{ }; #[derive(Parser)] -#[command( - version, - about = "Control the krata isolation engine" -)] +#[command(version, about = "Control the krata isolation engine")] pub struct ControlCommand { #[arg( short, diff --git a/crates/runtime/Cargo.toml b/crates/runtime/Cargo.toml index d406a96..a25a7f1 100644 --- a/crates/runtime/Cargo.toml +++ b/crates/runtime/Cargo.toml @@ -23,6 +23,7 @@ uuid = { workspace = true } krata-xenclient = { path = "../xen/xenclient", version = "^0.0.10" } krata-xenevtchn = { path = "../xen/xenevtchn", version = "^0.0.10" } krata-xengnt = { path = "../xen/xengnt", version = "^0.0.10" } +krata-xenplatform = { path = "../xen/xenplatform", version = "^0.0.10" } krata-xenstore = { path = "../xen/xenstore", version = "^0.0.10" } walkdir = { workspace = true } diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 9fc81d3..385965f 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -22,10 +22,10 @@ pub mod ip; pub mod launch; #[cfg(target_arch = "x86_64")] -type RuntimePlatform = xenclient::x86pv::X86PvPlatform; +type RuntimePlatform = xenplatform::x86pv::X86PvPlatform; #[cfg(not(target_arch = "x86_64"))] -type RuntimePlatform = xenclient::unsupported::UnsupportedPlatform; +type RuntimePlatform = xenplatform::unsupported::UnsupportedPlatform; pub struct GuestLoopInfo { pub device: String, diff --git a/crates/xen/xencall/Cargo.toml b/crates/xen/xencall/Cargo.toml index 4b10127..1f0bf06 100644 --- a/crates/xen/xencall/Cargo.toml +++ b/crates/xen/xencall/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "krata-xencall" -description = "An implementation of direct interfacing to xen privcmd for krata." +description = "An implementation of direct interfacing to Xen privcmd for krata" license.workspace = true version.workspace = true homepage.workspace = true diff --git a/crates/xen/xenclient/Cargo.toml b/crates/xen/xenclient/Cargo.toml index a2fc5f9..e019f6e 100644 --- a/crates/xen/xenclient/Cargo.toml +++ b/crates/xen/xenclient/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "krata-xenclient" -description = "An implementation of Xen userspace for krata." +description = "An implementation of Xen userspace for krata" license.workspace = true version.workspace = true homepage.workspace = true @@ -10,22 +10,16 @@ resolver = "2" [dependencies] async-trait = { workspace = true } -c2rust-bitfields = "0.18.0" -elf = { workspace = true } -flate2 = { workspace = true } indexmap = { workspace = true } libc = { workspace = true } log = { workspace = true } krata-xencall = { path = "../xencall", version = "^0.0.10" } +krata-xenplatform = { path = "../xenplatform", version = "^0.0.10" } krata-xenstore = { path = "../xenstore", version = "^0.0.10" } -memchr = { workspace = true } -nix = { workspace = true } regex = { workspace = true } -slice-copy = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true } uuid = { workspace = true } -xz2 = { workspace = true } [dev-dependencies] env_logger = { workspace = true } diff --git a/crates/xen/xenclient/examples/boot.rs b/crates/xen/xenclient/examples/boot.rs index 48e5d25..3045177 100644 --- a/crates/xen/xenclient/examples/boot.rs +++ b/crates/xen/xenclient/examples/boot.rs @@ -4,10 +4,10 @@ use xenclient::error::Result; use xenclient::{DomainConfig, XenClient}; #[cfg(target_arch = "x86_64")] -type RuntimePlatform = xenclient::x86pv::X86PvPlatform; +type RuntimePlatform = xenplatform::x86pv::X86PvPlatform; #[cfg(not(target_arch = "x86_64"))] -type RuntimePlatform = xenclient::unsupported::UnsupportedPlatform; +type RuntimePlatform = xenplatform::unsupported::UnsupportedPlatform; #[tokio::main] async fn main() -> Result<()> { diff --git a/crates/xen/xenclient/src/error.rs b/crates/xen/xenclient/src/error.rs index 7f6a059..9c18500 100644 --- a/crates/xen/xenclient/src/error.rs +++ b/crates/xen/xenclient/src/error.rs @@ -20,12 +20,6 @@ pub enum Error { PathParentNotFound, #[error("domain does not exist")] DomainNonExistent, - #[error("elf parse failed: {0}")] - ElfParseFailed(#[from] elf::ParseError), - #[error("mmap failed")] - MmapFailed, - #[error("munmap failed: {0}")] - UnmapFailed(nix::errno::Errno), #[error("memory setup failed: {0}")] MemorySetupFailed(&'static str), #[error("populate physmap failed: wanted={0}, received={1}, input_extents={2}")] @@ -46,6 +40,8 @@ pub enum Error { InvalidPciBdfString, #[error("pci device {0} is not assignable")] PciDeviceNotAssignable(PciBdf), + #[error("xen platform error: {0}")] + XenPlatform(#[from] xenplatform::error::Error), } pub type Result = std::result::Result; diff --git a/crates/xen/xenclient/src/lib.rs b/crates/xen/xenclient/src/lib.rs index 08a0ea8..1021d56 100644 --- a/crates/xen/xenclient/src/lib.rs +++ b/crates/xen/xenclient/src/lib.rs @@ -1,18 +1,13 @@ -pub mod boot; -pub mod elfloader; pub mod error; -pub mod mem; -pub mod sys; -use crate::boot::{BootDomain, BootSetup}; -use crate::elfloader::ElfImageLoader; use crate::error::{Error, Result}; -use boot::BootSetupPlatform; use indexmap::IndexMap; use log::{debug, trace, warn}; use pci::{PciBdf, XenPciBackend}; -use sys::XEN_PAGE_SHIFT; use tokio::time::timeout; +use xenplatform::boot::{BootDomain, BootSetup, BootSetupPlatform}; +use xenplatform::elfloader::ElfImageLoader; +use xenplatform::sys::XEN_PAGE_SHIFT; use std::path::PathBuf; use std::str::FromStr; @@ -28,10 +23,6 @@ use xenstore::{ pub mod pci; -pub mod unsupported; -#[cfg(target_arch = "x86_64")] -pub mod x86pv; - #[derive(Clone)] pub struct XenClient { pub store: XsdClient, diff --git a/crates/xen/xenevtchn/Cargo.toml b/crates/xen/xenevtchn/Cargo.toml index 644d928..6a4d9d9 100644 --- a/crates/xen/xenevtchn/Cargo.toml +++ b/crates/xen/xenevtchn/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "krata-xenevtchn" -description = "An implementation of xen evtchn for krata." +description = "An implementation of Xen evtchn for krata." license.workspace = true version.workspace = true homepage.workspace = true diff --git a/crates/xen/xengnt/Cargo.toml b/crates/xen/xengnt/Cargo.toml index 9b4c8aa..3addf3f 100644 --- a/crates/xen/xengnt/Cargo.toml +++ b/crates/xen/xengnt/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "krata-xengnt" -description = "An implementation of xen grant interfaces for krata." +description = "An implementation of Xen grant interfaces for krata" license.workspace = true version.workspace = true homepage.workspace = true diff --git a/crates/xen/xenplatform/Cargo.toml b/crates/xen/xenplatform/Cargo.toml new file mode 100644 index 0000000..92b387e --- /dev/null +++ b/crates/xen/xenplatform/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "krata-xenplatform" +description = "An implementation of Xen platforms for krata" +license.workspace = true +version.workspace = true +homepage.workspace = true +repository.workspace = true +edition = "2021" +resolver = "2" + +[dependencies] +async-trait = { workspace = true } +c2rust-bitfields = { workspace = true } +elf = { workspace = true } +flate2 = { workspace = true } +indexmap = { workspace = true } +libc = { workspace = true } +log = { workspace = true } +krata-xencall = { path = "../xencall", version = "^0.0.10" } +memchr = { workspace = true } +nix = { workspace = true } +regex = { workspace = true } +slice-copy = { workspace = true } +thiserror = { workspace = true } +tokio = { workspace = true } +uuid = { workspace = true } +xz2 = { workspace = true } + +[dev-dependencies] +env_logger = { workspace = true } +tokio = { workspace = true } + +[lib] +name = "xenplatform" diff --git a/crates/xen/xenclient/src/boot.rs b/crates/xen/xenplatform/src/boot.rs similarity index 100% rename from crates/xen/xenclient/src/boot.rs rename to crates/xen/xenplatform/src/boot.rs diff --git a/crates/xen/xenclient/src/elfloader.rs b/crates/xen/xenplatform/src/elfloader.rs similarity index 100% rename from crates/xen/xenclient/src/elfloader.rs rename to crates/xen/xenplatform/src/elfloader.rs diff --git a/crates/xen/xenplatform/src/error.rs b/crates/xen/xenplatform/src/error.rs new file mode 100644 index 0000000..72d85f7 --- /dev/null +++ b/crates/xen/xenplatform/src/error.rs @@ -0,0 +1,43 @@ +use std::io; + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("io issue encountered: {0}")] + Io(#[from] io::Error), + #[error("xencall issue encountered: {0}")] + XenCall(#[from] xencall::error::Error), + #[error("domain does not have a tty")] + TtyNotFound, + #[error("introducing the domain failed")] + IntroduceDomainFailed, + #[error("string conversion of a path failed")] + PathStringConversion, + #[error("parent of path not found")] + PathParentNotFound, + #[error("domain does not exist")] + DomainNonExistent, + #[error("elf parse failed: {0}")] + ElfParseFailed(#[from] elf::ParseError), + #[error("mmap failed")] + MmapFailed, + #[error("munmap failed: {0}")] + UnmapFailed(nix::errno::Errno), + #[error("memory setup failed: {0}")] + MemorySetupFailed(&'static str), + #[error("populate physmap failed: wanted={0}, received={1}, input_extents={2}")] + PopulatePhysmapFailed(usize, usize, usize), + #[error("unknown elf compression method")] + ElfCompressionUnknown, + #[error("expected elf image format not found")] + ElfInvalidImage, + #[error("provided elf image does not contain xen support")] + ElfXenSupportMissing, + #[error("regex error: {0}")] + RegexError(#[from] regex::Error), + #[error("error: {0}")] + GenericError(String), + #[error("failed to parse int: {0}")] + ParseIntError(#[from] std::num::ParseIntError), +} + +pub type Result = std::result::Result; diff --git a/crates/xen/xenplatform/src/lib.rs b/crates/xen/xenplatform/src/lib.rs new file mode 100644 index 0000000..322c388 --- /dev/null +++ b/crates/xen/xenplatform/src/lib.rs @@ -0,0 +1,11 @@ +pub mod boot; +pub mod elfloader; +pub mod error; +pub mod mem; +pub mod sys; + +use crate::error::Error; + +pub mod unsupported; +#[cfg(target_arch = "x86_64")] +pub mod x86pv; diff --git a/crates/xen/xenclient/src/mem.rs b/crates/xen/xenplatform/src/mem.rs similarity index 100% rename from crates/xen/xenclient/src/mem.rs rename to crates/xen/xenplatform/src/mem.rs diff --git a/crates/xen/xenclient/src/sys.rs b/crates/xen/xenplatform/src/sys.rs similarity index 100% rename from crates/xen/xenclient/src/sys.rs rename to crates/xen/xenplatform/src/sys.rs diff --git a/crates/xen/xenclient/src/unsupported.rs b/crates/xen/xenplatform/src/unsupported.rs similarity index 100% rename from crates/xen/xenclient/src/unsupported.rs rename to crates/xen/xenplatform/src/unsupported.rs diff --git a/crates/xen/xenclient/src/x86pv.rs b/crates/xen/xenplatform/src/x86pv.rs similarity index 100% rename from crates/xen/xenclient/src/x86pv.rs rename to crates/xen/xenplatform/src/x86pv.rs diff --git a/crates/xen/xenstore/Cargo.toml b/crates/xen/xenstore/Cargo.toml index 9295437..21b1d1b 100644 --- a/crates/xen/xenstore/Cargo.toml +++ b/crates/xen/xenstore/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "krata-xenstore" -description = "A client that interacts with xenstore for krata." +description = "A client that interacts with xenstore for krata" license.workspace = true version.workspace = true homepage.workspace = true diff --git a/release-plz.toml b/release-plz.toml index 5d4cfe1..4f1be25 100644 --- a/release-plz.toml +++ b/release-plz.toml @@ -36,6 +36,10 @@ semver_check = false name = "krata-xengnt" semver_check = false +[[package]] +name = "krata-xenplatform" +semver_check = false + [[package]] name = "krata-xenstore" semver_check = false