fn read_whole_chunk(
        &mut self,
        buf: &mut [u8],
        need_validate: bool,
        digester: digest::Algorithm,
    ) -> Result<usize> {
        let d_offset = self.chunk.decompress_offset() as i64;
        let d_size = self.chunk.decompress_size();

        let data_offset = unsafe { libc::lseek(self.fd, d_offset, libc::SEEK_DATA) };

        // TODO: This is not a reliable method to judge if chunk is integrated but just
        // immature stage since a chunk might span two filesystem blocks.
        if data_offset != d_offset {
            return Err(einval!());
        }

        let nr_read = uio::pread(self.fd, buf, d_offset).map_err(|_| last_error!())?;
        if nr_read == 0 || nr_read != d_size as usize {
            return Err(einval!());
        }

        if (need_validate || !self.is_ready())
            && !digest_check(buf, &self.chunk.block_id(), digester)
        {
            return Err(einval!());
        }

        self.set_ready();

        trace!(
            "read {}(offset={}) bytes from cache file",
            nr_read,
            d_offset
        );

        Ok(nr_read)
    }
/// Try to read from blob cache file, it might fail in loading data from blob cache
/// and it's normal as blob cache relies on chunk hash. Blob cache always validate
/// if chunk is integrated and correct before setting its status to `Ready`.
/// Given not integrated chunk, blob cache should fetch chunk from backend.
Try to read from blob cache file, it might fail in loading data from blob cache
and it's normal as blob cache relies on chunk hash. Blob cache always validate
if chunk is integrated and correct before setting its status to `Ready`.
Given not integrated chunk, blob cache should fetch chunk from backend.
Try to read from blob cache file it might fail in loading data from blob cache and it ' s normal as blob cache relies on chunk hash . Blob cache always validate if chunk is integrated and correct before setting its status to ` Ready ` . Given not integrated chunk blob cache should fetch chunk from backend .
fn read_whole_chunk(
        &mut self,
        buf: &mut [u8],
        need_validate: bool,
        digester: digest::Algorithm,
    ) -> Result<usize> {
        let d_offset = self.chunk.decompress_offset() as i64;
        let d_size = self.chunk.decompress_size();
        let data_offset = unsafe { libc::lseek(self.fd, d_offset, libc::SEEK_DATA) };
        // TODO: This is not a reliable method to judge if chunk is integrated but just
        // immature stage since a chunk might span two filesystem blocks.
        if data_offset != d_offset {
            return Err(einval!());
        }
        let nr_read = uio::pread(self.fd, buf, d_offset).map_err(|_| last_error!())?;
        if nr_read == 0 || nr_read != d_size as usize {
            return Err(einval!());
        }
        if (need_validate || !self.is_ready())
            && !digest_check(buf, &self.chunk.block_id(), digester)
        {
            return Err(einval!());
        }
        self.set_ready();
        trace!(
            "read {}(offset={}) bytes from cache file",
            nr_read,
            d_offset
        );
        Ok(nr_read)
    }
fn read_whole_chunk ( & mut self , buf : & mut [ u8 ] , need_validate : bool , digester : digest :: Algorithm , ) -> Result < usize > { let d_offset = self . chunk . decompress_offset ( ) as i64 ; let d_size = self . chunk . decompress_size ( ) ; let data_offset = unsafe { libc :: lseek ( self . fd , d_offset , libc :: SEEK_DATA ) } ; // TODO: This is not a reliable method to judge if chunk is integrated but just // immature stage since a chunk might span two filesystem blocks. if data_offset != d_offset { return Err ( einval ! ( ) ) ; } let nr_read = uio :: pread ( self . fd , buf , d_offset ) . map_err ( | _ | last_error ! ( ) ) ? ; if nr_read == 0 || nr_read != d_size as usize { return Err ( einval ! ( ) ) ; } if ( need_validate || ! self . is_ready ( ) ) && ! digest_check ( buf , & self . chunk . block_id ( ) , digester ) { return Err ( einval ! ( ) ) ; } self . set_ready ( ) ; trace ! ( " " nr_read d_offset ) ; Ok ( nr_read ) }
Try to read from blob cache file, it might fail in loading data from blob cache
and it's normal as blob cache relies on chunk hash.
Try to read from blob cache file it might fail in loading data from blob cache and it ' s normal as blob cache relies on chunk hash .
&mut self
buf
&mut [u8]
need_validate
bool
digester
digest::Algorithm
&mut self
buf
&mut [u8]
need_validate
bool
digester
digest::Algorithm