diff --git a/src/pdata/space_map_checker.rs b/src/pdata/space_map_checker.rs index d0a9f47..3e01561 100644 --- a/src/pdata/space_map_checker.rs +++ b/src/pdata/space_map_checker.rs @@ -190,14 +190,6 @@ fn gather_metadata_index_entries( ) -> Result> { let b = engine.read(bitmap_root)?; let entries = unpack::(b.get_data())?.indexes; - - // Filter out unused entries with block 0 - let entries: Vec = entries - .iter() - .take_while(|e| e.blocknr != 0) - .cloned() - .collect(); - metadata_sm.lock().unwrap().inc(bitmap_root, 1)?; inc_entries(&metadata_sm, &entries[0..])?; diff --git a/src/pdata/space_map_metadata.rs b/src/pdata/space_map_metadata.rs index 4567b05..21e3283 100644 --- a/src/pdata/space_map_metadata.rs +++ b/src/pdata/space_map_metadata.rs @@ -34,6 +34,13 @@ impl Unpack for MetadataIndex { let (i, blocknr) = le_u64(i)?; let (i, indexes) = nom::multi::count(IndexEntry::unpack, MAX_METADATA_BITMAPS)(i)?; + // Filter out unused entries + let indexes: Vec = indexes + .iter() + .take_while(|e| e.blocknr != 0) + .cloned() + .collect(); + Ok((i, MetadataIndex { blocknr, indexes })) } } @@ -100,7 +107,7 @@ pub fn write_metadata_sm(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result Result { + let mut sm = self.sm.lock().unwrap(); + let b = sm.alloc()?; + + if b.is_none() { + return Err(anyhow!("out of metadata space")); + } + + self.allocations.insert(b.unwrap()); + Ok(Block::zeroed(b.unwrap())) + } + pub fn clear_allocations(&mut self) -> BTreeSet { let mut tmp = BTreeSet::new(); std::mem::swap(&mut tmp, &mut self.allocations);