From 3c0f06c09c6d830755971dfcb073a6d79cfa4f2f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Fri, 4 Jun 2021 16:17:48 +0200 Subject: [PATCH] virtio-devices: vhost_user: Set NEED_REPLY when REPLY_ACK is supported Now that vhost crate allows the caller to set the header flags, we can set NEED_REPLY whenever the REPLY_ACK protocol feature is supported from both ends. Signed-off-by: Sebastien Boeuf --- Cargo.lock | 2 +- .../src/vhost_user/vu_common_ctrl.rs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5740563c7..149a1d96a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1111,7 +1111,7 @@ dependencies = [ [[package]] name = "vhost" version = "0.1.0" -source = "git+https://github.com/rust-vmm/vhost?branch=master#a8ff939161d41fc2f449b80e461d013c1e19f666" +source = "git+https://github.com/rust-vmm/vhost?branch=master#e294ed66fcc12e033957f20034ae5fef5bb9eeac" dependencies = [ "bitflags", "libc", diff --git a/virtio-devices/src/vhost_user/vu_common_ctrl.rs b/virtio-devices/src/vhost_user/vu_common_ctrl.rs index fc4612093..2b1438119 100644 --- a/virtio-devices/src/vhost_user/vu_common_ctrl.rs +++ b/virtio-devices/src/vhost_user/vu_common_ctrl.rs @@ -14,7 +14,7 @@ use std::thread::sleep; use std::time::{Duration, Instant}; use std::vec::Vec; use vhost::vhost_user::message::{ - VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures, + VhostUserHeaderFlag, VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures, }; use vhost::vhost_user::{Master, MasterReqHandler, VhostUserMaster, VhostUserMasterReqHandler}; use vhost::{VhostBackend, VhostUserMemoryRegionInfo, VringConfigData}; @@ -95,12 +95,18 @@ pub fn negotiate_features_vhost_user( vu.set_protocol_features(acked_protocol_features) .map_err(Error::VhostUserSetProtocolFeatures)?; - acked_protocol_features.bits() + acked_protocol_features } else { - 0 + VhostUserProtocolFeatures::empty() }; - Ok((acked_features, acked_protocol_features)) + if avail_protocol_features.contains(VhostUserProtocolFeatures::REPLY_ACK) + && acked_protocol_features.contains(VhostUserProtocolFeatures::REPLY_ACK) + { + vu.set_hdr_flags(VhostUserHeaderFlag::NEED_REPLY); + } + + Ok((acked_features, acked_protocol_features.bits())) } #[allow(clippy::too_many_arguments)] @@ -230,6 +236,10 @@ pub fn reinitialize_vhost_user( { vu.set_protocol_features(acked_protocol_features) .map_err(Error::VhostUserSetProtocolFeatures)?; + + if acked_protocol_features.contains(VhostUserProtocolFeatures::REPLY_ACK) { + vu.set_hdr_flags(VhostUserHeaderFlag::NEED_REPLY); + } } }