Skip to content

Commit

Permalink
Fix disk size alignment when adding FS overhead
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy authored and ahadas committed Aug 10, 2023
1 parent 33f8305 commit 13f9dd5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/openstack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
"//pkg/apis/forklift/v1beta1/ref",
"//pkg/controller/plan/adapter/base",
"//pkg/controller/plan/context",
"//pkg/controller/plan/util",
"//pkg/controller/provider/web",
"//pkg/controller/provider/web/base",
"//pkg/controller/provider/web/ocp",
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/plan/adapter/openstack/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/plan"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
plancontext "github.com/konveyor/forklift-controller/pkg/controller/plan/context"
utils "github.com/konveyor/forklift-controller/pkg/controller/plan/util"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/base"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/ocp"
model "github.com/konveyor/forklift-controller/pkg/controller/provider/web/openstack"
Expand Down Expand Up @@ -1099,7 +1100,7 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(image model.Image, storageC
}

if *volumeMode == core.PersistentVolumeFilesystem {
virtualSize = int64(float64(virtualSize) * 1.1)
virtualSize = utils.CalculateSpaceWithOverhead(virtualSize, 0.1)
}

// The image might be a VM Snapshot Image and has no volume associated to it
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/ovirt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//pkg/apis/forklift/v1beta1/ref",
"//pkg/controller/plan/adapter/base",
"//pkg/controller/plan/context",
"//pkg/controller/plan/util",
"//pkg/controller/provider/container/ovirt",
"//pkg/controller/provider/web",
"//pkg/controller/provider/web/base",
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/plan/adapter/ovirt/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
planbase "github.com/konveyor/forklift-controller/pkg/controller/plan/adapter/base"
plancontext "github.com/konveyor/forklift-controller/pkg/controller/plan/context"
utils "github.com/konveyor/forklift-controller/pkg/controller/plan/util"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/base"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/ocp"
model "github.com/konveyor/forklift-controller/pkg/controller/provider/web/ovirt"
Expand Down Expand Up @@ -794,7 +795,7 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(diskAttachment model.XDiskA
// Accounting for fsOverhead is only required for `volumeMode: Filesystem`, as we may not have enough space
// after creating a filesystem on an underlying block device
if *volumeMode == core.PersistentVolumeFilesystem {
diskSize = int64(float64(diskSize) * 1.1)
diskSize = utils.CalculateSpaceWithOverhead(diskSize, 0.1)
}

annotations[AnnImportDiskId] = diskAttachment.ID
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/plan/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"openstack.go",
"ovirt.go",
"utils.go",
],
importpath = "github.com/konveyor/forklift-controller/pkg/controller/plan/util",
visibility = ["//visibility:public"],
Expand Down
23 changes: 23 additions & 0 deletions pkg/controller/plan/util/utils.go
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
}

0 comments on commit 13f9dd5

Please sign in to comment.