all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 1/2] api2/tape/drive: add missing locks for some drive actions
Date: Mon,  8 Feb 2021 11:10:08 +0100	[thread overview]
Message-ID: <20210208101009.2557-1-d.csapak@proxmox.com> (raw)

else a backup/restore can easily be disrupted

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/api2/tape/drive.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs
index 29321601..76f15df5 100644
--- a/src/api2/tape/drive.rs
+++ b/src/api2/tape/drive.rs
@@ -84,8 +84,11 @@ use crate::{
 pub async fn load_media(drive: String, label_text: String) -> Result<(), Error> {
 
     let (config, _digest) = config::drive::config()?;
+    let lock_guard = lock_tape_device(&config, &drive)?;
 
     tokio::task::spawn_blocking(move || {
+        let _lock_guard = lock_guard; // keep lock guard
+
         let (mut changer, _) = required_media_changer(&config, &drive)?;
         changer.load_media(&label_text)
     }).await?
@@ -110,8 +113,11 @@ pub async fn load_media(drive: String, label_text: String) -> Result<(), Error>
 pub async fn load_slot(drive: String, source_slot: u64) -> Result<(), Error> {
 
     let (config, _digest) = config::drive::config()?;
+    let lock_guard = lock_tape_device(&config, &drive)?;
 
     tokio::task::spawn_blocking(move || {
+        let _lock_guard = lock_guard; // keep lock guard
+
         let (mut changer, _) = required_media_changer(&config, &drive)?;
         changer.load_media_from_slot(source_slot)
     }).await?
@@ -138,8 +144,11 @@ pub async fn load_slot(drive: String, source_slot: u64) -> Result<(), Error> {
 pub async fn export_media(drive: String, label_text: String) -> Result<u64, Error> {
 
     let (config, _digest) = config::drive::config()?;
+    let lock_guard = lock_tape_device(&config, &drive)?;
 
     tokio::task::spawn_blocking(move || {
+        let _lock_guard = lock_guard; // keep lock guard
+
         let (mut changer, changer_name) = required_media_changer(&config, &drive)?;
         match changer.export_media(&label_text)? {
             Some(slot) => Ok(slot),
@@ -170,8 +179,11 @@ pub async fn unload(
 ) -> Result<(), Error> {
 
     let (config, _digest) = config::drive::config()?;
+    let lock_guard = lock_tape_device(&config, &drive)?;
 
     tokio::task::spawn_blocking(move || {
+        let _lock_guard = lock_guard; // keep lock guard
+
         let (mut changer, _) = required_media_changer(&config, &drive)?;
         changer.unload_media(target_slot)
     }).await?
-- 
2.20.1





             reply	other threads:[~2021-02-08 10:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-08 10:10 Dominik Csapak [this message]
2021-02-08 10:10 ` [pbs-devel] [PATCH proxmox-backup 2/2] ui: tape/window/LabelMedia: change to POST Dominik Csapak
2021-02-09  7:46 ` [pbs-devel] applied: [PATCH proxmox-backup 1/2] api2/tape/drive: add missing locks for some drive actions Dietmar Maurer

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=20210208101009.2557-1-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal