Skip to content

Commit 63ac63c

Browse files
author
Erik Schilling
committed
scsi: add support for SYNCHRONIZE CACHE(10)
While the command also allows syncing individual regions of a LUN, we do not support that here and simply sync the entire file. Signed-off-by: Erik Schilling <[email protected]>
1 parent c55bc71 commit 63ac63c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

crates/scsi/src/scsi/emulation/block_device.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,16 @@ impl<T: BlockDeviceBackend> LogicalUnit for BlockDevice<T> {
660660
}
661661
}
662662
}
663+
LunSpecificCommand::SynchronizeCache10 => {
664+
// While SCSI allows just syncing a range, we just sync the entire file
665+
match self.backend.sync() {
666+
Ok(()) => Ok(CmdOutput::ok()),
667+
Err(e) => {
668+
error!("Error syncing block device: {}", e);
669+
Ok(CmdOutput::check_condition(sense::TARGET_FAILURE))
670+
}
671+
}
672+
}
663673
}
664674
}
665675
}

crates/scsi/src/scsi/emulation/command.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ pub(crate) enum LunSpecificCommand {
197197
},
198198
RequestSense(SenseFormat),
199199
TestUnitReady,
200+
SynchronizeCache10,
200201
}
201202

202203
#[derive(Debug)]
@@ -218,6 +219,7 @@ pub(crate) enum CommandType {
218219
TestUnitReady,
219220
Write10,
220221
WriteSame16,
222+
SynchronizeCache10,
221223
}
222224

223225
pub(crate) const OPCODES: &[(CommandType, (u8, Option<u16>))] = &[
@@ -228,6 +230,7 @@ pub(crate) const OPCODES: &[(CommandType, (u8, Option<u16>))] = &[
228230
(CommandType::ReadCapacity10, (0x25, None)),
229231
(CommandType::Read10, (0x28, None)),
230232
(CommandType::Write10, (0x2a, None)),
233+
(CommandType::SynchronizeCache10, (0x35, None)),
231234
(CommandType::WriteSame16, (0x93, None)),
232235
(CommandType::ReadCapacity16, (0x9e, Some(0x10))),
233236
(CommandType::ReportLuns, (0xa0, None)),
@@ -444,6 +447,18 @@ impl CommandType {
444447
0b0000_0000,
445448
0b0000_0100,
446449
],
450+
Self::SynchronizeCache10 => &[
451+
0x53,
452+
0b0000_0010,
453+
0b1111_1111,
454+
0b1111_1111,
455+
0b1111_1111,
456+
0b1111_1111,
457+
0b0011_1111,
458+
0b1111_1111,
459+
0b1111_1111,
460+
0b0000_0100,
461+
],
447462
}
448463
}
449464
}
@@ -598,6 +613,11 @@ impl Cdb {
598613
naca: (cdb[15] & 0b0000_0100) != 0,
599614
})
600615
}
616+
CommandType::SynchronizeCache10 => Ok(Self {
617+
command: Command::LunSpecificCommand(LunSpecificCommand::SynchronizeCache10),
618+
allocation_length: None,
619+
naca: (cdb[9] & 0b0000_0100) != 0,
620+
}),
601621
CommandType::ReadCapacity10 => Ok(Self {
602622
command: Command::LunSpecificCommand(LunSpecificCommand::ReadCapacity10),
603623
allocation_length: None,

0 commit comments

Comments
 (0)