reader: acquire shared flock on open snapshot

...to avoid it being forgotten or pruned while in use.

Update lock error message for deletions to be consistent.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2020-10-14 14:16:32 +02:00 committed by Dietmar Maurer
parent 7d6c4c39e9
commit 238a872d1f
2 changed files with 15 additions and 6 deletions

View File

@ -17,6 +17,7 @@ use crate::tools;
use crate::config::acl::{PRIV_DATASTORE_READ, PRIV_DATASTORE_BACKUP}; use crate::config::acl::{PRIV_DATASTORE_READ, PRIV_DATASTORE_BACKUP};
use crate::config::cached_user_info::CachedUserInfo; use crate::config::cached_user_info::CachedUserInfo;
use crate::api2::helpers; use crate::api2::helpers;
use crate::tools::fs::lock_dir_noblock_shared;
mod environment; mod environment;
use environment::*; use environment::*;
@ -98,6 +99,11 @@ fn upgrade_to_backup_reader_protocol(
} }
} }
let _guard = lock_dir_noblock_shared(
&datastore.snapshot_path(&backup_dir),
"snapshot",
"locked by another operation")?;
let path = datastore.base_path(); let path = datastore.base_path();
//let files = BackupInfo::list_files(&path, &backup_dir)?; //let files = BackupInfo::list_files(&path, &backup_dir)?;
@ -146,11 +152,14 @@ fn upgrade_to_backup_reader_protocol(
use futures::future::Either; use futures::future::Either;
futures::future::select(req_fut, abort_future) futures::future::select(req_fut, abort_future)
.map(|res| match res { .map(move |res| {
let _guard = _guard;
match res {
Either::Left((Ok(res), _)) => Ok(res), Either::Left((Ok(res), _)) => Ok(res),
Either::Left((Err(err), _)) => Err(err), Either::Left((Err(err), _)) => Err(err),
Either::Right((Ok(res), _)) => Ok(res), Either::Right((Ok(res), _)) => Ok(res),
Either::Right((Err(err), _)) => Err(err), Either::Right((Err(err), _)) => Err(err),
}
}) })
.map_ok(move |_| env.log("reader finished successfully")) .map_ok(move |_| env.log("reader finished successfully"))
})?; })?;

View File

@ -227,7 +227,7 @@ impl DataStore {
let _guard; let _guard;
if !force { if !force {
_guard = lock_dir_noblock(&full_path, "snapshot", "possibly running or used as base")?; _guard = lock_dir_noblock(&full_path, "snapshot", "possibly running or in use")?;
} }
log::info!("removing backup snapshot {:?}", full_path); log::info!("removing backup snapshot {:?}", full_path);