tape: changer: sg_pt: make extra scsi request for dvcid
some libraries cannot handle a request with volume tags and DVCID set at the same time. So we make 2 separate requests and merge them, since we want to keep the vendor/model/serial data. to not overcomplicate the code, add another special type to ElementType Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
9f5b57a348
commit
6c053ffc89
@ -265,13 +265,34 @@ pub fn transfer_medium<F: AsRawFd>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(u8)]
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
enum ElementType {
|
enum ElementType {
|
||||||
MediumTransport = 1,
|
MediumTransport,
|
||||||
Storage = 2,
|
Storage,
|
||||||
ImportExport = 3,
|
ImportExport,
|
||||||
DataTransfer = 4,
|
DataTransfer,
|
||||||
|
DataTransferWithDVCID,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ElementType {
|
||||||
|
fn byte1(&self) -> u8 {
|
||||||
|
let volume_tag_bit = 1u8 << 4;
|
||||||
|
match *self {
|
||||||
|
ElementType::MediumTransport => volume_tag_bit | 1,
|
||||||
|
ElementType::Storage => volume_tag_bit | 2,
|
||||||
|
ElementType::ImportExport => volume_tag_bit | 3,
|
||||||
|
ElementType::DataTransfer => volume_tag_bit | 4,
|
||||||
|
// some changers cannot get voltag + dvcid at the same time
|
||||||
|
ElementType::DataTransferWithDVCID => 4,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn byte6(&self) -> u8 {
|
||||||
|
match *self {
|
||||||
|
ElementType::DataTransferWithDVCID => 0b001, // Mixed=0,CurData=0,DVCID=1
|
||||||
|
_ => 0b000, // Mixed=0,CurData=0,DVCID=0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scsi_read_element_status_cdb(
|
fn scsi_read_element_status_cdb(
|
||||||
@ -283,15 +304,11 @@ fn scsi_read_element_status_cdb(
|
|||||||
|
|
||||||
let mut cmd = Vec::new();
|
let mut cmd = Vec::new();
|
||||||
cmd.push(0xB8); // READ ELEMENT STATUS (B8h)
|
cmd.push(0xB8); // READ ELEMENT STATUS (B8h)
|
||||||
cmd.push(1u8<<4 | (element_type as u8)); // volume tags and given type
|
cmd.push(element_type.byte1());
|
||||||
cmd.extend(&start_element_address.to_be_bytes());
|
cmd.extend(&start_element_address.to_be_bytes());
|
||||||
|
|
||||||
cmd.extend(&number_of_elements.to_be_bytes());
|
cmd.extend(&number_of_elements.to_be_bytes());
|
||||||
let byte6 = match element_type {
|
cmd.push(element_type.byte6());
|
||||||
ElementType::DataTransfer => 0b001, // Mixed=0,CurData=0,DVCID=1
|
|
||||||
_ => 0b000, // Mixed=0,CurData=0,DVCID=0
|
|
||||||
};
|
|
||||||
cmd.push(byte6);
|
|
||||||
cmd.extend(&allocation_len.to_be_bytes()[1..4]);
|
cmd.extend(&allocation_len.to_be_bytes()[1..4]);
|
||||||
cmd.push(0);
|
cmd.push(0);
|
||||||
cmd.push(0);
|
cmd.push(0);
|
||||||
@ -385,6 +402,21 @@ pub fn read_element_status<F: AsRawFd>(file: &mut F) -> Result<MtxStatus, Error>
|
|||||||
let page = get_element(&inquiry, &mut sg_raw, ElementType::DataTransfer, allocation_len, false)?;
|
let page = get_element(&inquiry, &mut sg_raw, ElementType::DataTransfer, allocation_len, false)?;
|
||||||
drives.extend(page.drives);
|
drives.extend(page.drives);
|
||||||
|
|
||||||
|
// get the serial + vendor + model,
|
||||||
|
// some changer require this to be an extra scsi command
|
||||||
|
let page = get_element(&inquiry, &mut sg_raw, ElementType::DataTransferWithDVCID, allocation_len, false)?;
|
||||||
|
// should be in same order and same count, but be on the safe side.
|
||||||
|
// there should not be too many drives normally
|
||||||
|
for drive in drives.iter_mut() {
|
||||||
|
for drive2 in &page.drives {
|
||||||
|
if drive2.element_address == drive.element_address {
|
||||||
|
drive.vendor = drive2.vendor.clone();
|
||||||
|
drive.model = drive2.model.clone();
|
||||||
|
drive.drive_serial_number = drive2.drive_serial_number.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let page = get_element(&inquiry, &mut sg_raw, ElementType::MediumTransport, allocation_len, false)?;
|
let page = get_element(&inquiry, &mut sg_raw, ElementType::MediumTransport, allocation_len, false)?;
|
||||||
transports.extend(page.transports);
|
transports.extend(page.transports);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user