mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
tpm: drop cmd from Emulator struct
The command is not done asynchronously. And there is no way to propagate this error anywhere. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
+6
-23
@@ -72,7 +72,6 @@ pub struct BackendCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Emulator {
|
pub struct Emulator {
|
||||||
cmd: Option<BackendCmd>,
|
|
||||||
caps: PtmCap, /* capabilities of the TPM */
|
caps: PtmCap, /* capabilities of the TPM */
|
||||||
control_socket: SocketDev,
|
control_socket: SocketDev,
|
||||||
data_fd: RawFd,
|
data_fd: RawFd,
|
||||||
@@ -100,7 +99,6 @@ impl Emulator {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut emulator = Self {
|
let mut emulator = Self {
|
||||||
cmd: None,
|
|
||||||
caps: 0,
|
caps: 0,
|
||||||
control_socket: socket,
|
control_socket: socket,
|
||||||
data_fd: -1,
|
data_fd: -1,
|
||||||
@@ -287,13 +285,12 @@ impl Emulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Function to write to data socket and read the response from it
|
/// Function to write to data socket and read the response from it
|
||||||
fn unix_tx_bufs(&mut self) -> Result<()> {
|
fn unix_tx_bufs(&mut self, cmd: &mut BackendCmd) -> Result<()> {
|
||||||
let isselftest: bool;
|
let isselftest: bool;
|
||||||
// SAFETY: type "sockaddr_storage" is valid with an all-zero byte-pattern value
|
// SAFETY: type "sockaddr_storage" is valid with an all-zero byte-pattern value
|
||||||
let mut addr: sockaddr_storage = unsafe { mem::zeroed() };
|
let mut addr: sockaddr_storage = unsafe { mem::zeroed() };
|
||||||
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
|
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
|
||||||
|
|
||||||
if let Some(ref mut cmd) = self.cmd {
|
|
||||||
cmd.selftest_done = false;
|
cmd.selftest_done = false;
|
||||||
isselftest = is_selftest(cmd.input.to_vec(), cmd.input_len);
|
isselftest = is_selftest(cmd.input.to_vec(), cmd.input_len);
|
||||||
|
|
||||||
@@ -362,34 +359,20 @@ impl Emulator {
|
|||||||
errcode.copy_from_slice(&cmd.output[6..6 + 4]);
|
errcode.copy_from_slice(&cmd.output[6..6 + 4]);
|
||||||
cmd.selftest_done = u32::from_ne_bytes(errcode).to_be() == 0;
|
cmd.selftest_done = u32::from_ne_bytes(errcode).to_be() == 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deliver_request(&mut self, in_cmd: &mut BackendCmd) -> Result<Vec<u8>> {
|
pub fn deliver_request(&mut self, cmd: &mut BackendCmd) -> Result<Vec<u8>> {
|
||||||
if self.cmd.is_some() {
|
self.unix_tx_bufs(cmd)?;
|
||||||
//previous request did not finish cleanly
|
|
||||||
return Err(Error::DeliverRequest(anyhow!(
|
|
||||||
"Cannot deliver tpm Request as previous cmd did not complete."
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
self.cmd = Some(in_cmd.clone());
|
|
||||||
|
|
||||||
self.unix_tx_bufs()?;
|
let output = cmd.output.clone();
|
||||||
|
cmd.output.fill(0);
|
||||||
|
cmd.output.clone_from(&output);
|
||||||
|
|
||||||
let output = self.cmd.as_ref().unwrap().output.clone();
|
|
||||||
in_cmd.output.fill(0);
|
|
||||||
in_cmd.output.clone_from(&output);
|
|
||||||
|
|
||||||
self.backend_request_completed();
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn backend_request_completed(&mut self) {
|
|
||||||
self.cmd = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cancel_cmd(&mut self) -> Result<()> {
|
pub fn cancel_cmd(&mut self) -> Result<()> {
|
||||||
let mut res: PtmResult = 0;
|
let mut res: PtmResult = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user