-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix disk size alignment when adding FS overhead
Signed-off-by: Bella Khizgiyaev <[email protected]>
- Loading branch information
Showing
6 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package util | ||
|
||
import "math" | ||
|
||
// Disk alignment size used to align FS overhead, | ||
// its a multiple of all known hardware block sizes 512/4k/8k/32k/64k | ||
const ( | ||
DefaultAlignBlockSize = 1024 * 1024 | ||
) | ||
|
||
func roundUp(requestedSpace, multiple int64) int64 { | ||
if multiple == 0 { | ||
return requestedSpace | ||
} | ||
partitions := math.Ceil(float64(requestedSpace) / float64(multiple)) | ||
return int64(partitions) * multiple | ||
} | ||
|
||
func CalculateSpaceWithOverhead(requestedSpace int64, filesystemOverhead float64) int64 { | ||
alignedSize := roundUp(requestedSpace, DefaultAlignBlockSize) | ||
spaceWithOverhead := int64(math.Ceil(float64(alignedSize) / (1 - filesystemOverhead))) | ||
return spaceWithOverhead | ||
} |