From 109ccd300fcf82a9c3f9f19ba247f92f2b72bc64 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 9 Apr 2021 11:33:33 +0200 Subject: [PATCH] cleanup: move tape SCSI code to src/tape/drive/lto/sg_tape/ --- src/api2/tape/drive.rs | 2 +- src/api2/types/tape/drive.rs | 59 +++++++++++++++ src/tape/drive/lto/mod.rs | 4 +- src/tape/drive/lto/sg_tape.rs | 21 +++--- .../drive/{ => lto/sg_tape}/encryption.rs | 0 src/tape/drive/{ => lto/sg_tape}/mam.rs | 2 +- .../{ => lto/sg_tape}/tape_alert_flags.rs | 0 .../{ => lto/sg_tape}/volume_statistics.rs | 71 ++----------------- src/tape/drive/mod.rs | 13 +--- 9 files changed, 81 insertions(+), 91 deletions(-) rename src/tape/drive/{ => lto/sg_tape}/encryption.rs (100%) rename src/tape/drive/{ => lto/sg_tape}/mam.rs (99%) rename src/tape/drive/{ => lto/sg_tape}/tape_alert_flags.rs (100%) rename src/tape/drive/{ => lto/sg_tape}/volume_statistics.rs (78%) diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index e354f4c0..ca45bb69 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -47,6 +47,7 @@ use crate::{ LabelUuidMap, MamAttribute, LtoDriveAndMediaStatus, + Lp17VolumeStatistics, }, tape::restore::{ fast_catalog_restore, @@ -71,7 +72,6 @@ use crate::{ drive::{ TapeDriver, LtoTapeHandle, - Lp17VolumeStatistics, open_lto_tape_device, media_changer, required_media_changer, diff --git a/src/api2/types/tape/drive.rs b/src/api2/types/tape/drive.rs index d060acc5..ecc65088 100644 --- a/src/api2/types/tape/drive.rs +++ b/src/api2/types/tape/drive.rs @@ -223,3 +223,62 @@ pub struct LtoDriveAndMediaStatus { #[serde(skip_serializing_if="Option::is_none")] pub medium_wearout: Option, } + +#[api()] +/// Volume statistics from SCSI log page 17h +#[derive(Default, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub struct Lp17VolumeStatistics { + /// Volume mounts (thread count) + pub volume_mounts: u64, + /// Total data sets written + pub volume_datasets_written: u64, + /// Write retries + pub volume_recovered_write_data_errors: u64, + /// Total unrecovered write errors + pub volume_unrecovered_write_data_errors: u64, + /// Total suspended writes + pub volume_write_servo_errors: u64, + /// Total fatal suspended writes + pub volume_unrecovered_write_servo_errors: u64, + /// Total datasets read + pub volume_datasets_read: u64, + /// Total read retries + pub volume_recovered_read_errors: u64, + /// Total unrecovered read errors + pub volume_unrecovered_read_errors: u64, + /// Last mount unrecovered write errors + pub last_mount_unrecovered_write_errors: u64, + /// Last mount unrecovered read errors + pub last_mount_unrecovered_read_errors: u64, + /// Last mount bytes written + pub last_mount_bytes_written: u64, + /// Last mount bytes read + pub last_mount_bytes_read: u64, + /// Lifetime bytes written + pub lifetime_bytes_written: u64, + /// Lifetime bytes read + pub lifetime_bytes_read: u64, + /// Last load write compression ratio + pub last_load_write_compression_ratio: u64, + /// Last load read compression ratio + pub last_load_read_compression_ratio: u64, + /// Medium mount time + pub medium_mount_time: u64, + /// Medium ready time + pub medium_ready_time: u64, + /// Total native capacity + pub total_native_capacity: u64, + /// Total used native capacity + pub total_used_native_capacity: u64, + /// Write protect + pub write_protect: bool, + /// Volume is WORM + pub worm: bool, + /// Beginning of medium passes + pub beginning_of_medium_passes: u64, + /// Middle of medium passes + pub middle_of_tape_passes: u64, + /// Volume serial number + pub serial: String, +} diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs index e38b6e85..9dc85ac9 100644 --- a/src/tape/drive/lto/mod.rs +++ b/src/tape/drive/lto/mod.rs @@ -38,15 +38,13 @@ use crate::{ MamAttribute, LtoDriveAndMediaStatus, LtoTapeDrive, + Lp17VolumeStatistics, }, tape::{ TapeRead, TapeWrite, drive::{ TapeDriver, - TapeAlertFlags, - Lp17VolumeStatistics, - mam_extract_media_usage, }, file_formats::{ PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0, diff --git a/src/tape/drive/lto/sg_tape.rs b/src/tape/drive/lto/sg_tape.rs index 5ef77922..9f59b321 100644 --- a/src/tape/drive/lto/sg_tape.rs +++ b/src/tape/drive/lto/sg_tape.rs @@ -8,6 +8,18 @@ use anyhow::{bail, format_err, Error}; use endian_trait::Endian; use nix::fcntl::{fcntl, FcntlArg, OFlag}; +mod encryption; +pub use encryption::*; + +mod volume_statistics; +pub use volume_statistics::*; + +mod tape_alert_flags; +pub use tape_alert_flags::*; + +mod mam; +pub use mam::*; + use proxmox::{ sys::error::SysResult, tools::io::{ReadExt, WriteExt}, @@ -16,6 +28,7 @@ use proxmox::{ use crate::{ api2::types::{ MamAttribute, + Lp17VolumeStatistics, }, tape::{ BlockRead, @@ -25,14 +38,6 @@ use crate::{ BlockedWriter, BlockedReader, }, - drive::{ - TapeAlertFlags, - Lp17VolumeStatistics, - read_mam_attributes, - read_tape_alert_flags, - read_volume_statistics, - set_encryption, - }, }, tools::sgutils2::{ SgRaw, diff --git a/src/tape/drive/encryption.rs b/src/tape/drive/lto/sg_tape/encryption.rs similarity index 100% rename from src/tape/drive/encryption.rs rename to src/tape/drive/lto/sg_tape/encryption.rs diff --git a/src/tape/drive/mam.rs b/src/tape/drive/lto/sg_tape/mam.rs similarity index 99% rename from src/tape/drive/mam.rs rename to src/tape/drive/lto/sg_tape/mam.rs index cbb377d3..06b81850 100644 --- a/src/tape/drive/mam.rs +++ b/src/tape/drive/lto/sg_tape/mam.rs @@ -11,7 +11,7 @@ use crate::{ api2::types::MamAttribute, tools::sgutils2::SgRaw, tape::{ - drive::TapeAlertFlags, + drive::lto::TapeAlertFlags, }, }; diff --git a/src/tape/drive/tape_alert_flags.rs b/src/tape/drive/lto/sg_tape/tape_alert_flags.rs similarity index 100% rename from src/tape/drive/tape_alert_flags.rs rename to src/tape/drive/lto/sg_tape/tape_alert_flags.rs diff --git a/src/tape/drive/volume_statistics.rs b/src/tape/drive/lto/sg_tape/volume_statistics.rs similarity index 78% rename from src/tape/drive/volume_statistics.rs rename to src/tape/drive/lto/sg_tape/volume_statistics.rs index a6a11590..1996e466 100644 --- a/src/tape/drive/volume_statistics.rs +++ b/src/tape/drive/lto/sg_tape/volume_statistics.rs @@ -2,15 +2,14 @@ use std::io::Read; use std::os::unix::io::AsRawFd; use anyhow::{bail, format_err, Error}; -use serde::{Serialize, Deserialize}; use endian_trait::Endian; -use proxmox::{ - api::api, - tools::io::ReadExt, -}; +use proxmox::tools::io::ReadExt; -use crate::tools::sgutils2::SgRaw; +use crate::{ + api2::types::Lp17VolumeStatistics, + tools::sgutils2::SgRaw, +}; /// SCSI command to query volume statistics /// @@ -54,66 +53,6 @@ struct LpParameterHeader { parameter_len: u8, } - -#[api()] -/// Volume statistics from SCSI log page 17h -#[derive(Default, Serialize, Deserialize)] -#[serde(rename_all = "kebab-case")] -pub struct Lp17VolumeStatistics { - /// Volume mounts (thread count) - pub volume_mounts: u64, - /// Total data sets written - pub volume_datasets_written: u64, - /// Write retries - pub volume_recovered_write_data_errors: u64, - /// Total unrecovered write errors - pub volume_unrecovered_write_data_errors: u64, - /// Total suspended writes - pub volume_write_servo_errors: u64, - /// Total fatal suspended writes - pub volume_unrecovered_write_servo_errors: u64, - /// Total datasets read - pub volume_datasets_read: u64, - /// Total read retries - pub volume_recovered_read_errors: u64, - /// Total unrecovered read errors - pub volume_unrecovered_read_errors: u64, - /// Last mount unrecovered write errors - pub last_mount_unrecovered_write_errors: u64, - /// Last mount unrecovered read errors - pub last_mount_unrecovered_read_errors: u64, - /// Last mount bytes written - pub last_mount_bytes_written: u64, - /// Last mount bytes read - pub last_mount_bytes_read: u64, - /// Lifetime bytes written - pub lifetime_bytes_written: u64, - /// Lifetime bytes read - pub lifetime_bytes_read: u64, - /// Last load write compression ratio - pub last_load_write_compression_ratio: u64, - /// Last load read compression ratio - pub last_load_read_compression_ratio: u64, - /// Medium mount time - pub medium_mount_time: u64, - /// Medium ready time - pub medium_ready_time: u64, - /// Total native capacity - pub total_native_capacity: u64, - /// Total used native capacity - pub total_used_native_capacity: u64, - /// Write protect - pub write_protect: bool, - /// Volume is WORM - pub worm: bool, - /// Beginning of medium passes - pub beginning_of_medium_passes: u64, - /// Middle of medium passes - pub middle_of_tape_passes: u64, - /// Volume serial number - pub serial: String, -} - fn decode_volume_statistics(data: &[u8]) -> Result { diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs index 920ae89f..0d9e3db3 100644 --- a/src/tape/drive/mod.rs +++ b/src/tape/drive/mod.rs @@ -2,21 +2,9 @@ mod virtual_tape; -mod tape_alert_flags; -pub use tape_alert_flags::*; - -mod volume_statistics; -pub use volume_statistics::*; - -mod encryption; -pub use encryption::*; - mod lto; pub use lto::*; -mod mam; -pub use mam::*; - use std::os::unix::io::AsRawFd; use std::path::PathBuf; @@ -57,6 +45,7 @@ use crate::{ TapeWrite, TapeRead, MediaId, + drive::lto::TapeAlertFlags, file_formats::{ PROXMOX_BACKUP_MEDIA_LABEL_MAGIC_1_0, PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0,