summaryrefslogtreecommitdiff
path: root/src/vhost_user/dummy_slave.rs
diff options
context:
space:
mode:
authorSebastien Boeuf <sebastien.boeuf@intel.com>2021-06-08 10:24:23 +0200
committerSebastien Boeuf <sebastien.boeuf@intel.com>2021-06-11 13:51:37 +0200
commita8ff939161d41fc2f449b80e461d013c1e19f666 (patch)
tree289513425919e07f3ccd894709e840b324e9610a /src/vhost_user/dummy_slave.rs
parent30ba3e7bbe9e0542cf480f44bc6845a8dbd2a6ba (diff)
downloadvmm_vhost-a8ff939161d41fc2f449b80e461d013c1e19f666.tar.gz
vhost_user: Add Inflight I/O tracking support
The inflight I/O tracking feature is useful for handling crashes and disconnections from the backend. It allows the backend to rely on a buffer that was shared earlier with the VMM to restore to the previous state it was before the crash. This feature depends on the availability of the protocol feature VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD, and it implements both VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD messages. Fixes #43 Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Diffstat (limited to 'src/vhost_user/dummy_slave.rs')
-rw-r--r--src/vhost_user/dummy_slave.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/vhost_user/dummy_slave.rs b/src/vhost_user/dummy_slave.rs
index b2b83d2..dc9eed5 100644
--- a/src/vhost_user/dummy_slave.rs
+++ b/src/vhost_user/dummy_slave.rs
@@ -1,7 +1,8 @@
// Copyright (C) 2019 Alibaba Cloud Computing. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
-use std::os::unix::io::RawFd;
+use std::fs::File;
+use std::os::unix::io::{AsRawFd, RawFd};
use super::message::*;
use super::*;
@@ -25,6 +26,7 @@ pub struct DummySlaveReqHandler {
pub err_fd: [Option<RawFd>; MAX_QUEUE_NUM],
pub vring_started: [bool; MAX_QUEUE_NUM],
pub vring_enabled: [bool; MAX_QUEUE_NUM],
+ pub inflight_file: Option<File>,
}
impl DummySlaveReqHandler {
@@ -245,6 +247,28 @@ impl VhostUserSlaveReqHandlerMut for DummySlaveReqHandler {
Ok(())
}
+ fn get_inflight_fd(
+ &mut self,
+ inflight: &VhostUserInflight,
+ ) -> Result<(VhostUserInflight, RawFd)> {
+ let file = tempfile::tempfile().unwrap();
+ let fd = file.as_raw_fd();
+ self.inflight_file = Some(file);
+ Ok((
+ VhostUserInflight {
+ mmap_size: 0x1000,
+ mmap_offset: 0,
+ num_queues: inflight.num_queues,
+ queue_size: inflight.queue_size,
+ },
+ fd,
+ ))
+ }
+
+ fn set_inflight_fd(&mut self, _inflight: &VhostUserInflight, _file: File) -> Result<()> {
+ Ok(())
+ }
+
fn get_max_mem_slots(&mut self) -> Result<u64> {
Ok(MAX_MEM_SLOTS as u64)
}