From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 07/11] api2/tape/drive: wrap some api calls in run_drive_blocking_task
Date: Thu, 18 Feb 2021 15:40:26 +0100 [thread overview]
Message-ID: <20210218144030.16778-7-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210218144030.16778-1-d.csapak@proxmox.com>
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 | 64 +++++++++++++++++++++++-------------------
1 file changed, 35 insertions(+), 29 deletions(-)
diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs
index 5ee56441..eeda9e21 100644
--- a/src/api2/tape/drive.rs
+++ b/src/api2/tape/drive.rs
@@ -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(
--
2.20.1
next prev parent reply other threads:[~2021-02-18 14:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-18 14:40 [pbs-devel] [PATCH proxmox-backup 01/11] tape/drive: add test_device_path_lock Dominik Csapak
2021-02-18 14:40 ` [pbs-devel] [PATCH proxmox-backup 02/11] tape/drive: add get/set status functions Dominik Csapak
2021-02-18 14:40 ` [pbs-devel] [PATCH proxmox-backup 03/11] api2/tape/drive: add run_drive_worker wrapper Dominik Csapak
2021-02-18 14:40 ` [pbs-devel] [PATCH proxmox-backup 04/11] api2/tape/drive: use 'run_drive_worker' where possible Dominik Csapak
2021-02-18 14:40 ` [pbs-devel] [PATCH proxmox-backup 05/11] api2/tape/drive: add wrapper for tokio::task::spawn_blocking Dominik Csapak
2021-02-18 14:40 ` [pbs-devel] [PATCH proxmox-backup 06/11] api2/tape/drive: use run_drive_blocking_task where possible Dominik Csapak
2021-02-18 14:40 ` Dominik Csapak [this message]
2021-02-18 14:40 ` [pbs-devel] [PATCH proxmox-backup 08/11] api2/tape/changer: add drive state to changer status output Dominik Csapak
2021-02-18 14:40 ` [pbs-devel] [PATCH proxmox-backup 09/11] api2/tape/{backup, restore}, proxmox-tape: set device state Dominik Csapak
2021-02-18 14:40 ` [pbs-devel] [PATCH proxmox-backup 10/11] ui: tape: fix eslint warnings (trailing comma) Dominik Csapak
2021-02-18 14:40 ` [pbs-devel] [PATCH proxmox-backup 11/11] ui: tape/ChangerStatus: show the state of the drive Dominik Csapak
2021-02-18 15:06 ` Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210218144030.16778-7-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox