@@ -57,6 +57,22 @@ pub const MAX_XATTR_VALUE_SIZE: usize = 64000;
57
57
pub const EXTENDED_ATTRIBUTE_RANGE_START : u64 = 64 ;
58
58
pub const EXTENDED_ATTRIBUTE_RANGE_END : u64 = 512 ;
59
59
60
+ /// Zeroes blocks in 'buffer' based on `bitmap`, one bit per block from start of buffer.
61
+ fn apply_bitmap_zeroing (
62
+ block_size : usize ,
63
+ bitmap : & bit_vec:: BitVec ,
64
+ mut buffer : MutableBufferRef < ' _ > ,
65
+ ) {
66
+ let buf = buffer. as_mut_slice ( ) ;
67
+ debug_assert_eq ! ( bitmap. len( ) * block_size, buf. len( ) ) ;
68
+ for ( i, block) in bitmap. iter ( ) . enumerate ( ) {
69
+ if !block {
70
+ let start = i * block_size;
71
+ buf[ start..start + block_size] . fill ( 0 ) ;
72
+ }
73
+ }
74
+ }
75
+
60
76
/// When writing, often the logic should be generic over whether or not checksums are generated.
61
77
/// This provides that and a handy way to convert to the more general ExtentMode that eventually
62
78
/// stores it on disk.
@@ -697,10 +713,6 @@ impl<S: HandleOwner> StoreObjectHandle<S> {
697
713
file_offset : u64 ,
698
714
mut buffer : MutableBufferRef < ' _ > ,
699
715
key_id : u64 ,
700
- // If provided, blocks in the bitmap that are zero will have their contents zeroed out. The
701
- // bitmap should be exactly the size of the buffer and aligned to the offset in the extent
702
- // the read is starting at.
703
- block_bitmap : Option < bit_vec:: BitVec > ,
704
716
) -> Result < ( ) , Error > {
705
717
let store = self . store ( ) ;
706
718
store. device_read_ops . fetch_add ( 1 , Ordering :: Relaxed ) ;
@@ -717,17 +729,6 @@ impl<S: HandleOwner> StoreObjectHandle<S> {
717
729
if let Some ( key) = key {
718
730
key. decrypt ( file_offset, buffer. as_mut_slice ( ) ) ?;
719
731
}
720
- if let Some ( bitmap) = block_bitmap {
721
- let block_size = self . block_size ( ) as usize ;
722
- let buf = buffer. as_mut_slice ( ) ;
723
- debug_assert_eq ! ( bitmap. len( ) * block_size, buf. len( ) ) ;
724
- for ( i, block) in bitmap. iter ( ) . enumerate ( ) {
725
- if !block {
726
- let start = i * block_size;
727
- buf[ start..start + block_size] . fill ( 0 ) ;
728
- }
729
- }
730
- }
731
732
Ok ( ( ) )
732
733
}
733
734
@@ -985,7 +986,7 @@ impl<S: HandleOwner> StoreObjectHandle<S> {
985
986
"R" ,
986
987
) ;
987
988
}
988
- let ( head, tail) = buf. split_at_mut ( to_copy) ;
989
+ let ( mut head, tail) = buf. split_at_mut ( to_copy) ;
989
990
let maybe_bitmap = match mode {
990
991
ExtentMode :: OverwritePartial ( bitmap) => {
991
992
let mut read_bitmap = bitmap. clone ( ) . split_off (
@@ -996,13 +997,15 @@ impl<S: HandleOwner> StoreObjectHandle<S> {
996
997
}
997
998
_ => None ,
998
999
} ;
999
- reads. push ( self . read_and_decrypt (
1000
- device_offset,
1001
- offset,
1002
- head,
1003
- key_id,
1004
- maybe_bitmap,
1005
- ) ) ;
1000
+ reads. push ( async move {
1001
+ self
1002
+ . read_and_decrypt ( device_offset, offset, head. reborrow ( ) , key_id)
1003
+ . await ?;
1004
+ if let Some ( bitmap) = maybe_bitmap {
1005
+ apply_bitmap_zeroing ( self . block_size ( ) as usize , & bitmap, head) ;
1006
+ }
1007
+ Ok :: < ( ) , Error > ( ( ) )
1008
+ } ) ;
1006
1009
buf = tail;
1007
1010
if buf. is_empty ( ) {
1008
1011
break ;
@@ -1031,7 +1034,7 @@ impl<S: HandleOwner> StoreObjectHandle<S> {
1031
1034
"RT" ,
1032
1035
) ;
1033
1036
}
1034
- self . read_and_decrypt ( device_offset, offset, align_buf. as_mut ( ) , key_id, None )
1037
+ self . read_and_decrypt ( device_offset, offset, align_buf. as_mut ( ) , key_id)
1035
1038
. await ?;
1036
1039
buf. as_mut_slice ( ) . copy_from_slice ( & align_buf. as_slice ( ) [ ..end_align] ) ;
1037
1040
buf = buf. subslice_mut ( 0 ..0 ) ;
@@ -1112,9 +1115,15 @@ impl<S: HandleOwner> StoreObjectHandle<S> {
1112
1115
extent_key. range . start ,
1113
1116
buffer. subslice_mut ( offset..end as usize ) ,
1114
1117
* key_id,
1115
- maybe_bitmap,
1116
1118
)
1117
1119
. await ?;
1120
+ if let Some ( bitmap) = maybe_bitmap {
1121
+ apply_bitmap_zeroing (
1122
+ self . block_size ( ) as usize ,
1123
+ & bitmap,
1124
+ buffer. subslice_mut ( offset..end as usize ) ,
1125
+ ) ;
1126
+ }
1118
1127
last_offset = end;
1119
1128
if last_offset >= size {
1120
1129
break ;
0 commit comments