backup/chunk_store: optionally log progress on creation

and enable it for the worker variants

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-06-02 13:27:03 +02:00 committed by Dietmar Maurer
parent b90036dadd
commit 2de4dc3a81
4 changed files with 12 additions and 8 deletions

View File

@ -54,11 +54,12 @@ pub(crate) fn do_create_datastore(
_lock: std::fs::File, _lock: std::fs::File,
mut config: SectionConfigData, mut config: SectionConfigData,
datastore: DataStoreConfig, datastore: DataStoreConfig,
worker: Option<&dyn crate::task::TaskState>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let path: PathBuf = datastore.path.clone().into(); let path: PathBuf = datastore.path.clone().into();
let backup_user = crate::backup::backup_user()?; let backup_user = crate::backup::backup_user()?;
let _store = ChunkStore::create(&datastore.name, path, backup_user.uid, backup_user.gid)?; let _store = ChunkStore::create(&datastore.name, path, backup_user.uid, backup_user.gid, worker)?;
config.set_data(&datastore.name, "datastore", &datastore)?; config.set_data(&datastore.name, "datastore", &datastore)?;
@ -157,7 +158,7 @@ pub fn create_datastore(
Some(datastore.name.to_string()), Some(datastore.name.to_string()),
auth_id, auth_id,
false, false,
move |_worker| do_create_datastore(lock, config, datastore), move |worker| do_create_datastore(lock, config, datastore, Some(&worker)),
) )
} }

View File

@ -190,7 +190,7 @@ pub fn create_datastore_disk(
bail!("datastore '{}' already exists.", datastore.name); bail!("datastore '{}' already exists.", datastore.name);
} }
crate::api2::config::datastore::do_create_datastore(lock, config, datastore)?; crate::api2::config::datastore::do_create_datastore(lock, config, datastore, Some(&worker))?;
} }
Ok(()) Ok(())

View File

@ -383,7 +383,7 @@ pub fn create_zpool(
bail!("datastore '{}' already exists.", datastore.name); bail!("datastore '{}' already exists.", datastore.name);
} }
crate::api2::config::datastore::do_create_datastore(lock, config, datastore)?; crate::api2::config::datastore::do_create_datastore(lock, config, datastore, Some(&worker))?;
} }
Ok(()) Ok(())

View File

@ -7,6 +7,7 @@ use std::os::unix::io::AsRawFd;
use proxmox::tools::fs::{CreateOptions, create_path, create_dir}; use proxmox::tools::fs::{CreateOptions, create_path, create_dir};
use crate::task_log;
use crate::tools; use crate::tools;
use crate::api2::types::GarbageCollectionStatus; use crate::api2::types::GarbageCollectionStatus;
@ -61,7 +62,7 @@ impl ChunkStore {
chunk_dir chunk_dir
} }
pub fn create<P>(name: &str, path: P, uid: nix::unistd::Uid, gid: nix::unistd::Gid) -> Result<Self, Error> pub fn create<P>(name: &str, path: P, uid: nix::unistd::Uid, gid: nix::unistd::Gid, worker: Option<&dyn TaskState>) -> Result<Self, Error>
where where
P: Into<PathBuf>, P: Into<PathBuf>,
{ {
@ -104,7 +105,9 @@ impl ChunkStore {
} }
let percentage = (i*100)/(64*1024); let percentage = (i*100)/(64*1024);
if percentage != last_percentage { if percentage != last_percentage {
// eprintln!("ChunkStore::create {}%", percentage); if let Some(worker) = worker {
task_log!(worker, "Chunkstore create: {}%", percentage)
}
last_percentage = percentage; last_percentage = percentage;
} }
} }
@ -461,7 +464,7 @@ fn test_chunk_store1() {
assert!(chunk_store.is_err()); assert!(chunk_store.is_err());
let user = nix::unistd::User::from_uid(nix::unistd::Uid::current()).unwrap().unwrap(); let user = nix::unistd::User::from_uid(nix::unistd::Uid::current()).unwrap().unwrap();
let chunk_store = ChunkStore::create("test", &path, user.uid, user.gid).unwrap(); let chunk_store = ChunkStore::create("test", &path, user.uid, user.gid, None).unwrap();
let (chunk, digest) = super::DataChunkBuilder::new(&[0u8, 1u8]).build().unwrap(); let (chunk, digest) = super::DataChunkBuilder::new(&[0u8, 1u8]).build().unwrap();
@ -472,7 +475,7 @@ fn test_chunk_store1() {
assert!(exists); assert!(exists);
let chunk_store = ChunkStore::create("test", &path, user.uid, user.gid); let chunk_store = ChunkStore::create("test", &path, user.uid, user.gid, None);
assert!(chunk_store.is_err()); assert!(chunk_store.is_err());
if let Err(_e) = std::fs::remove_dir_all(".testdir") { /* ignore */ } if let Err(_e) = std::fs::remove_dir_all(".testdir") { /* ignore */ }