[pbs-devel] [PATCH proxmox-backup 2/4] tape: add drive activity to drive status api

Dominik Csapak d.csapak at proxmox.com
Mon May 13 12:49:24 CEST 2024


and show it in the gui for single drives. Adds the known values for the
activity to the UI.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 pbs-api-types/src/tape/drive.rs |  3 +++
 pbs-tape/src/sg_tape.rs         |  5 ++++-
 www/Utils.js                    | 29 +++++++++++++++++++++++++++++
 www/tape/DriveStatus.js         |  4 ++++
 4 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/pbs-api-types/src/tape/drive.rs b/pbs-api-types/src/tape/drive.rs
index de569980a..caa6b3b3e 100644
--- a/pbs-api-types/src/tape/drive.rs
+++ b/pbs-api-types/src/tape/drive.rs
@@ -216,6 +216,9 @@ pub struct LtoDriveAndMediaStatus {
     /// Estimated tape wearout factor (assuming max. 16000 end-to-end passes)
     #[serde(skip_serializing_if = "Option::is_none")]
     pub medium_wearout: Option<f64>,
+    /// Current device activity
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub drive_activity: Option<DeviceActivity>,
 }
 
 #[api()]
diff --git a/pbs-tape/src/sg_tape.rs b/pbs-tape/src/sg_tape.rs
index 85be6b071..d185dd1ac 100644
--- a/pbs-tape/src/sg_tape.rs
+++ b/pbs-tape/src/sg_tape.rs
@@ -31,7 +31,8 @@ use proxmox_io::{ReadExt, WriteExt};
 use proxmox_sys::error::SysResult;
 
 use pbs_api_types::{
-    Lp17VolumeStatistics, LtoDriveAndMediaStatus, LtoTapeDrive, MamAttribute, TapeDensity,
+    DeviceActivity, Lp17VolumeStatistics, LtoDriveAndMediaStatus, LtoTapeDrive, MamAttribute,
+    TapeDensity,
 };
 
 use crate::linux_list_drives::open_lto_tape_device;
@@ -960,6 +961,7 @@ impl SgTape {
     pub fn get_drive_and_media_status(&mut self) -> Result<LtoDriveAndMediaStatus, Error> {
         let drive_status = self.read_drive_status()?;
 
+        let drive_activity = read_device_activity(&mut self.file).ok();
         let alert_flags = self
             .tape_alert_flags()
             .map(|flags| format!("{:?}", flags))
@@ -983,6 +985,7 @@ impl SgTape {
             medium_passes: None,
             medium_wearout: None,
             volume_mounts: None,
+            drive_activity,
         };
 
         if self.test_unit_ready().is_ok() {
diff --git a/www/Utils.js b/www/Utils.js
index 1d7351a32..df03a4c87 100644
--- a/www/Utils.js
+++ b/www/Utils.js
@@ -659,6 +659,9 @@ Ext.define('PBS.Utils', {
 	    if (key === 'bytes-read' || key === 'bytes-written') {
 		val = Proxmox.Utils.format_size(val);
 	    }
+	    if (key === 'drive-activity') {
+		val = PBS.Utils.renderDriveActivity(val);
+	    }
 	    list.push({ key: key, value: val });
 	}
 
@@ -692,6 +695,32 @@ Ext.define('PBS.Utils', {
 	}).show();
     },
 
+    tapeDriveActivities: {
+	'no-activity': gettext('No Activity'),
+	'cleaning': gettext('Cleaning'),
+	'loading': gettext('Loading'),
+	'unloading': gettext('Unloading'),
+	'other': gettext('Other Activity'),
+	'reading': gettext('Reading data'),
+	'writing': gettext('Writing data'),
+	'locating': gettext('Locating'),
+	'rewinding': gettext('Rewinding'),
+	'erasing': gettext('Erasing'),
+	'formatting': gettext('Formatting'),
+	'calibrating': gettext('Calibrating'),
+	'other-dt': gettext('Other DT Activity'),
+	'microcode-update': gettext('Updating Microcode'),
+	'reading-encrypted': gettext('Reading encrypted data'),
+	'writing-encrypted': gettext('Writing encrypted data'),
+    },
+
+    renderDriveActivity: function(value) {
+	if (!value) {
+	    return Proxmox.Utils.unknownText;
+	}
+	return PBS.Utils.tapeDriveActivities[value] ?? value;
+    },
+
     renderDriveState: function(value, md) {
 	if (!value) {
 	    return gettext('Idle');
diff --git a/www/tape/DriveStatus.js b/www/tape/DriveStatus.js
index 2c55fc97f..a392202ca 100644
--- a/www/tape/DriveStatus.js
+++ b/www/tape/DriveStatus.js
@@ -348,6 +348,10 @@ Ext.define('PBS.TapeManagement.DriveStatusGrid', {
 	    header: gettext('Compression'),
 	    renderer: Proxmox.Utils.format_boolean,
 	},
+	'drive-activity': {
+	    header: gettext('Drive Activity'),
+	    renderer: PBS.Utils.renderDriveActivity,
+	},
 	'file-number': {
 	    header: gettext('Tape Position'),
 	    renderer: function(value, mD, r, rI, cI, store) {
-- 
2.39.2





More information about the pbs-devel mailing list