add verify_backup_dir_with_lock for callers already holding locks

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2020-10-20 10:08:24 +02:00 committed by Dietmar Maurer
parent 115d927c15
commit bcc2880461
1 changed files with 32 additions and 10 deletions

View File

@ -2,6 +2,7 @@ use std::collections::HashSet;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::sync::atomic::{Ordering, AtomicUsize}; use std::sync::atomic::{Ordering, AtomicUsize};
use std::time::Instant; use std::time::Instant;
use nix::dir::Dir;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
@ -284,12 +285,21 @@ pub fn verify_backup_dir(
worker: Arc<dyn TaskState + Send + Sync>, worker: Arc<dyn TaskState + Send + Sync>,
upid: UPID, upid: UPID,
) -> Result<bool, Error> { ) -> Result<bool, Error> {
let snap_lock = lock_dir_noblock_shared(
let _guard_res = lock_dir_noblock_shared(
&datastore.snapshot_path(&backup_dir), &datastore.snapshot_path(&backup_dir),
"snapshot", "snapshot",
"locked by another operation"); "locked by another operation");
if let Err(err) = _guard_res { match snap_lock {
Ok(snap_lock) => verify_backup_dir_with_lock(
datastore,
backup_dir,
verified_chunks,
corrupt_chunks,
worker,
upid,
snap_lock
),
Err(err) => {
task_log!( task_log!(
worker, worker,
"SKIPPED: verify {}:{} - could not acquire snapshot lock: {}", "SKIPPED: verify {}:{} - could not acquire snapshot lock: {}",
@ -297,9 +307,21 @@ pub fn verify_backup_dir(
backup_dir, backup_dir,
err, err,
); );
return Ok(true); Ok(true)
} }
}
}
/// See verify_backup_dir
pub fn verify_backup_dir_with_lock(
datastore: Arc<DataStore>,
backup_dir: &BackupDir,
verified_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
corrupt_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
worker: Arc<dyn TaskState + Send + Sync>,
upid: UPID,
_snap_lock: Dir,
) -> Result<bool, Error> {
let manifest = match datastore.load_manifest(&backup_dir) { let manifest = match datastore.load_manifest(&backup_dir) {
Ok((manifest, _)) => manifest, Ok((manifest, _)) => manifest,
Err(err) => { Err(err) => {