mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-20 23:11:16 +00:00
vm-virtio: Add helpers to update queue indexes
In anticipation for adding snapshot/restore support to virtio devices, this commit introduces two new helpers updating the available and used indexes of a queue, relying on the guest memory. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
fd45e94510
commit
12fec55064
@ -648,6 +648,46 @@ impl Queue {
|
|||||||
pub fn go_to_previous_position(&mut self) {
|
pub fn go_to_previous_position(&mut self) {
|
||||||
self.next_avail -= Wrapping(1);
|
self.next_avail -= Wrapping(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get latest index from available ring.
|
||||||
|
pub fn update_avail_index_from_memory(&mut self, mem: &GuestMemoryMmap) {
|
||||||
|
let index_addr = match mem.checked_offset(self.avail_ring, 2) {
|
||||||
|
Some(ret) => ret,
|
||||||
|
None => {
|
||||||
|
error!("Invalid offset 0x{:x}", self.avail_ring.raw_value() + 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let next_avail: u16 = match mem.read_obj::<u16>(index_addr) {
|
||||||
|
Ok(ret) => ret,
|
||||||
|
Err(e) => {
|
||||||
|
error!("Couldn't read `idx` field from memory: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
self.next_avail = Wrapping(next_avail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get latest index from used ring.
|
||||||
|
pub fn update_used_index_from_memory(&mut self, mem: &GuestMemoryMmap) {
|
||||||
|
let index_addr = match mem.checked_offset(self.used_ring, 2) {
|
||||||
|
Some(ret) => ret,
|
||||||
|
None => {
|
||||||
|
error!("Invalid offset 0x{:x}", self.used_ring.raw_value() + 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let next_used: u16 = match mem.read_obj::<u16>(index_addr) {
|
||||||
|
Ok(ret) => ret,
|
||||||
|
Err(e) => {
|
||||||
|
error!("Couldn't read `idx` field from memory: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
self.next_used = Wrapping(next_used);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user