From 30ba3e7bbe9e0542cf480f44bc6845a8dbd2a6ba Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Fri, 4 Jun 2021 15:54:19 +0200 Subject: [PATCH] vhost_user: Add header flags support Introduce a new method set_flags() in order to let the caller define the expected set of flags that should be applied to the header for the following messages. Fixes #40 Signed-off-by: Sebastien Boeuf --- coverage_config_x86_64.json | 2 +- src/vhost_user/master.rs | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json index 2b2c164..f9164a8 100644 --- a/coverage_config_x86_64.json +++ b/coverage_config_x86_64.json @@ -1 +1 @@ -{"coverage_score": 81.2, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"} +{"coverage_score": 81.0, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"} diff --git a/src/vhost_user/master.rs b/src/vhost_user/master.rs index 0a4bef8..b8ba0af 100644 --- a/src/vhost_user/master.rs +++ b/src/vhost_user/master.rs @@ -84,6 +84,7 @@ impl Master { protocol_features_ready: false, max_queue_num, error: None, + hdr_flags: VhostUserHeaderFlag::empty(), })), } } @@ -125,6 +126,12 @@ impl Master { Ok(Self::new(endpoint, max_queue_num)) } + + /// Set the header flags that should be applied to all following messages. + pub fn set_hdr_flags(&self, flags: VhostUserHeaderFlag) { + let mut node = self.node(); + node.hdr_flags = flags; + } } impl VhostBackend for Master { @@ -546,6 +553,8 @@ struct MasterInternal { max_queue_num: u64, // Internal flag to mark failure state. error: Option, + // List of header flags. + hdr_flags: VhostUserHeaderFlag, } impl MasterInternal { @@ -555,7 +564,7 @@ impl MasterInternal { fds: Option<&[RawFd]>, ) -> VhostUserResult> { self.check_state()?; - let hdr = Self::new_request_header(code, 0); + let hdr = self.new_request_header(code, 0); self.main_sock.send_header(&hdr, fds)?; Ok(hdr) } @@ -571,7 +580,7 @@ impl MasterInternal { } self.check_state()?; - let hdr = Self::new_request_header(code, mem::size_of::() as u32); + let hdr = self.new_request_header(code, mem::size_of::() as u32); self.main_sock.send_message(&hdr, msg, fds)?; Ok(hdr) } @@ -594,7 +603,7 @@ impl MasterInternal { } self.check_state()?; - let hdr = Self::new_request_header(code, len as u32); + let hdr = self.new_request_header(code, len as u32); self.main_sock .send_message_with_payload(&hdr, msg, payload, fds)?; Ok(hdr) @@ -615,7 +624,7 @@ impl MasterInternal { // This flag is set when there is no file descriptor in the ancillary data. This signals // that polling will be used instead of waiting for the call. let msg = VhostUserU64::new(queue_index as u64); - let hdr = Self::new_request_header(code, mem::size_of::() as u32); + let hdr = self.new_request_header(code, mem::size_of::() as u32); self.main_sock.send_message(&hdr, &msg, Some(&[fd]))?; Ok(hdr) } @@ -698,9 +707,8 @@ impl MasterInternal { } #[inline] - fn new_request_header(request: MasterReq, size: u32) -> VhostUserMsgHeader { - // TODO: handle NEED_REPLY flag - VhostUserMsgHeader::new(request, 0x1, size) + fn new_request_header(&self, request: MasterReq, size: u32) -> VhostUserMsgHeader { + VhostUserMsgHeader::new(request, self.hdr_flags.bits() | 0x1, size) } }