diff options
author | Sebastien Boeuf <sebastien.boeuf@intel.com> | 2021-06-04 15:54:19 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2021-06-08 10:35:35 +0200 |
commit | 30ba3e7bbe9e0542cf480f44bc6845a8dbd2a6ba (patch) | |
tree | 2f97fc03185ee01af7420f3a8b24ab7103bfd7e3 | |
parent | e4ba734144ac7a06cd8d6a43be3a3bf8e9e413a1 (diff) | |
download | vmm_vhost-30ba3e7bbe9e0542cf480f44bc6845a8dbd2a6ba.tar.gz |
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 <sebastien.boeuf@intel.com>
-rw-r--r-- | coverage_config_x86_64.json | 2 | ||||
-rw-r--r-- | 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<i32>, + // List of header flags. + hdr_flags: VhostUserHeaderFlag, } impl MasterInternal { @@ -555,7 +564,7 @@ impl MasterInternal { fds: Option<&[RawFd]>, ) -> VhostUserResult<VhostUserMsgHeader<MasterReq>> { 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::<T>() as u32); + let hdr = self.new_request_header(code, mem::size_of::<T>() 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::<VhostUserU64>() as u32); + let hdr = self.new_request_header(code, mem::size_of::<VhostUserU64>() 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<MasterReq> { - // TODO: handle NEED_REPLY flag - VhostUserMsgHeader::new(request, 0x1, size) + fn new_request_header(&self, request: MasterReq, size: u32) -> VhostUserMsgHeader<MasterReq> { + VhostUserMsgHeader::new(request, self.hdr_flags.bits() | 0x1, size) } } |