async fn write_config_object(
        &self,
        metadata: &mut NexusMetaData,
        config: &NexusConfig,
        now: &SystemTime,
    ) -> Result<(), MetaDataError> {
        if metadata.header.used_entries >= metadata.header.max_entries {
            return Err(MetaDataError::IndexSizeExceeded {
                used: metadata.header.used_entries + 1,
                size: metadata.header.max_entries,
            });
        }

        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 start: u64;

        if let Some(entry) = metadata.index.last() {
            start = entry.data_end + 1;
            if start > metadata.header.data_end {
                return Err(MetaDataError::PartitionSizeExceeded {});
            }
        } else {
            start = metadata.header.data_start;
        }

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

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

        let mut buf = DmaBuf::new(block_size * blocks, 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((metadata.header.self_lba + start) * block_size, &buf)
            .await
            .context(WriteError {
                name: String::from("object"),
            })?;

        metadata.header.generation += 1;
        metadata.header.used_entries += 1;

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

        Ok(())
    }
/// Write a config object to disk.
/// Also add a corresponding entry to the index and update the header.
/// Will fail if there is insufficent space remaining on the disk.
Write a config object to disk.
Also add a corresponding entry to the index and update the header.
Will fail if there is insufficent space remaining on the disk.
Write a config object to disk . Also add a corresponding entry to the index and update the header . Will fail if there is insufficent space remaining on the disk .
async fn write_config_object(
        &self,
        metadata: &mut NexusMetaData,
        config: &NexusConfig,
        now: &SystemTime,
    ) -> Result<(), MetaDataError> {
        if metadata.header.used_entries >= metadata.header.max_entries {
            return Err(MetaDataError::IndexSizeExceeded {
                used: metadata.header.used_entries + 1,
                size: metadata.header.max_entries,
            });
        }
        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 start: u64;
        if let Some(entry) = metadata.index.last() {
            start = entry.data_end + 1;
            if start > metadata.header.data_end {
                return Err(MetaDataError::PartitionSizeExceeded {});
            }
        } else {
            start = metadata.header.data_start;
        }
        let blocks = Aligned::get_blocks(
            serialized_size(config).context(SerializeError {})?,
            block_size,
        );
        let next = start + blocks;
        if next > metadata.header.data_end + 1 {
            return Err(MetaDataError::PartitionSizeExceeded {});
        }
        let mut buf = DmaBuf::new(block_size * blocks, 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((metadata.header.self_lba + start) * block_size, &buf)
            .await
            .context(WriteError {
                name: String::from("object"),
            })?;
        metadata.header.generation += 1;
        metadata.header.used_entries += 1;
        metadata.index.push(MetaDataIndexEntry {
            revision: metadata.header.generation,
            timestamp,
            data_checksum: checksum,
            data_start: start,
            data_end: next - 1,
        });
        Ok(())
    }
async fn write_config_object ( & self , metadata : & mut NexusMetaData , config : & NexusConfig , now : & SystemTime , ) -> Result < ( ) , MetaDataError > { if metadata . header . used_entries >= metadata . header . max_entries { return Err ( MetaDataError :: IndexSizeExceeded { used : metadata . header . used_entries + 1 , size : metadata . header . max_entries , } ) ; } 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 start : u64 ; if let Some ( entry ) = metadata . index . last ( ) { start = entry . data_end + 1 ; if start > metadata . header . data_end { return Err ( MetaDataError :: PartitionSizeExceeded { } ) ; } } else { start = metadata . header . data_start ; } let blocks = Aligned :: get_blocks ( serialized_size ( config ) . context ( SerializeError { } ) ? , block_size , ) ; let next = start + blocks ; if next > metadata . header . data_end + 1 { return Err ( MetaDataError :: PartitionSizeExceeded { } ) ; } let mut buf = DmaBuf :: new ( block_size * blocks , 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 ( ( metadata . header . self_lba + start ) * block_size , & buf ) . await . context ( WriteError { name : String :: from ( " " ) , } ) ? ; metadata . header . generation += 1 ; metadata . header . used_entries += 1 ; metadata . index . push ( MetaDataIndexEntry { revision : metadata . header . generation , timestamp , data_checksum : checksum , data_start : start , data_end : next - 1 , } ) ; Ok ( ( ) ) }
Write a config object to disk.
Write a config object to disk .
&self
metadata
&mut NexusMetaData
config
&NexusConfig
now
&SystemTime