Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions pkg/hostpath/snapshotmetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (cb *fileBlockReader) getChangedBlockMetadata(ctx context.Context) ([]*csi.
blockIndex := cb.offset / cb.blockSize
sBuffer := make([]byte, cb.blockSize)
tBuffer := make([]byte, cb.blockSize)
zeroBlock := make([]byte, cb.blockSize)
eofBaseFile, eofTargetFile := false, false

changedBlocks := []*csi.BlockMetadata{}
Expand All @@ -143,15 +144,19 @@ func (cb *fileBlockReader) getChangedBlockMetadata(ctx context.Context) ([]*csi.
if eofTargetFile {
return changedBlocks, io.EOF
}
// if VARIABLE_LENGTH type is enabled, return blocks extend instead of individual blocks.
blockMetadata := createBlockMetadata(blockIndex, cb.blockSize)
if extendBlock(changedBlocks, csi.BlockMetadataType(cb.blockMetadataType), blockIndex, cb.blockSize) {
changedBlocks[len(changedBlocks)-1].SizeBytes += cb.blockSize
cb.offset += cb.blockSize
blockIndex++
continue
// return only allocated blocks.
if blockChanged(zeroBlock, tBuffer[:targetReadBytes]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work when a change wrote a whole lot of zero bytes over existing data to the volume?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it should be fine, as cb.base == nil here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for GetMetadataAllocated, where the backup application requires only the allocated data from the snapshot. During restoration, any uninitialized bytes will be filled with zeroes anyway.

// if VARIABLE_LENGTH type is enabled, return blocks extend instead of individual blocks.
blockMetadata := createBlockMetadata(blockIndex, cb.blockSize)
if extendBlock(changedBlocks, csi.BlockMetadataType(cb.blockMetadataType), blockIndex, cb.blockSize) {
changedBlocks[len(changedBlocks)-1].SizeBytes += cb.blockSize
cb.offset += cb.blockSize
blockIndex++
continue
}
changedBlocks = append(changedBlocks, blockMetadata)
}
changedBlocks = append(changedBlocks, blockMetadata)

cb.offset += cb.blockSize
blockIndex++
continue
Expand Down