use io_format_err, io_bail, io_err_other from proxmox-lang
and move the comment from the local io_bail in pbs-client/src/pxar/fuse.rs to the only use Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
committed by
Wolfgang Bumiller
parent
b066586a47
commit
f26d7ca5c5
@ -69,11 +69,11 @@ impl <R: BlockRead> BlockedReader<R> {
|
||||
fn check_buffer(buffer: &BlockHeader, seq_nr: u32) -> Result<(usize, bool), std::io::Error> {
|
||||
|
||||
if buffer.magic != PROXMOX_TAPE_BLOCK_HEADER_MAGIC_1_0 {
|
||||
proxmox_sys::io_bail!("detected tape block with wrong magic number - not written by proxmox tape");
|
||||
proxmox_lang::io_bail!("detected tape block with wrong magic number - not written by proxmox tape");
|
||||
}
|
||||
|
||||
if seq_nr != buffer.seq_nr() {
|
||||
proxmox_sys::io_bail!(
|
||||
proxmox_lang::io_bail!(
|
||||
"detected tape block with wrong sequence number ({} != {})",
|
||||
seq_nr, buffer.seq_nr())
|
||||
}
|
||||
@ -82,9 +82,9 @@ impl <R: BlockRead> BlockedReader<R> {
|
||||
let found_end_marker = buffer.flags.contains(BlockHeaderFlags::END_OF_STREAM);
|
||||
|
||||
if size > buffer.payload.len() {
|
||||
proxmox_sys::io_bail!("detected tape block with wrong payload size ({} > {}", size, buffer.payload.len());
|
||||
proxmox_lang::io_bail!("detected tape block with wrong payload size ({} > {}", size, buffer.payload.len());
|
||||
} else if size == 0 && !found_end_marker {
|
||||
proxmox_sys::io_bail!("detected tape block with zero payload size");
|
||||
proxmox_lang::io_bail!("detected tape block with zero payload size");
|
||||
}
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ impl <R: BlockRead> BlockedReader<R> {
|
||||
let bytes = reader.read_block(data)?;
|
||||
|
||||
if bytes != BlockHeader::SIZE {
|
||||
return Err(proxmox_sys::io_format_err!("got wrong block size").into());
|
||||
return Err(proxmox_lang::io_format_err!("got wrong block size").into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -113,13 +113,13 @@ impl <R: BlockRead> BlockedReader<R> {
|
||||
let mut tmp_buf = [0u8; 512]; // use a small buffer for testing EOF
|
||||
match reader.read_block(&mut tmp_buf) {
|
||||
Ok(_) => {
|
||||
proxmox_sys::io_bail!("detected tape block after block-stream end marker");
|
||||
proxmox_lang::io_bail!("detected tape block after block-stream end marker");
|
||||
}
|
||||
Err(BlockReadError::EndOfFile) => {
|
||||
Ok(())
|
||||
}
|
||||
Err(BlockReadError::EndOfStream) => {
|
||||
proxmox_sys::io_bail!("got unexpected end of tape");
|
||||
proxmox_lang::io_bail!("got unexpected end of tape");
|
||||
}
|
||||
Err(BlockReadError::Error(err)) => {
|
||||
Err(err)
|
||||
@ -135,12 +135,12 @@ impl <R: BlockRead> BlockedReader<R> {
|
||||
self.got_eod = true;
|
||||
self.read_pos = self.buffer.payload.len();
|
||||
if !self.found_end_marker && check_end_marker {
|
||||
proxmox_sys::io_bail!("detected tape stream without end marker");
|
||||
proxmox_lang::io_bail!("detected tape stream without end marker");
|
||||
}
|
||||
return Ok(0); // EOD
|
||||
}
|
||||
Err(BlockReadError::EndOfStream) => {
|
||||
proxmox_sys::io_bail!("got unexpected end of tape");
|
||||
proxmox_lang::io_bail!("got unexpected end of tape");
|
||||
}
|
||||
Err(BlockReadError::Error(err)) => {
|
||||
return Err(err);
|
||||
@ -167,10 +167,10 @@ impl <R: BlockRead> TapeRead for BlockedReader<R> {
|
||||
|
||||
fn is_incomplete(&self) -> Result<bool, std::io::Error> {
|
||||
if !self.got_eod {
|
||||
proxmox_sys::io_bail!("is_incomplete failed: EOD not reached");
|
||||
proxmox_lang::io_bail!("is_incomplete failed: EOD not reached");
|
||||
}
|
||||
if !self.found_end_marker {
|
||||
proxmox_sys::io_bail!("is_incomplete failed: no end marker found");
|
||||
proxmox_lang::io_bail!("is_incomplete failed: no end marker found");
|
||||
}
|
||||
|
||||
Ok(self.incomplete)
|
||||
@ -178,7 +178,7 @@ impl <R: BlockRead> TapeRead for BlockedReader<R> {
|
||||
|
||||
fn has_end_marker(&self) -> Result<bool, std::io::Error> {
|
||||
if !self.got_eod {
|
||||
proxmox_sys::io_bail!("has_end_marker failed: EOD not reached");
|
||||
proxmox_lang::io_bail!("has_end_marker failed: EOD not reached");
|
||||
}
|
||||
|
||||
Ok(self.found_end_marker)
|
||||
@ -207,7 +207,7 @@ impl <R: BlockRead> Read for BlockedReader<R> {
|
||||
fn read(&mut self, buffer: &mut [u8]) -> Result<usize, std::io::Error> {
|
||||
|
||||
if self.read_error {
|
||||
proxmox_sys::io_bail!("detected read after error - internal error");
|
||||
proxmox_lang::io_bail!("detected read after error - internal error");
|
||||
}
|
||||
|
||||
let mut buffer_size = self.buffer.size();
|
||||
|
@ -65,7 +65,7 @@ impl <W: BlockWrite> BlockedWriter<W> {
|
||||
|
||||
fn write_eof(&mut self) -> Result<(), std::io::Error> {
|
||||
if self.wrote_eof {
|
||||
proxmox_sys::io_bail!("BlockedWriter: detected multiple EOF writes");
|
||||
proxmox_lang::io_bail!("BlockedWriter: detected multiple EOF writes");
|
||||
}
|
||||
self.wrote_eof = true;
|
||||
|
||||
|
@ -22,7 +22,7 @@ impl <R: Read> EmulateTapeReader<R> {
|
||||
impl <R: Read> BlockRead for EmulateTapeReader<R> {
|
||||
fn read_block(&mut self, buffer: &mut [u8]) -> Result<usize, BlockReadError> {
|
||||
if self.got_eof {
|
||||
return Err(BlockReadError::Error(proxmox_sys::io_format_err!("detected read after EOF!")));
|
||||
return Err(BlockReadError::Error(proxmox_lang::io_format_err!("detected read after EOF!")));
|
||||
}
|
||||
match self.reader.read_exact_or_eof(buffer)? {
|
||||
false => {
|
||||
@ -33,7 +33,7 @@ impl <R: Read> BlockRead for EmulateTapeReader<R> {
|
||||
// test buffer len after EOF test (to allow EOF test with small buffers in BufferedReader)
|
||||
if buffer.len() != PROXMOX_TAPE_BLOCK_SIZE {
|
||||
return Err(BlockReadError::Error(
|
||||
proxmox_sys::io_format_err!(
|
||||
proxmox_lang::io_format_err!(
|
||||
"EmulateTapeReader: read_block with wrong block size ({} != {})",
|
||||
buffer.len(),
|
||||
PROXMOX_TAPE_BLOCK_SIZE,
|
||||
|
@ -39,7 +39,7 @@ impl <W: Write> BlockWrite for EmulateTapeWriter<W> {
|
||||
fn write_block(&mut self, buffer: &[u8]) -> Result<bool, io::Error> {
|
||||
|
||||
if buffer.len() != PROXMOX_TAPE_BLOCK_SIZE {
|
||||
proxmox_sys::io_bail!("EmulateTapeWriter: got write with wrong block size ({} != {}",
|
||||
proxmox_lang::io_bail!("EmulateTapeWriter: got write with wrong block size ({} != {}",
|
||||
buffer.len(), PROXMOX_TAPE_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ impl <W: Write> BlockWrite for EmulateTapeWriter<W> {
|
||||
|
||||
fn write_filemark(&mut self) -> Result<(), std::io::Error> {
|
||||
if self.wrote_eof {
|
||||
proxmox_sys::io_bail!("EmulateTapeWriter: detected multiple EOF writes");
|
||||
proxmox_lang::io_bail!("EmulateTapeWriter: detected multiple EOF writes");
|
||||
}
|
||||
// do nothing, just record the call
|
||||
self.wrote_eof = true;
|
||||
|
@ -528,11 +528,11 @@ impl SgTape {
|
||||
) -> Result<(), std::io::Error> {
|
||||
|
||||
if count > 255 {
|
||||
proxmox_sys::io_bail!("write_filemarks failed: got strange count '{}'", count);
|
||||
proxmox_lang::io_bail!("write_filemarks failed: got strange count '{}'", count);
|
||||
}
|
||||
|
||||
let mut sg_raw = SgRaw::new(&mut self.file, 16)
|
||||
.map_err(|err| proxmox_sys::io_format_err!("write_filemarks failed (alloc) - {}", err))?;
|
||||
.map_err(|err| proxmox_lang::io_format_err!("write_filemarks failed (alloc) - {}", err))?;
|
||||
|
||||
sg_raw.set_timeout(Self::SCSI_TAPE_DEFAULT_TIMEOUT);
|
||||
let mut cmd = Vec::new();
|
||||
@ -551,7 +551,7 @@ impl SgTape {
|
||||
/* LEOM - ignore */
|
||||
}
|
||||
Err(err) => {
|
||||
proxmox_sys::io_bail!("write filemark failed - {}", err);
|
||||
proxmox_lang::io_bail!("write filemark failed - {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -630,7 +630,7 @@ impl SgTape {
|
||||
let transfer_len = data.len();
|
||||
|
||||
if transfer_len > 0x800000 {
|
||||
proxmox_sys::io_bail!("write failed - data too large");
|
||||
proxmox_lang::io_bail!("write failed - data too large");
|
||||
}
|
||||
|
||||
let mut sg_raw = SgRaw::new(&mut self.file, 0)
|
||||
@ -654,7 +654,7 @@ impl SgTape {
|
||||
Ok(true) // LEOM
|
||||
}
|
||||
Err(err) => {
|
||||
proxmox_sys::io_bail!("write failed - {}", err);
|
||||
proxmox_lang::io_bail!("write failed - {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -664,7 +664,7 @@ impl SgTape {
|
||||
|
||||
if transfer_len > 0xFFFFFF {
|
||||
return Err(BlockReadError::Error(
|
||||
proxmox_sys::io_format_err!("read failed - buffer too large")
|
||||
proxmox_lang::io_format_err!("read failed - buffer too large")
|
||||
));
|
||||
}
|
||||
|
||||
@ -691,14 +691,14 @@ impl SgTape {
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(BlockReadError::Error(
|
||||
proxmox_sys::io_format_err!("read failed - {}", err)
|
||||
proxmox_lang::io_format_err!("read failed - {}", err)
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
if data.len() != transfer_len {
|
||||
return Err(BlockReadError::Error(
|
||||
proxmox_sys::io_format_err!("read failed - unexpected block len ({} != {})", data.len(), buffer.len())
|
||||
proxmox_lang::io_format_err!("read failed - unexpected block len ({} != {})", data.len(), buffer.len())
|
||||
));
|
||||
}
|
||||
|
||||
@ -949,7 +949,7 @@ impl <'a> BlockRead for SgTapeReader<'a> {
|
||||
|
||||
fn read_block(&mut self, buffer: &mut [u8]) -> Result<usize, BlockReadError> {
|
||||
if self.end_of_file {
|
||||
return Err(BlockReadError::Error(proxmox_sys::io_format_err!("detected read after EOF!")));
|
||||
return Err(BlockReadError::Error(proxmox_lang::io_format_err!("detected read after EOF!")));
|
||||
}
|
||||
match self.sg_tape.read_block(buffer) {
|
||||
Ok(usize) => Ok(usize),
|
||||
|
@ -34,7 +34,7 @@ pub trait TapeWrite {
|
||||
data: &[u8],
|
||||
) -> Result<bool, std::io::Error> {
|
||||
if header.size as usize != data.len() {
|
||||
proxmox_sys::io_bail!("write_header with wrong size - internal error");
|
||||
proxmox_lang::io_bail!("write_header with wrong size - internal error");
|
||||
}
|
||||
let header = header.to_le();
|
||||
|
||||
|
Reference in New Issue
Block a user