chore(xen): split platform support into separate crate (#195)

This commit is contained in:
Alex Zenla 2024-06-21 01:10:45 -07:00 committed by GitHub
parent 23c7302c04
commit 6f39f115b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 136 additions and 45 deletions

32
Cargo.lock generated
View File

@ -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"

View File

@ -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"

View File

@ -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,

View File

@ -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 }

View File

@ -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,

View File

@ -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

View File

@ -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 }

View File

@ -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<()> {

View File

@ -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<T> = std::result::Result<T, Error>;

View File

@ -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<P: BootSetupPlatform> {
pub store: XsdClient,

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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<T> = std::result::Result<T, Error>;

View File

@ -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;

View File

@ -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

View File

@ -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