Skip to content

Commit 4d66f68

Browse files
committed
block: removed virtio flush feature
Signed-off-by: George Pisaltu <[email protected]>
1 parent a6004e3 commit 4d66f68

File tree

4 files changed

+7
-71
lines changed

4 files changed

+7
-71
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Changed Docker images repository from DockerHub to Amazon ECR.
88
- Fixed off-by-one error in virtio-block descriptor address validation.
9+
- Removed the `flush` capability from the block device
910

1011
## [0.24.0]
1112

src/devices/src/virtio/block/device.rs

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl Block {
162162
) -> io::Result<Block> {
163163
let disk_properties = DiskProperties::new(disk_image_path, is_disk_read_only)?;
164164

165-
let mut avail_features = (1u64 << VIRTIO_F_VERSION_1) | (1u64 << VIRTIO_BLK_F_FLUSH);
165+
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1;
166166

167167
if is_disk_read_only {
168168
avail_features |= 1u64 << VIRTIO_BLK_F_RO;
@@ -513,7 +513,7 @@ pub(crate) mod tests {
513513

514514
assert_eq!(block.device_type(), TYPE_BLOCK);
515515

516-
let features: u64 = (1u64 << VIRTIO_F_VERSION_1) | (1u64 << VIRTIO_BLK_F_FLUSH);
516+
let features: u64 = 1u64 << VIRTIO_F_VERSION_1;
517517

518518
assert_eq!(block.avail_features_by_page(0), features as u32);
519519
assert_eq!(block.avail_features_by_page(1), (features >> 32) as u32);
@@ -708,7 +708,7 @@ pub(crate) mod tests {
708708
let status_addr = GuestAddress(vq.dtable[2].addr.get());
709709

710710
// Currently only VIRTIO_BLK_T_IN, VIRTIO_BLK_T_OUT,
711-
// VIRTIO_BLK_T_FLUSH and VIRTIO_BLK_T_GET_ID are supported.
711+
// VIRTIO_BLK_T_GET_ID are supported.
712712
// Generate an unsupported request.
713713
let request_header = RequestHeader::new(42, 0);
714714
mem.write_obj::<RequestHeader>(request_header, request_type_addr)
@@ -907,50 +907,6 @@ pub(crate) mod tests {
907907
}
908908
}
909909

910-
#[test]
911-
fn test_flush() {
912-
let mut block = default_block();
913-
let mem = default_mem();
914-
let vq = VirtQueue::new(GuestAddress(0), &mem, 16);
915-
set_queue(&mut block, 0, vq.create_queue());
916-
block.activate(mem.clone()).unwrap();
917-
initialize_virtqueue(&vq);
918-
919-
let request_type_addr = GuestAddress(vq.dtable[0].addr.get());
920-
let status_addr = GuestAddress(vq.dtable[2].addr.get());
921-
922-
// Flush completes successfully without a data descriptor.
923-
{
924-
vq.dtable[0].next.set(2);
925-
926-
mem.write_obj::<u32>(VIRTIO_BLK_T_FLUSH, request_type_addr)
927-
.unwrap();
928-
929-
invoke_handler_for_queue_event(&mut block);
930-
assert_eq!(vq.used.idx.get(), 1);
931-
assert_eq!(vq.used.ring[0].get().id, 0);
932-
assert_eq!(vq.used.ring[0].get().len, 1);
933-
assert_eq!(mem.read_obj::<u32>(status_addr).unwrap(), VIRTIO_BLK_S_OK);
934-
}
935-
936-
// Flush completes successfully even with a data descriptor.
937-
{
938-
vq.used.idx.set(0);
939-
set_queue(&mut block, 0, vq.create_queue());
940-
vq.dtable[0].next.set(1);
941-
942-
mem.write_obj::<u32>(VIRTIO_BLK_T_FLUSH, request_type_addr)
943-
.unwrap();
944-
945-
invoke_handler_for_queue_event(&mut block);
946-
assert_eq!(vq.used.idx.get(), 1);
947-
assert_eq!(vq.used.ring[0].get().id, 0);
948-
// status byte length.
949-
assert_eq!(vq.used.ring[0].get().len, 1);
950-
assert_eq!(mem.read_obj::<u32>(status_addr).unwrap(), VIRTIO_BLK_S_OK);
951-
}
952-
}
953-
954910
#[test]
955911
fn test_get_device_id() {
956912
let mut block = default_block();

src/devices/src/virtio/block/request.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// found in the THIRD-PARTY file.
77

88
use std::convert::From;
9-
use std::io::{self, Seek, SeekFrom, Write};
9+
use std::io::{self, Seek, SeekFrom};
1010
use std::result;
1111

1212
use logger::{IncMetric, METRICS};
@@ -20,7 +20,6 @@ use super::{Error, SECTOR_SHIFT, SECTOR_SIZE};
2020
#[derive(Debug)]
2121
pub enum ExecuteError {
2222
BadRequest(Error),
23-
Flush(io::Error),
2423
Read(GuestMemoryError),
2524
Seek(io::Error),
2625
Write(GuestMemoryError),
@@ -31,7 +30,6 @@ impl ExecuteError {
3130
pub fn status(&self) -> u32 {
3231
match *self {
3332
ExecuteError::BadRequest(_) => VIRTIO_BLK_S_IOERR,
34-
ExecuteError::Flush(_) => VIRTIO_BLK_S_IOERR,
3533
ExecuteError::Read(_) => VIRTIO_BLK_S_IOERR,
3634
ExecuteError::Seek(_) => VIRTIO_BLK_S_IOERR,
3735
ExecuteError::Write(_) => VIRTIO_BLK_S_IOERR,
@@ -44,7 +42,6 @@ impl ExecuteError {
4442
pub enum RequestType {
4543
In,
4644
Out,
47-
Flush,
4845
GetDeviceID,
4946
Unsupported(u32),
5047
}
@@ -54,7 +51,6 @@ impl From<u32> for RequestType {
5451
match value {
5552
VIRTIO_BLK_T_IN => RequestType::In,
5653
VIRTIO_BLK_T_OUT => RequestType::Out,
57-
VIRTIO_BLK_T_FLUSH => RequestType::Flush,
5854
VIRTIO_BLK_T_GET_ID => RequestType::GetDeviceID,
5955
t => RequestType::Unsupported(t),
6056
}
@@ -137,11 +133,7 @@ impl Request {
137133
.ok_or(Error::DescriptorChainTooShort)?;
138134

139135
if !desc.has_next() {
140-
status_desc = desc;
141-
// Only flush requests are allowed to skip the data descriptor.
142-
if req.request_type != RequestType::Flush {
143-
return Err(Error::DescriptorChainTooShort);
144-
}
136+
return Err(Error::DescriptorChainTooShort);
145137
} else {
146138
data_desc = desc;
147139
status_desc = data_desc
@@ -214,13 +206,6 @@ impl Request {
214206
0
215207
})
216208
.map_err(ExecuteError::Write),
217-
RequestType::Flush => diskfile
218-
.flush()
219-
.map(|_| {
220-
METRICS.block.flush_count.inc();
221-
0
222-
})
223-
.map_err(ExecuteError::Flush),
224209
RequestType::GetDeviceID => {
225210
let disk_id = disk.image_id();
226211
if (self.data_len as usize) < disk_id.len() {
@@ -253,7 +238,6 @@ mod tests {
253238
let supported_request_types = vec![
254239
VIRTIO_BLK_T_IN,
255240
VIRTIO_BLK_T_OUT,
256-
VIRTIO_BLK_T_FLUSH,
257241
VIRTIO_BLK_T_GET_ID,
258242
];
259243

@@ -276,7 +260,6 @@ mod tests {
276260
fn test_request_type_from() {
277261
assert_eq!(RequestType::from(VIRTIO_BLK_T_IN), RequestType::In);
278262
assert_eq!(RequestType::from(VIRTIO_BLK_T_OUT), RequestType::Out);
279-
assert_eq!(RequestType::from(VIRTIO_BLK_T_FLUSH), RequestType::Flush);
280263
assert_eq!(
281264
RequestType::from(VIRTIO_BLK_T_GET_ID),
282265
RequestType::GetDeviceID
@@ -290,10 +273,6 @@ mod tests {
290273
ExecuteError::BadRequest(Error::InvalidOffset).status(),
291274
VIRTIO_BLK_S_IOERR
292275
);
293-
assert_eq!(
294-
ExecuteError::Flush(io::Error::from_raw_os_error(42)).status(),
295-
VIRTIO_BLK_S_IOERR
296-
);
297276
assert_eq!(
298277
ExecuteError::Read(GuestMemoryError::InvalidBackendAddress).status(),
299278
VIRTIO_BLK_S_IOERR

tests/integration_tests/build/test_coverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# this contains the frequency while on AMD it does not.
2424
# Checkout the cpuid crate. In the future other
2525
# differences may appear.
26-
COVERAGE_DICT = {"Intel": 85.44, "AMD": 84.77, "ARM": 83.6}
26+
COVERAGE_DICT = {"Intel": 85.44, "AMD": 84.77, "ARM": 83.55}
2727

2828
PROC_MODEL = proc.proc_type()
2929

0 commit comments

Comments
 (0)