api: tape restore: avoid throwing away ns mapping, use target_store instead

avoid assembling a hash mapping of namespaces only to not use it,
i.e., throw it away then anyway

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-06-05 16:59:55 +02:00
parent f31e32a006
commit 5a2e6ccf77
1 changed files with 23 additions and 28 deletions

View File

@ -698,9 +698,9 @@ fn restore_list_worker(
.collect() .collect()
}; };
for (store, snapshot, _ns, _) in snapshots.iter() { for (store, snapshot, _ns, _) in snapshots.iter() {
let datastore = match store_map.get_targets(store, &ns) { let datastore = match store_map.target_store(store) {
Some(store, _) => store, Some(store) => store,
_ => bail!("unexpected error"), // we already checked those None => bail!("unexpected error"), // we already checked those
}; };
let (media_id, file_num) = let (media_id, file_num) =
if let Some((media_uuid, file_num)) = catalog.lookup_snapshot(store, &snapshot) { if let Some((media_uuid, file_num)) = catalog.lookup_snapshot(store, &snapshot) {
@ -773,9 +773,7 @@ fn restore_list_worker(
BTreeMap::new(); BTreeMap::new();
for (source_datastore, chunks) in datastore_chunk_map.into_iter() { for (source_datastore, chunks) in datastore_chunk_map.into_iter() {
let (datastore, _) = store_map let datastore = store_map.target_store(&source_datastore).ok_or_else(|| {
.get_targets(&source_datastore, &Default::default())
.ok_or_else(|| {
format_err!("could not find mapping for source datastore: {source_datastore}") format_err!("could not find mapping for source datastore: {source_datastore}")
})?; })?;
for digest in chunks.into_iter() { for digest in chunks.into_iter() {
@ -1051,9 +1049,8 @@ fn restore_snapshots_to_tmpdir(
let mut decoder = pxar::decoder::sync::Decoder::from_std(reader)?; let mut decoder = pxar::decoder::sync::Decoder::from_std(reader)?;
let target_datastore = let target_datastore = match store_map.target_store(&source_datastore) {
match store_map.get_targets(&source_datastore, &Default::default()) { Some(datastore) => datastore,
Some((datastore, _)) => datastore,
None => { None => {
task_warn!( task_warn!(
worker, worker,
@ -1137,9 +1134,7 @@ fn restore_file_chunk_map(
"File {nr}: chunk archive for datastore '{source_datastore}'", "File {nr}: chunk archive for datastore '{source_datastore}'",
); );
let (datastore, _) = store_map let datastore = store_map.target_store(&source_datastore).ok_or_else(|| {
.get_targets(&source_datastore, &Default::default())
.ok_or_else(|| {
format_err!("unexpected chunk archive for store: {source_datastore}") format_err!("unexpected chunk archive for store: {source_datastore}")
})?; })?;
@ -1381,7 +1376,7 @@ fn restore_archive<'a>(
let (backup_ns, backup_dir) = parse_ns_and_snapshot(&snapshot)?; let (backup_ns, backup_dir) = parse_ns_and_snapshot(&snapshot)?;
if let Some((store_map, restore_owner)) = target.as_ref() { if let Some((store_map, restore_owner)) = target.as_ref() {
if let Some((datastore, _)) = store_map.get_targets(&datastore_name, &backup_ns) { if let Some(datastore) = store_map.target_store(&datastore_name) {
check_and_create_namespaces( check_and_create_namespaces(
&user_info, &user_info,
&datastore, &datastore,
@ -1470,20 +1465,20 @@ fn restore_archive<'a>(
); );
let datastore = target let datastore = target
.as_ref() .as_ref()
.and_then(|t| t.0.get_targets(&source_datastore, &Default::default())); .and_then(|t| t.0.target_store(&source_datastore));
if datastore.is_some() || target.is_none() { if datastore.is_some() || target.is_none() {
let checked_chunks = checked_chunks_map let checked_chunks = checked_chunks_map
.entry( .entry(
datastore datastore
.as_ref() .as_ref()
.map(|(d, _)| d.name()) .map(|d| d.name())
.unwrap_or("_unused_") .unwrap_or("_unused_")
.to_string(), .to_string(),
) )
.or_insert(HashSet::new()); .or_insert(HashSet::new());
let chunks = if let Some((datastore, _)) = datastore { let chunks = if let Some(datastore) = datastore {
restore_chunk_archive( restore_chunk_archive(
worker.clone(), worker.clone(),
reader, reader,