Skip to content

Commit 1906686

Browse files
stefano-garzarellajiangliu
authored andcommitted
vhost_kern: add VhostKernFeatures trait
Add new VhostKernFeatures trait to handle the backend features supported by the backend and acked by the fronted. Signed-off-by: Stefano Garzarella <[email protected]>
1 parent 8dea3b6 commit 1906686

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/vhost_kern/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,37 @@ impl<T: VhostKernBackend> VhostBackend for T {
281281
ioctl_result(ret, ())
282282
}
283283
}
284+
285+
/// Interface to handle in-kernel backend features.
286+
pub trait VhostKernFeatures: Sized + AsRawFd {
287+
/// Get features acked with the vhost backend.
288+
fn get_backend_features_acked(&self) -> u64;
289+
290+
/// Set features acked with the vhost backend.
291+
fn set_backend_features_acked(&mut self, features: u64);
292+
293+
/// Get a bitmask of supported vhost backend features.
294+
fn get_backend_features(&self) -> Result<u64> {
295+
let mut avail_features: u64 = 0;
296+
// This ioctl is called on a valid vhost fd and has its return value checked.
297+
let ret =
298+
unsafe { ioctl_with_mut_ref(self, VHOST_GET_BACKEND_FEATURES(), &mut avail_features) };
299+
ioctl_result(ret, avail_features)
300+
}
301+
302+
/// Inform the vhost subsystem which backend features to enable. This should
303+
/// be a subset of supported features from VHOST_GET_BACKEND_FEATURES.
304+
///
305+
/// # Arguments
306+
/// * `features` - Bitmask of features to set.
307+
fn set_backend_features(&mut self, features: u64) -> Result<()> {
308+
// This ioctl is called on a valid vhost fd and has its return value checked.
309+
let ret = unsafe { ioctl_with_ref(self, VHOST_SET_BACKEND_FEATURES(), &features) };
310+
311+
if ret >= 0 {
312+
self.set_backend_features_acked(features);
313+
}
314+
315+
ioctl_result(ret, ())
316+
}
317+
}

0 commit comments

Comments
 (0)