Skip to content

Commit

Permalink
disk: align logical volumes up in EnsureSize()
Browse files Browse the repository at this point in the history
When creating an LV they need to be aligned up boundaries
or lvcreate will fail. When a lv is create via CreateLogicalVolume()
this hapens because the size is calculcated with `v.AlignUp()` but
when a resize is required via `lv.EnsureSize()` this is not taken
into account.

This fixes the failure in bib PR#750
  • Loading branch information
mvo5 authored and ondrejbudai committed Dec 7, 2024
1 parent e82349a commit 048c8c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/disk/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,18 @@ func (vg *LVMVolumeGroup) CreateLogicalVolume(lvName string, size uint64, payloa
return &vg.LogicalVolumes[len(vg.LogicalVolumes)-1], nil
}

func (vg *LVMVolumeGroup) AlignUp(size uint64) uint64 {

func alignUp(size uint64) uint64 {
if size%LVMDefaultExtentSize != 0 {
size += LVMDefaultExtentSize - size%LVMDefaultExtentSize
}

return size
}

func (vg *LVMVolumeGroup) AlignUp(size uint64) uint64 {
return alignUp(size)
}

func (vg *LVMVolumeGroup) MetadataSize() uint64 {
if vg == nil {
return 0
Expand Down Expand Up @@ -214,7 +217,7 @@ func (lv *LVMLogicalVolume) EnsureSize(s uint64) bool {
panic("LVMLogicalVolume.EnsureSize: nil entity")
}
if s > lv.Size {
lv.Size = s
lv.Size = alignUp(s)
return true
}
return false
Expand Down
11 changes: 11 additions & 0 deletions pkg/disk/lvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/osbuild/images/pkg/datasizes"
)

func TestLVMVCreateMountpoint(t *testing.T) {
Expand Down Expand Up @@ -66,3 +68,12 @@ func TestImplementsInterfacesCompileTimeCheckLVM(t *testing.T) {
var _ = Container(&LVMVolumeGroup{})
var _ = Sizeable(&LVMLogicalVolume{})
}

func TestLVMLogicalVolumeEnsureSize(t *testing.T) {
lv := &LVMLogicalVolume{
Size: 1024 * 1024,
}
resized := lv.EnsureSize(1024*1024 + 17)
assert.True(t, resized)
assert.Equal(t, uint64(4*datasizes.MiB), lv.Size)
}

0 comments on commit 048c8c6

Please sign in to comment.