Skip to content

Commit

Permalink
runtime-rs: build qemu params for QmpSocket
Browse files Browse the repository at this point in the history
Fixies: kata-containers#9603

Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
  • Loading branch information
Apokleos committed May 7, 2024
1 parent e59dcf0 commit 59fd754
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,6 @@ impl ToQemuParams for DeviceIntelIommu {
// to create a QMP unix domain manageent socket, e.g.,
// -qmp unix:/tmp/qmp-socket,server=on,wait=off.
#[derive(Debug, Default, PartialEq)]
#[allow(dead_code)]
pub enum MonitorProtocol {
// Socket using a human-friendly text-based protocol.
Hmp,
Expand All @@ -1202,7 +1201,6 @@ pub enum MonitorProtocol {
QmpPretty,
}

#[allow(dead_code)]
impl MonitorProtocol {
pub fn new(proto: &str) -> Self {
match proto {
Expand Down Expand Up @@ -1259,7 +1257,6 @@ impl QmpSocket {
}

// validate returns true if the QmpSocket structure is valid and complete.
#[allow(dead_code)]
fn validate(&self) -> bool {
if self.socket_type.as_str() != QMP_SOCKET_TYPE {
return false;
Expand All @@ -1283,7 +1280,33 @@ impl QmpSocket {
#[async_trait]
impl ToQemuParams for QmpSocket {
async fn qemu_params(&self) -> Result<Vec<String>> {
Ok(vec![])
if !self.validate() {
return Err(anyhow!("validate qmp socket failed"));
}

let mut params: Vec<String> = Vec::new();

// -qmp unix:fd=SOCKFD,server=on,wait=off
// -qmp unix:path=/tmp/qmp-socket,server=on,wait=off
let param_qmp = format!("-{}", self.protocol.to_string());
if self.fd.is_some() {
params.push(format!(
"{}:fd={}",
self.socket_type,
self.fd.as_ref().unwrap().as_raw_fd()
));
} else {
params.push(format!("{}:path={}", self.socket_type, self.name));
}

if self.server {
params.push("server=on".to_owned());
if self.nowait {
params.push("wait=off".to_owned());
}
}

Ok(vec![param_qmp, params.join(",")])
}
}

Expand Down

0 comments on commit 59fd754

Please sign in to comment.