tape: further PoolWriter cleanups
This commit is contained in:
parent
c503ea7045
commit
66e42bec05
@ -3,10 +3,7 @@ use std::path::Path;
|
|||||||
|
|
||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
|
|
||||||
use proxmox::{
|
use proxmox::tools::Uuid;
|
||||||
tools::Uuid,
|
|
||||||
api::section_config::SectionConfigData,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backup::{
|
backup::{
|
||||||
@ -28,6 +25,7 @@ use crate::{
|
|||||||
MediaSetCatalog,
|
MediaSetCatalog,
|
||||||
tape_write_snapshot_archive,
|
tape_write_snapshot_archive,
|
||||||
request_and_load_media,
|
request_and_load_media,
|
||||||
|
file_formats::MediaSetLabel,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -148,11 +146,15 @@ impl PoolWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let (drive_config, _digest) = crate::config::drive::config()?;
|
let (drive_config, _digest) = crate::config::drive::config()?;
|
||||||
let (drive, catalog) = drive_load_and_label_media(
|
|
||||||
|
let (mut drive, old_media_id) =
|
||||||
|
request_and_load_media(worker, &drive_config, &self.drive_name, media.label())?;
|
||||||
|
|
||||||
|
let catalog = update_media_set_label(
|
||||||
worker,
|
worker,
|
||||||
&drive_config,
|
drive.as_mut(),
|
||||||
&self.drive_name,
|
old_media_id.media_set_label,
|
||||||
&media.id(),
|
media.id(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.status = Some(PoolWriterState { drive, catalog, at_eom: false, bytes_written: 0 });
|
self.status = Some(PoolWriterState { drive, catalog, at_eom: false, bytes_written: 0 });
|
||||||
@ -336,34 +338,29 @@ fn write_chunk_archive<'a>(
|
|||||||
Ok((chunk_list, content_uuid, leom, writer.bytes_written()))
|
Ok((chunk_list, content_uuid, leom, writer.bytes_written()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Requests and load 'media' into the drive. Then compare the media
|
// Compare the media set label. If the media is empty, or the existing
|
||||||
// set label. If the tabe is empty, or the existing set label does not
|
// set label does not match the expected media set, overwrite the
|
||||||
// match the expected media set, overwrite the media set label.
|
// media set label.
|
||||||
fn drive_load_and_label_media(
|
fn update_media_set_label(
|
||||||
worker: &WorkerTask,
|
worker: &WorkerTask,
|
||||||
drive_config: &SectionConfigData,
|
drive: &mut dyn TapeDriver,
|
||||||
drive_name: &str,
|
old_set: Option<MediaSetLabel>,
|
||||||
media_id: &MediaId,
|
media_id: &MediaId,
|
||||||
) -> Result<(Box<dyn TapeDriver>, MediaCatalog), Error> {
|
) -> Result<MediaCatalog, Error> {
|
||||||
|
|
||||||
let (mut tmp_drive, old_media_id) =
|
|
||||||
request_and_load_media(worker, &drive_config, &drive_name, &media_id.label)?;
|
|
||||||
|
|
||||||
let media_catalog;
|
let media_catalog;
|
||||||
|
|
||||||
let new_set = match media_id.media_set_label {
|
let new_set = match media_id.media_set_label {
|
||||||
None => {
|
None => bail!("got media without media set - internal error"),
|
||||||
bail!("got media without media set - internal error");
|
|
||||||
}
|
|
||||||
Some(ref set) => set,
|
Some(ref set) => set,
|
||||||
};
|
};
|
||||||
|
|
||||||
let status_path = Path::new(TAPE_STATUS_DIR);
|
let status_path = Path::new(TAPE_STATUS_DIR);
|
||||||
|
|
||||||
match &old_media_id.media_set_label {
|
match old_set {
|
||||||
None => {
|
None => {
|
||||||
println!("wrinting new media set label");
|
worker.log(format!("wrinting new media set label"));
|
||||||
tmp_drive.write_media_set_label(new_set)?;
|
drive.write_media_set_label(new_set)?;
|
||||||
media_catalog = MediaCatalog::overwrite(status_path, media_id, true)?;
|
media_catalog = MediaCatalog::overwrite(status_path, media_id, true)?;
|
||||||
}
|
}
|
||||||
Some(media_set_label) => {
|
Some(media_set_label) => {
|
||||||
@ -374,17 +371,19 @@ fn drive_load_and_label_media(
|
|||||||
}
|
}
|
||||||
media_catalog = MediaCatalog::open(status_path, &media_id.label.uuid, true, false)?;
|
media_catalog = MediaCatalog::open(status_path, &media_id.label.uuid, true, false)?;
|
||||||
} else {
|
} else {
|
||||||
println!("wrinting new media set label (overwrite '{}/{}')",
|
worker.log(
|
||||||
media_set_label.uuid.to_string(), media_set_label.seq_nr);
|
format!("wrinting new media set label (overwrite '{}/{}')",
|
||||||
|
media_set_label.uuid.to_string(), media_set_label.seq_nr)
|
||||||
|
);
|
||||||
|
|
||||||
tmp_drive.write_media_set_label(new_set)?;
|
drive.write_media_set_label(new_set)?;
|
||||||
media_catalog = MediaCatalog::overwrite(status_path, media_id, true)?;
|
media_catalog = MediaCatalog::overwrite(status_path, media_id, true)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: verify last content/media_catalog somehow?
|
// todo: verify last content/media_catalog somehow?
|
||||||
tmp_drive.move_to_eom()?;
|
drive.move_to_eom()?;
|
||||||
|
|
||||||
Ok((tmp_drive, media_catalog))
|
Ok(media_catalog)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user