mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vhost_user_block: Correctly report number of used bytes
The number of bytes written into descriptors should be reported for `add_used()`. Here it is either just the status byte or also the size of serial ID for the block device. Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
@@ -20,7 +20,7 @@ use std::time::Instant;
|
|||||||
use std::{convert, io, process, result};
|
use std::{convert, io, process, result};
|
||||||
|
|
||||||
use block::qcow::{self, ImageType, QcowFile};
|
use block::qcow::{self, ImageType, QcowFile};
|
||||||
use block::{Request, VirtioBlockConfig, build_serial};
|
use block::{Request, RequestType, VirtioBlockConfig, build_serial};
|
||||||
use libc::EFD_NONBLOCK;
|
use libc::EFD_NONBLOCK;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use option_parser::{OptionParser, OptionParserError, Toggle};
|
use option_parser::{OptionParser, OptionParserError, Toggle};
|
||||||
@@ -128,36 +128,33 @@ impl VhostUserBlkThread {
|
|||||||
.pop_descriptor_chain(self.mem.memory())
|
.pop_descriptor_chain(self.mem.memory())
|
||||||
{
|
{
|
||||||
debug!("got an element in the queue");
|
debug!("got an element in the queue");
|
||||||
let len;
|
let len = match Request::parse(&mut desc_chain, None) {
|
||||||
match Request::parse(&mut desc_chain, None) {
|
|
||||||
Ok(mut request) => {
|
Ok(mut request) => {
|
||||||
debug!("element is a valid request");
|
debug!("element is a valid request");
|
||||||
request.set_writeback(self.writeback.load(Ordering::Acquire));
|
request.set_writeback(self.writeback.load(Ordering::Acquire));
|
||||||
let status = match request.execute(
|
let (status, len) = match request.execute(
|
||||||
&mut self.disk_image.lock().unwrap().deref_mut(),
|
&mut self.disk_image.lock().unwrap().deref_mut(),
|
||||||
self.disk_nsectors,
|
self.disk_nsectors,
|
||||||
desc_chain.memory(),
|
desc_chain.memory(),
|
||||||
&self.serial,
|
&self.serial,
|
||||||
) {
|
) {
|
||||||
Ok(l) => {
|
Ok(_) if request.request_type == RequestType::GetDeviceId => {
|
||||||
len = l;
|
(VIRTIO_BLK_S_OK as u8, self.serial.len() as u32 + 1)
|
||||||
VIRTIO_BLK_S_OK as u8
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
len = 1;
|
|
||||||
e.status()
|
|
||||||
}
|
}
|
||||||
|
Ok(l) => (VIRTIO_BLK_S_OK as u8, l + 1),
|
||||||
|
Err(e) => (e.status(), 1),
|
||||||
};
|
};
|
||||||
desc_chain
|
desc_chain
|
||||||
.memory()
|
.memory()
|
||||||
.write_obj(status, request.status_addr)
|
.write_obj(status, request.status_addr)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
len
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("failed to parse available descriptor chain: {err:?}");
|
error!("failed to parse available descriptor chain: {err:?}");
|
||||||
len = 0;
|
0
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
vring
|
vring
|
||||||
.get_queue_mut()
|
.get_queue_mut()
|
||||||
|
|||||||
Reference in New Issue
Block a user