tape: cleanup LinuxDriveStatus - make density optional

This commit is contained in:
Dietmar Maurer 2020-12-29 09:10:30 +01:00
parent 0993923ed5
commit afb0220642
2 changed files with 28 additions and 16 deletions

View File

@ -117,8 +117,6 @@ pub struct MamAttribute {
#[api()] #[api()]
#[derive(Serialize,Deserialize,Copy,Clone,Debug)] #[derive(Serialize,Deserialize,Copy,Clone,Debug)]
pub enum TapeDensity { pub enum TapeDensity {
/// No tape loaded
None,
/// LTO1 /// LTO1
LTO1, LTO1,
/// LTO2 /// LTO2
@ -144,7 +142,6 @@ impl TryFrom<u8> for TapeDensity {
fn try_from(value: u8) -> Result<Self, Self::Error> { fn try_from(value: u8) -> Result<Self, Self::Error> {
let density = match value { let density = match value {
0x00 => TapeDensity::None,
0x40 => TapeDensity::LTO1, 0x40 => TapeDensity::LTO1,
0x42 => TapeDensity::LTO2, 0x42 => TapeDensity::LTO2,
0x44 => TapeDensity::LTO3, 0x44 => TapeDensity::LTO3,
@ -164,23 +161,30 @@ impl TryFrom<u8> for TapeDensity {
properties: { properties: {
density: { density: {
type: TapeDensity, type: TapeDensity,
optional: true,
}, },
}, },
)] )]
#[derive(Serialize,Deserialize)] #[derive(Serialize,Deserialize)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
/// Drive/Media status for Linux SCSI drives. /// Drive/Media status for Linux SCSI drives.
///
/// Media related data is optional - only set if there is a medium
/// loaded.
pub struct LinuxDriveAndMediaStatus { pub struct LinuxDriveAndMediaStatus {
/// Block size (0 is variable size) /// Block size (0 is variable size)
pub blocksize: u32, pub blocksize: u32,
/// Tape density /// Tape density
pub density: TapeDensity, #[serde(skip_serializing_if="Option::is_none")]
pub density: Option<TapeDensity>,
/// Status flags /// Status flags
pub status: String, pub status: String,
/// Current file number /// Current file number
pub file_number: i32, #[serde(skip_serializing_if="Option::is_none")]
pub file_number: Option<u32>,
/// Current block number /// Current block number
pub block_number: i32, #[serde(skip_serializing_if="Option::is_none")]
pub block_number: Option<u32>,
/// Medium Manufacture Date (epoch) /// Medium Manufacture Date (epoch)
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
pub manufactured: Option<i64>, pub manufactured: Option<i64>,

View File

@ -41,10 +41,10 @@ use crate::{
#[derive(Debug)] #[derive(Debug)]
pub struct LinuxDriveStatus { pub struct LinuxDriveStatus {
pub blocksize: u32, pub blocksize: u32,
pub density: TapeDensity,
pub status: GMTStatusFlags, pub status: GMTStatusFlags,
pub file_number: i32, pub density: Option<TapeDensity>,
pub block_number: i32, pub file_number: Option<u32>,
pub block_number: Option<u32>,
} }
impl LinuxDriveStatus { impl LinuxDriveStatus {
@ -244,8 +244,6 @@ impl LinuxTapeHandle {
bail!("MTIOCGET failed - {}", err); bail!("MTIOCGET failed - {}", err);
} }
println!("{:?}", status);
let gmt = GMTStatusFlags::from_bits_truncate(status.mt_gstat); let gmt = GMTStatusFlags::from_bits_truncate(status.mt_gstat);
let blocksize; let blocksize;
@ -258,14 +256,24 @@ impl LinuxTapeHandle {
let density = ((status.mt_dsreg & MT_ST_DENSITY_MASK) >> MT_ST_DENSITY_SHIFT) as u8; let density = ((status.mt_dsreg & MT_ST_DENSITY_MASK) >> MT_ST_DENSITY_SHIFT) as u8;
let density = TapeDensity::try_from(density)?;
Ok(LinuxDriveStatus { Ok(LinuxDriveStatus {
blocksize, blocksize,
density,
status: gmt, status: gmt,
file_number: status.mt_fileno, density: if density != 0 {
block_number: status.mt_blkno, Some(TapeDensity::try_from(density)?)
} else {
None
},
file_number: if status.mt_fileno > 0 {
Some(status.mt_fileno as u32)
} else {
None
},
block_number: if status.mt_blkno > 0 {
Some(status.mt_blkno as u32)
} else {
None
},
}) })
} }