Merge branch 'master' of ssh://proxdev.maurer-it.com/rust/proxmox-backup

This commit is contained in:
Dietmar Maurer
2021-01-21 10:56:52 +01:00
122 changed files with 521 additions and 614 deletions

View File

@ -24,10 +24,7 @@ pub fn has_encryption<F: AsRawFd>(
Ok(data) => data,
Err(_) => return false,
};
match decode_spin_data_encryption_caps(&data) {
Ok(_) => true,
Err(_) => false,
}
decode_spin_data_encryption_caps(&data).is_ok()
}
/// Set or clear encryption key

View File

@ -85,12 +85,12 @@ pub fn linux_tape_changer_list() -> Vec<TapeDeviceInfo> {
let vendor = device.property_value("ID_VENDOR")
.map(std::ffi::OsString::from)
.and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
.unwrap_or(String::from("unknown"));
.unwrap_or_else(|| String::from("unknown"));
let model = device.property_value("ID_MODEL")
.map(std::ffi::OsString::from)
.and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
.unwrap_or(String::from("unknown"));
.unwrap_or_else(|| String::from("unknown"));
let dev_path = format!("/dev/tape/by-id/scsi-{}", serial);
@ -166,12 +166,12 @@ pub fn linux_tape_device_list() -> Vec<TapeDeviceInfo> {
let vendor = device.property_value("ID_VENDOR")
.map(std::ffi::OsString::from)
.and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
.unwrap_or(String::from("unknown"));
.unwrap_or_else(|| String::from("unknown"));
let model = device.property_value("ID_MODEL")
.map(std::ffi::OsString::from)
.and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
.unwrap_or(String::from("unknown"));
.unwrap_or_else(|| String::from("unknown"));
let dev_path = format!("/dev/tape/by-id/scsi-{}-nst", serial);

View File

@ -98,16 +98,14 @@ impl LinuxTapeDrive {
if drive_status.blocksize == 0 {
// device is variable block size - OK
} else {
if drive_status.blocksize != PROXMOX_TAPE_BLOCK_SIZE as u32 {
eprintln!("device is in fixed block size mode with wrong size ({} bytes)", drive_status.blocksize);
eprintln!("trying to set variable block size mode...");
if handle.set_block_size(0).is_err() {
bail!("set variable block size mod failed - device uses wrong blocksize.");
}
} else {
// device is in fixed block size mode with correct block size
} else if drive_status.blocksize != PROXMOX_TAPE_BLOCK_SIZE as u32 {
eprintln!("device is in fixed block size mode with wrong size ({} bytes)", drive_status.blocksize);
eprintln!("trying to set variable block size mode...");
if handle.set_block_size(0).is_err() {
bail!("set variable block size mod failed - device uses wrong blocksize.");
}
} else {
// device is in fixed block size mode with correct block size
}
// Only root can set driver options, so we cannot
@ -528,7 +526,7 @@ impl TapeDriver for LinuxTapeHandle {
let result: Result<u64, String> = serde_json::from_str(&output)?;
result
.map_err(|err| format_err!("{}", err))
.map(|bits| TapeAlertFlags::from_bits_truncate(bits))
.map(TapeAlertFlags::from_bits_truncate)
}
/// Set or clear encryption key

View File

@ -32,7 +32,7 @@ enum MamFormat {
DEC,
}
static MAM_ATTRIBUTES: &'static [ (u16, u16, MamFormat, &'static str) ] = &[
static MAM_ATTRIBUTES: &[ (u16, u16, MamFormat, &str) ] = &[
(0x00_00, 8, MamFormat::DEC, "Remaining Capacity In Partition"),
(0x00_01, 8, MamFormat::DEC, "Maximum Capacity In Partition"),
(0x00_02, 8, MamFormat::DEC, "Tapealert Flags"),

View File

@ -258,13 +258,13 @@ pub fn required_media_changer(
) -> Result<(Box<dyn MediaChange>, String), Error> {
match media_changer(config, drive) {
Ok(Some(result)) => {
return Ok(result);
Ok(result)
}
Ok(None) => {
bail!("drive '{}' has no associated changer device", drive);
},
Err(err) => {
return Err(err);
Err(err)
}
}
}
@ -339,7 +339,7 @@ pub fn request_and_load_media(
let media_id = check_label(handle.as_mut(), &label.uuid)?;
return Ok((handle, media_id));
Ok((handle, media_id))
}
"linux" => {
let drive_config = LinuxTapeDrive::deserialize(config)?;
@ -390,20 +390,18 @@ pub fn request_and_load_media(
media_id.label.uuid.to_string(),
));
return Ok((Box::new(handle), media_id));
} else {
if Some(media_id.label.uuid.clone()) != last_media_uuid {
worker.log(format!(
"wrong media label {} ({})",
media_id.label.label_text,
media_id.label.uuid.to_string(),
));
last_media_uuid = Some(media_id.label.uuid);
}
} else if Some(media_id.label.uuid.clone()) != last_media_uuid {
worker.log(format!(
"wrong media label {} ({})",
media_id.label.label_text,
media_id.label.uuid.to_string(),
));
last_media_uuid = Some(media_id.label.uuid);
}
}
Ok((None, _)) => {
if last_media_uuid.is_some() {
worker.log(format!("found empty media without label (please label all tapes first)"));
worker.log("found empty media without label (please label all tapes first)".to_string());
last_media_uuid = None;
}
}

View File

@ -17,6 +17,7 @@ bitflags::bitflags!{
///
/// See LTO SCSI Reference LOG_SENSE - LP 2Eh: TapeAlerts
pub struct TapeAlertFlags: u64 {
#[allow(clippy::eq_op)]
const READ_WARNING = 1 << (0x0001 -1);
const WRITE_WARNING = 1 << (0x0002 -1);
const HARD_ERROR = 1 << (0x0003 -1);

View File

@ -168,8 +168,8 @@ impl VirtualTapeHandle {
if path.is_file() && path.extension() == Some(std::ffi::OsStr::new("json")) {
if let Some(name) = path.file_stem() {
if let Some(name) = name.to_str() {
if name.starts_with("tape-") {
list.push(name[5..].to_string());
if let Some(label) = name.strip_prefix("tape-") {
list.push(label.to_string());
}
}
}

View File

@ -95,19 +95,16 @@ fn decode_volume_statistics(data: &[u8]) -> Result<Lp17VolumeStatistics, Error>
let read_be_counter = |reader: &mut &[u8], len: u8| {
let len = len as usize;
if len == 0 || len > 8 {
bail!("invalid conter size '{}'", len);
}
let mut buffer = [0u8; 8];
reader.read_exact(&mut buffer[..len])?;
let mut value: u64 = 0;
for i in 0..len {
value = value << 8;
value = value | buffer[i] as u64;
}
let value = buffer
.iter()
.take(len)
.fold(0, |value, curr| (value << 8) | *curr as u64);
Ok(value)
};