pub async fn write_all_config_objects(
        &self,
        header: &MetaDataHeader,
        list: &[NexusConfig],
        generation: u64,
        now: &SystemTime,
    ) -> Result<Vec<MetaDataIndexEntry>, MetaDataError> {
        if list.len() > header.max_entries as usize {
            return Err(MetaDataError::IndexSizeExceeded {
                used: list.len() as u32,
                size: header.max_entries,
            });
        }

        let mut index: Vec<MetaDataIndexEntry> = Vec::new();

        let (bdev, hndl) = self.get_dev().context(NexusChildError {})?;
        let block_size = bdev.block_len() as u64;

        let timestamp = now
            .duration_since(UNIX_EPOCH)
            .context(TimeStampError {})?
            .as_micros();

        let mut start = header.data_start;
        let mut revision = generation;

        for config in list {
            let blocks = Aligned::get_blocks(
                serialized_size(config).context(SerializeError {})?,
                block_size,
            );
            let next = start + blocks;

            if next > header.data_end + 1 {
                return Err(MetaDataError::PartitionSizeExceeded {});
            }

            let mut buf = DmaBuf::new(blocks * block_size, bdev.alignment())
                .context(WriteAlloc {
                    name: String::from("object"),
                })?;
            let mut writer = Cursor::new(buf.as_mut_slice());

            serialize_into(&mut writer, config).context(SerializeError {})?;
            let checksum = crc32::checksum_ieee(buf.as_slice());

            hndl.write_at((header.self_lba + start) * block_size, &buf)
                .await
                .context(WriteError {
                    name: String::from("object"),
                })?;

            revision += 1;

            index.push(MetaDataIndexEntry {
                revision,
                timestamp,
                data_checksum: checksum,
                data_start: start,
                data_end: next - 1,
            });

            start = next;
        }

        Ok(index)
    }
/// Write an array of config object to disk.
/// Also generate a suitable index.
/// Will fail if there is insufficent space on the disk.
Write an array of config object to disk.
Also generate a suitable index.
Will fail if there is insufficent space on the disk.
Write an array of config object to disk . Also generate a suitable index . Will fail if there is insufficent space on the disk .
pub async fn write_all_config_objects(
        &self,
        header: &MetaDataHeader,
        list: &[NexusConfig],
        generation: u64,
        now: &SystemTime,
    ) -> Result<Vec<MetaDataIndexEntry>, MetaDataError> {
        if list.len() > header.max_entries as usize {
            return Err(MetaDataError::IndexSizeExceeded {
                used: list.len() as u32,
                size: header.max_entries,
            });
        }
        let mut index: Vec<MetaDataIndexEntry> = Vec::new();
        let (bdev, hndl) = self.get_dev().context(NexusChildError {})?;
        let block_size = bdev.block_len() as u64;
        let timestamp = now
            .duration_since(UNIX_EPOCH)
            .context(TimeStampError {})?
            .as_micros();
        let mut start = header.data_start;
        let mut revision = generation;
        for config in list {
            let blocks = Aligned::get_blocks(
                serialized_size(config).context(SerializeError {})?,
                block_size,
            );
            let next = start + blocks;
            if next > header.data_end + 1 {
                return Err(MetaDataError::PartitionSizeExceeded {});
            }
            let mut buf = DmaBuf::new(blocks * block_size, bdev.alignment())
                .context(WriteAlloc {
                    name: String::from("object"),
                })?;
            let mut writer = Cursor::new(buf.as_mut_slice());
            serialize_into(&mut writer, config).context(SerializeError {})?;
            let checksum = crc32::checksum_ieee(buf.as_slice());
            hndl.write_at((header.self_lba + start) * block_size, &buf)
                .await
                .context(WriteError {
                    name: String::from("object"),
                })?;
            revision += 1;
            index.push(MetaDataIndexEntry {
                revision,
                timestamp,
                data_checksum: checksum,
                data_start: start,
                data_end: next - 1,
            });
            start = next;
        }
        Ok(index)
    }
pub async fn write_all_config_objects ( & self , header : & MetaDataHeader , list : & [ NexusConfig ] , generation : u64 , now : & SystemTime , ) -> Result < Vec < MetaDataIndexEntry > , MetaDataError > { if list . len ( ) > header . max_entries as usize { return Err ( MetaDataError :: IndexSizeExceeded { used : list . len ( ) as u32 , size : header . max_entries , } ) ; } let mut index : Vec < MetaDataIndexEntry > = Vec :: new ( ) ; let ( bdev , hndl ) = self . get_dev ( ) . context ( NexusChildError { } ) ? ; let block_size = bdev . block_len ( ) as u64 ; let timestamp = now . duration_since ( UNIX_EPOCH ) . context ( TimeStampError { } ) ? . as_micros ( ) ; let mut start = header . data_start ; let mut revision = generation ; for config in list { let blocks = Aligned :: get_blocks ( serialized_size ( config ) . context ( SerializeError { } ) ? , block_size , ) ; let next = start + blocks ; if next > header . data_end + 1 { return Err ( MetaDataError :: PartitionSizeExceeded { } ) ; } let mut buf = DmaBuf :: new ( blocks * block_size , bdev . alignment ( ) ) . context ( WriteAlloc { name : String :: from ( " " ) , } ) ? ; let mut writer = Cursor :: new ( buf . as_mut_slice ( ) ) ; serialize_into ( & mut writer , config ) . context ( SerializeError { } ) ? ; let checksum = crc32 :: checksum_ieee ( buf . as_slice ( ) ) ; hndl . write_at ( ( header . self_lba + start ) * block_size , & buf ) . await . context ( WriteError { name : String :: from ( " " ) , } ) ? ; revision += 1 ; index . push ( MetaDataIndexEntry { revision , timestamp , data_checksum : checksum , data_start : start , data_end : next - 1 , } ) ; start = next ; } Ok ( index ) }
Write an array of config object to disk.
Write an array of config object to disk .
&self
header
&MetaDataHeader
list
&[NexusConfig]
generation
u64
now
&SystemTime