introduce logging for debug purposes

This commit is contained in:
Alex Zenla
2024-01-11 12:21:33 -08:00
parent 2e4f688916
commit 684a7d1f62
14 changed files with 127 additions and 10 deletions

View File

@ -9,6 +9,7 @@ path = "src/lib.rs"
[dependencies]
libc = "0.2"
log = "0.4.20"
[dependencies.uuid]
version = "1.6.1"
@ -18,6 +19,9 @@ features = ["v4"]
version = "0.27.1"
features = ["ioctl"]
[dev-dependencies]
env_logger = "0.10.1"
[[example]]
name = "xencall-domain-info"
path = "examples/domain_info.rs"

View File

@ -3,6 +3,8 @@ use xencall::sys::CreateDomain;
use xencall::{XenCall, XenCallError};
fn main() -> Result<(), XenCallError> {
env_logger::init();
let call = XenCall::open()?;
let domctl: DomainControl = DomainControl::new(&call);
let domid = domctl.create_domain(CreateDomain::default())?;

View File

@ -2,6 +2,8 @@ use xencall::domctl::DomainControl;
use xencall::{XenCall, XenCallError};
fn main() -> Result<(), XenCallError> {
env_logger::init();
let call = XenCall::open()?;
let domctl: DomainControl = DomainControl::new(&call);
let info = domctl.get_domain_info(1)?;

View File

@ -1,6 +1,8 @@
use xencall::{XenCall, XenCallError};
fn main() -> Result<(), XenCallError> {
env_logger::init();
let call = XenCall::open()?;
let info = call.get_version_capabilities()?;
println!("{:?}", info);

View File

@ -5,7 +5,9 @@ use crate::sys::{
XEN_DOMCTL_MAX_MEM, XEN_DOMCTL_MAX_VCPUS,
};
use crate::{XenCall, XenCallError};
use log::trace;
use std::ffi::c_ulong;
use std::os::fd::AsRawFd;
use std::ptr::addr_of_mut;
pub struct DomainControl<'a> {
@ -18,6 +20,11 @@ impl DomainControl<'_> {
}
pub fn get_domain_info(&self, domid: u32) -> Result<GetDomainInfo, XenCallError> {
trace!(
"domctl fd={} get_domain_info domid={}",
self.call.handle.as_raw_fd(),
domid
);
let mut domctl = DomCtl {
cmd: XEN_DOMCTL_GETDOMAININFO,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
@ -53,6 +60,11 @@ impl DomainControl<'_> {
}
pub fn create_domain(&self, create_domain: CreateDomain) -> Result<u32, XenCallError> {
trace!(
"domctl fd={} create_domain create_domain={:?}",
self.call.handle.as_raw_fd(),
create_domain
);
let mut domctl = DomCtl {
cmd: XEN_DOMCTL_CREATEDOMAIN,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
@ -65,6 +77,12 @@ impl DomainControl<'_> {
}
pub fn set_max_mem(&self, domid: u32, memkb: u64) -> Result<(), XenCallError> {
trace!(
"domctl fd={} set_max_mem domid={} memkb={}",
self.call.handle.as_raw_fd(),
domid,
memkb
);
let mut domctl = DomCtl {
cmd: XEN_DOMCTL_MAX_MEM,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
@ -79,6 +97,12 @@ impl DomainControl<'_> {
}
pub fn set_max_vcpus(&self, domid: u32, max_vcpus: u32) -> Result<(), XenCallError> {
trace!(
"domctl fd={} set_max_vcpus domid={} max_vcpus={}",
self.call.handle.as_raw_fd(),
domid,
max_vcpus
);
let mut domctl = DomCtl {
cmd: XEN_DOMCTL_MAX_VCPUS,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
@ -93,6 +117,12 @@ impl DomainControl<'_> {
}
pub fn hypercall_init(&self, domid: u32, gmfn: u64) -> Result<(), XenCallError> {
trace!(
"domctl fd={} hypercall_init domid={} max_vcpus={}",
self.call.handle.as_raw_fd(),
domid,
gmfn
);
let mut domctl = DomCtl {
cmd: XEN_DOMCTL_HYPERCALL_INIT,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
@ -107,6 +137,11 @@ impl DomainControl<'_> {
}
pub fn destroy_domain(&self, domid: u32) -> Result<(), XenCallError> {
trace!(
"domctl fd={} destroy_domain domid={}",
self.call.handle.as_raw_fd(),
domid
);
let mut domctl = DomCtl {
cmd: XEN_DOMCTL_DESTROYDOMAIN,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,

View File

@ -7,6 +7,7 @@ use crate::sys::{
HYPERVISOR_XEN_VERSION, XENVER_CAPABILITIES,
};
use libc::{mmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};
use log::trace;
use nix::errno::Errno;
use std::error::Error;
use std::ffi::{c_long, c_ulong, c_void};
@ -66,6 +67,12 @@ impl XenCall {
}
pub fn mmap(&self, addr: u64, len: u64) -> Option<u64> {
trace!(
"call fd={} mmap addr={:#x} len={}",
self.handle.as_raw_fd(),
addr,
len
);
unsafe {
let ptr = mmap(
addr as *mut c_void,
@ -84,6 +91,12 @@ impl XenCall {
}
pub fn hypercall(&self, op: c_ulong, arg: [c_ulong; 5]) -> Result<c_long, XenCallError> {
trace!(
"call fd={} hypercall op={:#x}, arg={:?}",
self.handle.as_raw_fd(),
op,
arg
);
unsafe {
let mut call = Hypercall { op, arg };
let result = sys::hypercall(self.handle.as_raw_fd(), &mut call)?;
@ -129,15 +142,6 @@ impl XenCall {
self.hypercall(op, [arg1, arg2, arg3, arg4, 0])
}
pub fn multicall(&self, calls: &mut [MultiCallEntry]) -> Result<(), XenCallError> {
self.hypercall2(
HYPERVISOR_MULTICALL,
calls.as_mut_ptr() as c_ulong,
calls.len() as c_ulong,
)?;
Ok(())
}
pub fn hypercall5(
&self,
op: c_ulong,
@ -150,6 +154,20 @@ impl XenCall {
self.hypercall(op, [arg1, arg2, arg3, arg4, arg5])
}
pub fn multicall(&self, calls: &mut [MultiCallEntry]) -> Result<(), XenCallError> {
trace!(
"call fd={} multicall calls={:?}",
self.handle.as_raw_fd(),
calls
);
self.hypercall2(
HYPERVISOR_MULTICALL,
calls.as_mut_ptr() as c_ulong,
calls.len() as c_ulong,
)?;
Ok(())
}
pub fn mmap_batch(
&self,
domid: u32,
@ -157,6 +175,14 @@ impl XenCall {
addr: u64,
mfns: Vec<u64>,
) -> Result<c_long, XenCallError> {
trace!(
"call fd={} mmap_batch domid={} num={} addr={:#x} mfns={:?}",
self.handle.as_raw_fd(),
domid,
num,
addr,
mfns
);
unsafe {
let mut mfns = mfns.clone();
let mut errors = vec![0i32; mfns.len()];
@ -173,6 +199,10 @@ impl XenCall {
}
pub fn get_version_capabilities(&self) -> Result<XenCapabilitiesInfo, XenCallError> {
trace!(
"call fd={} get_version_capabilities",
self.handle.as_raw_fd()
);
let mut info = XenCapabilitiesInfo {
capabilities: [0; 1024],
};

View File

@ -4,8 +4,10 @@ use crate::sys::{
use crate::{XenCall, XenCallError};
use std::ffi::c_ulong;
use std::os::fd::AsRawFd;
use libc::c_long;
use log::trace;
use std::ptr::addr_of_mut;
pub struct MemoryControl<'a> {
@ -25,6 +27,7 @@ impl MemoryControl<'_> {
mem_flags: u32,
extent_starts: &[u64],
) -> Result<Vec<u64>, XenCallError> {
trace!("memory fd={} populate_physmap domid={} nr_extents={} extent_order={} mem_flags={} extent_starts={:?}", self.call.handle.as_raw_fd(), domid, nr_extents, extent_order, mem_flags, extent_starts);
let mut extent_starts = extent_starts.to_vec();
let mut reservation = MemoryReservation {
extent_start: extent_starts.as_mut_ptr() as c_ulong,