async fn allocate(&self, transaction: &mut Transaction, len: u64) -> Result<Range<u64>, Error> {
        ensure!(len % self.block_size as u64 == 0);

        self.ensure_open().await?;

        let tree = &self.tree;
        let result = {
            let mut layer_set = tree.layer_set();
            layer_set.add_layer(self.reserved_allocations.clone());
            let mut merger = layer_set.merger();
            let mut iter = merger.seek(Bound::Unbounded).await?;
            let mut last_offset = 0;
            loop {
                let next = iter.get();
                match next {
                    None => {
                        // TODO(csuter): Don't assume infinite device size.
                        break last_offset..last_offset + len;
                    }
                    Some(ItemRef { key: AllocatorKey { device_range, .. }, .. }) => {
                        if device_range.start > last_offset {
                            break last_offset..min(last_offset + len, device_range.start);
                        }
                        last_offset = device_range.end;
                    }
                }
                iter.advance().await?;
            }
        };
        log::debug!("allocate {:?}", result);
        self.reserve(transaction, result.clone()).await;
        Ok(result)
    }
// TODO(csuter): this should return a reservation object rather than just a range so that it can
// get cleaned up when dropped.
this should return a reservation object rather than just a range so that it can
get cleaned up when dropped.
this should return a reservation object rather than just a range so that it can get cleaned up when dropped .
async fn allocate(&self, transaction: &mut Transaction, len: u64) -> Result<Range<u64>, Error> {
        ensure!(len % self.block_size as u64 == 0);
        self.ensure_open().await?;
        let tree = &self.tree;
        let result = {
            let mut layer_set = tree.layer_set();
            layer_set.add_layer(self.reserved_allocations.clone());
            let mut merger = layer_set.merger();
            let mut iter = merger.seek(Bound::Unbounded).await?;
            let mut last_offset = 0;
            loop {
                let next = iter.get();
                match next {
                    None => {
                        // TODO(csuter): Don't assume infinite device size.
                        break last_offset..last_offset + len;
                    }
                    Some(ItemRef { key: AllocatorKey { device_range, .. }, .. }) => {
                        if device_range.start > last_offset {
                            break last_offset..min(last_offset + len, device_range.start);
                        }
                        last_offset = device_range.end;
                    }
                }
                iter.advance().await?;
            }
        };
        log::debug!("allocate {:?}", result);
        self.reserve(transaction, result.clone()).await;
        Ok(result)
    }
async fn allocate ( & self , transaction : & mut Transaction , len : u64 ) -> Result < Range < u64 > , Error > { ensure ! ( len self block_size as u64 0 ) ; self . ensure_open ( ) . await ? ; let tree = & self . tree ; let result = { let mut layer_set = tree . layer_set ( ) ; layer_set . add_layer ( self . reserved_allocations . clone ( ) ) ; let mut merger = layer_set . merger ( ) ; let mut iter = merger . seek ( Bound :: Unbounded ) . await ? ; let mut last_offset = 0 ; loop { let next = iter . get ( ) ; match next { None => { // TODO(csuter): Don't assume infinite device size. break last_offset .. last_offset + len ; } Some ( ItemRef { key : AllocatorKey { device_range , .. } , .. } ) => { if device_range . start > last_offset { break last_offset .. min ( last_offset + len , device_range . start ) ; } last_offset = device_range . end ; } } iter . advance ( ) . await ? ; } } ; log :: debug ! ( " " result ) ; self . reserve ( transaction , result . clone ( ) ) . await ; Ok ( result ) }
TODO(csuter): this should return a reservation object rather than just a range so that it can
get cleaned up when dropped.
TODO ( csuter ) : this should return a reservation object rather than just a range so that it can get cleaned up when dropped .
&self
transaction
&mut Transaction
len
u64
&self
transaction
&mut Transaction
len
u64