mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2025-12-26 22:48:17 +00:00
scsi: run rustfmt
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
This commit is contained in:
parent
4cd80cb968
commit
81f1b8d59a
@ -17,11 +17,13 @@ use thiserror::Error as ThisError;
|
||||
use vhost_user_backend::VhostUserDaemon;
|
||||
use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap};
|
||||
|
||||
use crate::scsi::emulation::{
|
||||
block_device::{BlockDevice, FileBackend, MediumRotationRate},
|
||||
target::EmulatedTarget,
|
||||
use crate::{
|
||||
scsi::emulation::{
|
||||
block_device::{BlockDevice, FileBackend, MediumRotationRate},
|
||||
target::EmulatedTarget,
|
||||
},
|
||||
vhu_scsi::VhostUserScsiBackend,
|
||||
};
|
||||
use crate::vhu_scsi::VhostUserScsiBackend;
|
||||
|
||||
#[derive(Debug, ThisError)]
|
||||
enum Error {
|
||||
|
||||
@ -684,7 +684,7 @@ impl<T: BlockDeviceBackend> LogicalUnit for BlockDevice<T> {
|
||||
return Ok(CmdOutput::check_condition(sense::INVALID_FIELD_IN_CDB));
|
||||
}
|
||||
ParseOpcodeResult::Invalid => {
|
||||
warn!("Reporting that we don't support command {:#2x}. It might be worth adding.", opcode);
|
||||
warn!("Reporting that we don't support command {opcode:#2x}. It might be worth adding.");
|
||||
one_command_not_supported(data_in).map_err(CmdError::DataIn)?;
|
||||
}
|
||||
},
|
||||
@ -701,7 +701,7 @@ impl<T: BlockDeviceBackend> LogicalUnit for BlockDevice<T> {
|
||||
timeout_descriptor(data_in).map_err(CmdError::DataIn)?;
|
||||
}
|
||||
} else {
|
||||
warn!("Reporting that we don't support command {:#2x}/{:#2x}. It might be worth adding.", opcode, sa);
|
||||
warn!("Reporting that we don't support command {opcode:#2x}/{sa:#2x}. It might be worth adding.");
|
||||
one_command_not_supported(data_in).map_err(CmdError::DataIn)?;
|
||||
}
|
||||
}
|
||||
@ -710,7 +710,7 @@ impl<T: BlockDeviceBackend> LogicalUnit for BlockDevice<T> {
|
||||
// think an invalid opcode is one for which our implementation
|
||||
// "does not implement service actions", so we say invalid field in
|
||||
// CDB
|
||||
warn!("Reporting that we don't support command {:#2x}/{:#2x}. It might be worth adding.", opcode, sa);
|
||||
warn!("Reporting that we don't support command {opcode:#2x}/{sa:#2x}. It might be worth adding.");
|
||||
return Ok(CmdOutput::check_condition(sense::INVALID_FIELD_IN_CDB));
|
||||
}
|
||||
}
|
||||
@ -736,12 +736,12 @@ impl<T: BlockDeviceBackend> LogicalUnit for BlockDevice<T> {
|
||||
timeout_descriptor(data_in).map_err(CmdError::DataIn)?;
|
||||
}
|
||||
} else {
|
||||
warn!("Reporting that we don't support command {:#2x}/{:#2x}. It might be worth adding.", opcode, sa);
|
||||
warn!("Reporting that we don't support command {opcode:#2x}/{sa:#2x}. It might be worth adding.");
|
||||
one_command_not_supported(data_in).map_err(CmdError::DataIn)?;
|
||||
}
|
||||
}
|
||||
ParseOpcodeResult::Invalid => {
|
||||
warn!("Reporting that we don't support command {:#2x}[/{:#2x}]. It might be worth adding.", opcode, sa);
|
||||
warn!("Reporting that we don't support command {opcode:#2x}[/{sa:#2x}]. It might be worth adding.");
|
||||
one_command_not_supported(data_in).map_err(CmdError::DataIn)?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::io::{Read, Write};
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
io::{Read, Write},
|
||||
};
|
||||
|
||||
use log::error;
|
||||
|
||||
|
||||
@ -2,9 +2,10 @@
|
||||
|
||||
//! Tests for stuff shared between commands.
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use std::io::ErrorKind;
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
|
||||
use super::{do_command_fail, test_image};
|
||||
use crate::scsi::{
|
||||
emulation::{block_device::BlockDevice, target::EmulatedTarget},
|
||||
|
||||
@ -1,18 +1,19 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
|
||||
|
||||
use core::slice;
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io::{self, ErrorKind};
|
||||
use std::mem;
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
io::{self, ErrorKind},
|
||||
mem,
|
||||
};
|
||||
|
||||
use log::{debug, error, info, warn};
|
||||
use vhost::vhost_user::{VhostUserProtocolFeatures, VhostUserVirtioFeatures};
|
||||
use vhost_user_backend::{VhostUserBackendMut, VringRwLock, VringT};
|
||||
use virtio_bindings::virtio_scsi::{virtio_scsi_config, virtio_scsi_event};
|
||||
use virtio_bindings::{
|
||||
virtio_config::VIRTIO_F_VERSION_1,
|
||||
virtio_ring::{VIRTIO_RING_F_EVENT_IDX, VIRTIO_RING_F_INDIRECT_DESC},
|
||||
virtio_scsi::VIRTIO_SCSI_F_HOTPLUG,
|
||||
virtio_scsi::{virtio_scsi_config, virtio_scsi_event, VIRTIO_SCSI_F_HOTPLUG},
|
||||
};
|
||||
use virtio_queue::QueueOwnedT;
|
||||
use vm_memory::{GuestAddressSpace, GuestMemoryAtomic, GuestMemoryLoadGuard, GuestMemoryMmap};
|
||||
@ -21,11 +22,12 @@ use vmm_sys_util::{
|
||||
eventfd::{EventFd, EFD_NONBLOCK},
|
||||
};
|
||||
|
||||
use crate::scsi::Target;
|
||||
use crate::virtio::CDB_SIZE;
|
||||
use crate::{
|
||||
scsi::{self, CmdError, TaskAttr},
|
||||
virtio::{self, Request, RequestParseError, Response, ResponseCode, VirtioScsiLun, SENSE_SIZE},
|
||||
scsi::{self, CmdError, Target, TaskAttr},
|
||||
virtio::{
|
||||
self, Request, RequestParseError, Response, ResponseCode, VirtioScsiLun, CDB_SIZE,
|
||||
SENSE_SIZE,
|
||||
},
|
||||
};
|
||||
|
||||
const REQUEST_QUEUE: u16 = 2;
|
||||
@ -92,7 +94,8 @@ impl VhostUserScsiBackend {
|
||||
2 => TaskAttr::HeadOfQueue,
|
||||
3 => TaskAttr::Aca,
|
||||
_ => {
|
||||
// virtio-scsi spec allows us to map any task attr to simple, presumably
|
||||
// virtio-scsi spec allows us to map any task attr to simple,
|
||||
// presumably
|
||||
// including future ones
|
||||
warn!("Unknown task attr: {}", r.task_attr);
|
||||
TaskAttr::Simple
|
||||
@ -117,8 +120,9 @@ impl VhostUserScsiBackend {
|
||||
}
|
||||
}
|
||||
Err(CmdError::CdbTooShort) => {
|
||||
// the CDB buffer is, by default, sized larger than any CDB we support; we don't
|
||||
// handle writes to config space (because QEMU doesn't let us), so there's no
|
||||
// the CDB buffer is, by default, sized larger than any CDB we support;
|
||||
// we don't handle writes to config space
|
||||
// (because QEMU doesn't let us), so there's no
|
||||
// way the guest can set it too small
|
||||
unreachable!();
|
||||
}
|
||||
@ -128,8 +132,9 @@ impl VhostUserScsiBackend {
|
||||
} else {
|
||||
error!("Error writing response to guest memory: {}", e);
|
||||
|
||||
// There's some chance the header and data in are on different descriptors,
|
||||
// and only the data in descriptor is bad, so let's at least try to write an
|
||||
// There's some chance the header and data in are on different
|
||||
// descriptors, and only the data in
|
||||
// descriptor is bad, so let's at least try to write an
|
||||
// error to the header
|
||||
Response::error(ResponseCode::Failure, body_writer.residual())
|
||||
}
|
||||
@ -427,7 +432,8 @@ mod tests {
|
||||
let mem = GuestMemoryAtomic::new(
|
||||
GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x1000_0000)]).unwrap(),
|
||||
);
|
||||
// The `build_desc_chain` function will populate the `NEXT` related flags and field.
|
||||
// The `build_desc_chain` function will populate the `NEXT` related flags and
|
||||
// field.
|
||||
let v = vec![
|
||||
RawDescriptor::from(Descriptor::new(0x10_0000, 0x100, 0, 0)), // request
|
||||
RawDescriptor::from(Descriptor::new(
|
||||
|
||||
@ -39,8 +39,7 @@ impl VirtioScsiLun {
|
||||
// bytes[2..3] is a normal SCSI single-level lun
|
||||
if (bytes[2] & Self::ADDRESS_METHOD_PATTERN) != Self::FLAT_SPACE_ADDRESSING_METHOD {
|
||||
error!(
|
||||
"Got LUN in unsupported format: {:#2x} {:#2x}. \
|
||||
Only flat space addressing is supported!",
|
||||
"Got LUN in unsupported format: {:#2x} {:#2x}. Only flat space addressing is supported!",
|
||||
bytes[2], bytes[3]
|
||||
);
|
||||
return None;
|
||||
@ -350,7 +349,8 @@ pub(crate) mod tests {
|
||||
let mem: GuestMemoryMmap =
|
||||
GuestMemoryMmap::from_ranges(&[(GuestAddress(0), 0x1000_0000)]).unwrap();
|
||||
|
||||
// The `build_desc_chain` function will populate the `NEXT` related flags and field.
|
||||
// The `build_desc_chain` function will populate the `NEXT` related flags and
|
||||
// field.
|
||||
let v = vec![
|
||||
// A device-writable request header descriptor.
|
||||
RawDescriptor::from(Descriptor::new(0x10_0000, 0x100, 0, 0)),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user