virtio-devices: vhost_user: Adapt state() to return Result

This is a refactoring step in preparation for fetching backend device
state via SET_DEVICE_STATE_FD which can fail.

Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
Rob Bradford
2026-03-26 14:14:37 -07:00
parent 3e233af654
commit 8536a2536e
5 changed files with 17 additions and 11 deletions

View File

@@ -191,7 +191,7 @@ impl Blk {
})
}
fn state(&self) -> State {
fn state(&self) -> std::result::Result<State, MigratableError> {
self.vu_common.state(&self.common, self.config)
}
}
@@ -367,7 +367,7 @@ impl Snapshottable for Blk {
}
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
self.vu_common.snapshot(&self.state())
self.vu_common.snapshot(&self.state()?)
}
}
impl Transportable for Blk {}

View File

@@ -200,7 +200,7 @@ impl Fs {
})
}
fn state(&self) -> State {
fn state(&self) -> std::result::Result<State, MigratableError> {
self.vu_common.state(&self.common, self.config)
}
}
@@ -377,7 +377,7 @@ impl Snapshottable for Fs {
}
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
self.vu_common.snapshot(&self.state())
self.vu_common.snapshot(&self.state()?)
}
}
impl Transportable for Fs {}

View File

@@ -156,7 +156,7 @@ since the backend only supports {backend_num_queues}\n",
})
}
fn state(&self) -> State {
fn state(&self) -> std::result::Result<State, MigratableError> {
self.vu_common.state(&self.common, ())
}
@@ -396,7 +396,7 @@ impl Snapshottable for GenericVhostUser {
}
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
self.vu_common.snapshot(&self.state())
self.vu_common.snapshot(&self.state()?)
}
}
impl Transportable for GenericVhostUser {}

View File

@@ -457,15 +457,21 @@ impl VhostUserCommon {
Ok(())
}
pub fn state<C: Default>(&self, common: &crate::VirtioCommon, config: C) -> VhostUserState<C> {
VhostUserState {
pub fn state<C: Default>(
&self,
common: &crate::VirtioCommon,
config: C,
) -> std::result::Result<VhostUserState<C>, MigratableError> {
let state = VhostUserState {
avail_features: common.avail_features,
acked_features: common.acked_features,
config,
acked_protocol_features: self.acked_protocol_features,
vu_num_queues: self.vu_num_queues,
..Default::default()
}
};
Ok(state)
}
pub fn snapshot<T>(&mut self, state: &T) -> std::result::Result<Snapshot, MigratableError>

View File

@@ -220,7 +220,7 @@ impl Net {
})
}
fn state(&self) -> State {
fn state(&self) -> std::result::Result<State, MigratableError> {
self.vu_common.state(&self.common, self.config)
}
}
@@ -425,7 +425,7 @@ impl Snapshottable for Net {
}
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
self.vu_common.snapshot(&self.state())
self.vu_common.snapshot(&self.state()?)
}
}
impl Transportable for Net {}