From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] api2/tape/backup: wait indefinitely for lock in scheduled backup jobs
Date: Wed, 17 Mar 2021 14:38:10 +0100 [thread overview]
Message-ID: <20210317133810.24041-1-d.csapak@proxmox.com> (raw)
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 <d.csapak@proxmox.com>
---
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
next reply other threads:[~2021-03-17 13:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 13:38 Dominik Csapak [this message]
2021-03-18 5:53 ` Dietmar Maurer
2021-03-18 9:25 ` Dominik Csapak
2021-03-18 6:04 ` 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=20210317133810.24041-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