Skip to content

Commit

Permalink
Make the filesystem overhead configurable
Browse files Browse the repository at this point in the history
This patch will allow the user to configure the filesystem overhead.
Currently it defaults to 10%. The overhead is mainly required for ext4
and the root partition.

Signed-off-by: Liran Rotenberg <[email protected]>
  • Loading branch information
liranr23 committed Nov 9, 2023
1 parent 0849112 commit 0afd260
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ spec:
value: ${SNAPSHOT_STATUS_CHECK_RATE}
- name: CDI_EXPORT_TOKEN_TTL
value: ${CDI_EXPORT_TOKEN_TTL}
- name: FILESYSTEM_OVERHEAD
value: ${FILESYSTEM_OVERHEAD}
- name: POPULATOR_CONTROLLER_IMAGE
value: ${POPULATOR_CONTROLLER_IMAGE}
- name: OVIRT_POPULATOR_IMAGE
Expand Down
1 change: 1 addition & 0 deletions operator/roles/forkliftcontroller/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ controller_snapshot_status_check_rate_seconds: 10
controller_vsphere_incremental_backup: true
controller_ovirt_warm_migration: true
controller_max_vm_inflight: 20
controller_filesystem_overhead: 10
profiler_volume_path: "/var/cache/profiler"

inventory_volume_path: "/var/cache/inventory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ spec:
- name: CDI_EXPORT_TOKEN_TTL
value: "{{ CDI_EXPORT_TOKEN_TTL }}"
{% endif %}
{% if controller_filesystem_overhead is number %}
- name: FILESYSTEM_OVERHEAD
value: "{{ controller_filesystem_overhead }}"
{% endif %}
{% if controller_vsphere_incremental_backup|bool %}
- name: FEATURE_VSPHERE_INCREMENTAL_BACKUP
value: "true"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/plan/adapter/openstack/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(image model.Image, storageC
}

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

// The image might be a VM Snapshot Image and has no volume associated to it
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 @@ -783,6 +783,7 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(diskAttachment model.XDiskA
annotations map[string]string) (pvc *core.PersistentVolumeClaim, err error) {

// We add 10% overhead because of the fsOverhead in CDI, around 5% to ext4 and 5% for root partition.
// This value is configurable using `FILESYSTEM_OVERHEAD`
diskSize := diskAttachment.Disk.ProvisionedSize

var accessModes []core.PersistentVolumeAccessMode
Expand All @@ -796,7 +797,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 = utils.CalculateSpaceWithOverhead(diskSize, 0.1)
diskSize = utils.CalculateSpaceWithOverhead(diskSize)
}

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 @@ -13,6 +13,7 @@ go_library(
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/provider/web/openstack",
"//pkg/controller/provider/web/ovirt",
"//pkg/settings",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
],
Expand Down
10 changes: 7 additions & 3 deletions pkg/controller/plan/util/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package util

import "math"
import (
"math"

"github.com/konveyor/forklift-controller/pkg/settings"
)

// Disk alignment size used to align FS overhead,
// its a multiple of all known hardware block sizes 512/4k/8k/32k/64k
Expand All @@ -16,8 +20,8 @@ func roundUp(requestedSpace, multiple int64) int64 {
return int64(partitions) * multiple
}

func CalculateSpaceWithOverhead(requestedSpace int64, filesystemOverhead float64) int64 {
func CalculateSpaceWithOverhead(requestedSpace int64) int64 {
alignedSize := roundUp(requestedSpace, DefaultAlignBlockSize)
spaceWithOverhead := int64(math.Ceil(float64(alignedSize) / (1 - filesystemOverhead)))
spaceWithOverhead := int64(math.Ceil(float64(alignedSize) / (1 - float64(settings.Settings.FileSystemOverhead)/100)))
return spaceWithOverhead
}
8 changes: 7 additions & 1 deletion pkg/settings/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
SnapshotRemovalTimeout = "SNAPSHOT_REMOVAL_TIMEOUT"
SnapshotStatusCheckRate = "SNAPSHOT_STATUS_CHECK_RATE"
CDIExportTokenTTL = "CDI_EXPORT_TOKEN_TTL"
FileSystemOverhead = "FILESYSTEM_OVERHEAD"
)

// Default virt-v2v image.
Expand Down Expand Up @@ -46,6 +47,8 @@ type Migration struct {
VirtV2vDontRequestKVM bool
// OCP Export token TTL minutes
CDIExportTokenTTL int
// FileSystem overhead in percantage
FileSystemOverhead int
}

// Load settings.
Expand Down Expand Up @@ -87,11 +90,14 @@ func (r *Migration) Load() (err error) {
r.VirtV2vImageWarm = DefaultVirtV2vImage
}
r.VirtV2vDontRequestKVM = getEnvBool(VirtV2vDontRequestKVM, false)

r.CDIExportTokenTTL, err = getEnvLimit(CDIExportTokenTTL, 0)
if err != nil {
err = liberr.Wrap(err)
}
r.FileSystemOverhead, err = getEnvLimitMinimal(FileSystemOverhead, 10, 0)
if err != nil {
err = liberr.Wrap(err)
}

return
}
11 changes: 9 additions & 2 deletions pkg/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package settings

import (
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
"fmt"
"os"
"strconv"
)
Expand Down Expand Up @@ -70,14 +71,20 @@ func (r *ControllerSettings) Load() error {
// Get positive integer limit from the environment
// using the specified variable name and default.
func getEnvLimit(name string, def int) (int, error) {
return getEnvLimitMinimal(name, def, 1)
}

// Get an integer limit from the environment
// using the specified variable name and default.
func getEnvLimitMinimal(name string, def, minimum int) (int, error) {
limit := 0
if s, found := os.LookupEnv(name); found {
n, err := strconv.Atoi(s)
if err != nil {
return 0, liberr.New(name + " must be an integer")
}
if n < 1 {
return 0, liberr.New(name + " must be >= 1")
if n < minimum {
return 0, liberr.New(fmt.Sprintf(name + " must be >= %d", minimum))
}
limit = n
} else {
Expand Down

0 comments on commit 0afd260

Please sign in to comment.