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 E86AA6B809 for ; Wed, 17 Mar 2021 14:38:13 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E65F42DF6E for ; Wed, 17 Mar 2021 14:38:13 +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 5DD492DF66 for ; Wed, 17 Mar 2021 14:38:13 +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 27DAF44730 for ; Wed, 17 Mar 2021 14:38:13 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Wed, 17 Mar 2021 14:38:10 +0100 Message-Id: <20210317133810.24041-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.184 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [backup.rs] Subject: [pbs-devel] [PATCH proxmox-backup] api2/tape/backup: wait indefinitely for lock in scheduled backup jobs 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: Wed, 17 Mar 2021 13:38:13 -0000 so that a user can schedule multiple backup jobs onto a single media pool without having to consider timing them apart this makes sense since we can backup multiple datastores onto the same media-set but can only specify one datastore per backup job Signed-off-by: Dominik Csapak --- src/api2/tape/backup.rs | 57 +++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index 0d42c31a..f29eb715 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -5,6 +5,7 @@ use anyhow::{bail, format_err, Error}; use serde_json::Value; use proxmox::{ + try_block, api::{ api, RpcEnvironment, @@ -177,8 +178,15 @@ pub fn do_tape_backup_job( let (drive_config, _digest) = config::drive::config()?; - // early check/lock before starting worker - let drive_lock = lock_tape_device(&drive_config, &setup.drive)?; + // for scheduled jobs we acquire the lock later in the worker + let drive_lock = if schedule.is_some() { + None + } else { + Some(lock_tape_device(&drive_config, &setup.drive)?) + }; + + let notify_user = setup.notify_user.as_ref().unwrap_or_else(|| &Userid::root_userid()); + let email = lookup_user_email(notify_user); let upid_str = WorkerTask::new_thread( &worker_type, @@ -186,26 +194,37 @@ pub fn do_tape_backup_job( auth_id.clone(), false, move |worker| { - let _drive_lock = drive_lock; // keep lock guard - - set_tape_device_state(&setup.drive, &worker.upid().to_string())?; job.start(&worker.upid().to_string())?; + let mut drive_lock = drive_lock; + + let (job_result, summary) = match try_block!({ + if schedule.is_some() { + // for scheduled tape backup jobs, we wait indefinitely for the lock + task_log!(worker, "waiting for drive lock..."); + loop { + if let Ok(lock) = lock_tape_device(&drive_config, &setup.drive) { + drive_lock = Some(lock); + break; + } // ignore errors + + worker.check_abort()?; + } + } + set_tape_device_state(&setup.drive, &worker.upid().to_string())?; - task_log!(worker,"Starting tape backup job '{}'", job_id); - if let Some(event_str) = schedule { - task_log!(worker,"task triggered by schedule '{}'", event_str); - } - - let notify_user = setup.notify_user.as_ref().unwrap_or_else(|| &Userid::root_userid()); - let email = lookup_user_email(notify_user); + task_log!(worker,"Starting tape backup job '{}'", job_id); + if let Some(event_str) = schedule { + task_log!(worker,"task triggered by schedule '{}'", event_str); + } - let (job_result, summary) = match backup_worker( - &worker, - datastore, - &pool_config, - &setup, - email.clone(), - ) { + backup_worker( + &worker, + datastore, + &pool_config, + &setup, + email.clone(), + ) + }) { Ok(summary) => (Ok(()), summary), Err(err) => (Err(err), Default::default()), }; -- 2.20.1