From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 999B96B421 for ; Thu, 18 Feb 2021 15:41:05 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 04FFFF6D8 for ; Thu, 18 Feb 2021 15:40:35 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id E8EEBF64B for ; Thu, 18 Feb 2021 15:40:31 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B2CA144FE3 for ; Thu, 18 Feb 2021 15:40:31 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 18 Feb 2021 15:40:26 +0100 Message-Id: <20210218144030.16778-7-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210218144030.16778-1-d.csapak@proxmox.com> References: <20210218144030.16778-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.215 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 07/11] api2/tape/drive: wrap some api calls in run_drive_blocking_task X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Feb 2021 14:41:05 -0000 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 --- 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, 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, 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, Error> { }, )] /// Read Volume Statistics (SCSI log page 17h) -pub fn volume_statistics(drive: String) -> Result { - - 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 { + 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 { }, )] /// Get drive/media status -pub fn status(drive: String) -> Result { - - 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 { + 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