]> git.proxmox.com Git - proxmox-backup.git/commitdiff
api2/tape/drive: wrap some api calls in run_drive_blocking_task
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 18 Feb 2021 14:40:26 +0000 (15:40 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 19 Feb 2021 09:14:08 +0000 (10:14 +0100)
those calls could also block, so we have to run them in a blocking
tokio task, as to not block the current thread

nice side effect is that we now also update the state for that
drive in those instances

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/api2/tape/drive.rs

index 5ee5644102eba5d696e665bd6b5182363c75aad1..eeda9e2156c4ea1819280c49cd2fe06465e4c9dc 100644 (file)
@@ -1014,16 +1014,18 @@ fn barcode_label_media_worker(
     },
 )]
 /// Read Cartridge Memory (Medium auxiliary memory attributes)
-pub fn cartridge_memory(drive: String) -> Result<Vec<MamAttribute>, Error> {
-
-    let (config, _digest) = config::drive::config()?;
-
-    let _lock_guard = lock_tape_device(&config, &drive)?;
-
-    let drive_config: LinuxTapeDrive = config.lookup("linux", &drive)?;
-    let mut handle = drive_config.open()?;
+pub async fn cartridge_memory(drive: String) -> Result<Vec<MamAttribute>, Error> {
+    run_drive_blocking_task(
+        drive.clone(),
+        "reading cartridge memory".to_string(),
+        move |config| {
+            let drive_config: LinuxTapeDrive = config.lookup("linux", &drive)?;
+            let mut handle = drive_config.open()?;
 
-    handle.cartridge_memory()
+            handle.cartridge_memory()
+        }
+    )
+    .await
 }
 
 #[api(
@@ -1039,16 +1041,18 @@ pub fn cartridge_memory(drive: String) -> Result<Vec<MamAttribute>, Error> {
     },
 )]
 /// Read Volume Statistics (SCSI log page 17h)
-pub fn volume_statistics(drive: String) -> Result<Lp17VolumeStatistics, Error> {
-
-    let (config, _digest) = config::drive::config()?;
-
-    let _lock_guard = lock_tape_device(&config, &drive)?;
-
-    let drive_config: LinuxTapeDrive = config.lookup("linux", &drive)?;
-    let mut handle = drive_config.open()?;
+pub async fn volume_statistics(drive: String) -> Result<Lp17VolumeStatistics, Error> {
+    run_drive_blocking_task(
+        drive.clone(),
+        "reading volume statistics".to_string(),
+        move |config| {
+            let drive_config: LinuxTapeDrive = config.lookup("linux", &drive)?;
+            let mut handle = drive_config.open()?;
 
-    handle.volume_statistics()
+            handle.volume_statistics()
+        }
+    )
+    .await
 }
 
 #[api(
@@ -1064,20 +1068,22 @@ pub fn volume_statistics(drive: String) -> Result<Lp17VolumeStatistics, Error> {
     },
 )]
 /// Get drive/media status
-pub fn status(drive: String) -> Result<LinuxDriveAndMediaStatus, Error> {
-
-    let (config, _digest) = config::drive::config()?;
-
-    let _lock_guard = lock_tape_device(&config, &drive)?;
-
-    let drive_config: LinuxTapeDrive = config.lookup("linux", &drive)?;
+pub async fn status(drive: String) -> Result<LinuxDriveAndMediaStatus, Error> {
+    run_drive_blocking_task(
+        drive.clone(),
+        "reading drive status".to_string(),
+        move |config| {
+            let drive_config: LinuxTapeDrive = config.lookup("linux", &drive)?;
 
-    // Note: use open_linux_tape_device, because this also works if no medium loaded
-    let file = open_linux_tape_device(&drive_config.path)?;
+            // Note: use open_linux_tape_device, because this also works if no medium loaded
+            let file = open_linux_tape_device(&drive_config.path)?;
 
-    let mut handle = LinuxTapeHandle::new(file);
+            let mut handle = LinuxTapeHandle::new(file);
 
-    handle.get_drive_and_media_status()
+            handle.get_drive_and_media_status()
+        }
+    )
+    .await
 }
 
 #[api(