Skip to content

Commit 6fcd198

Browse files
committed
boot volume: use size of backing volume
So far this was hard coded to 10G, which for example did not allow to boot bigger images like - haha - "Micro"OS.
1 parent 41318e7 commit 6fcd198

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

internal/virter/libvirt_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ func (l *FakeLibvirtConnection) StorageVolDownload(Vol libvirt.StorageVol, inStr
160160
return nil
161161
}
162162

163+
func (l *FakeLibvirtConnection) StorageVolGetInfo(Vol libvirt.StorageVol) (rType int8, rCapacity uint64, rAllocation uint64, err error) {
164+
_, ok := l.vols[Vol.Name]
165+
if !ok {
166+
return 0, 0, 0, mockLibvirtError(errNoStorageVol)
167+
}
168+
169+
return 0, 42, 23, nil
170+
}
171+
163172
func (l *FakeLibvirtConnection) NetworkLookupByName(Name string) (rNet libvirt.Network, err error) {
164173
if Name != networkName {
165174
return libvirt.Network{}, errors.New("unknown network")

internal/virter/libvirtxml.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ func (v *Virter) ciDataVolumeXML(name string) (string, error) {
197197
return v.diskVolumeXML(name, 0, "B", "raw")
198198
}
199199

200-
func (v *Virter) vmVolumeXML(name string, backingPath string) (string, error) {
201-
volume := v.diskVolume(name, 10, "GiB", "qcow2")
200+
func (v *Virter) vmVolumeXML(name string, backingPath string, sizeB uint64) (string, error) {
201+
volume := v.diskVolume(name, sizeB, "B", "qcow2")
202202
volume.BackingStore = &lx.StorageVolumeBackingStore{
203203
Path: backingPath,
204204
Format: &lx.StorageVolumeTargetFormat{Type: "qcow2"},

internal/virter/virter.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type LibvirtConnection interface {
2424
StorageVolGetXMLDesc(Vol libvirt.StorageVol, Flags uint32) (rXML string, err error)
2525
StorageVolCreateXMLFrom(Pool libvirt.StoragePool, XML string, Clonevol libvirt.StorageVol, Flags libvirt.StorageVolCreateFlags) (rVol libvirt.StorageVol, err error)
2626
StorageVolDownload(Vol libvirt.StorageVol, inStream io.Writer, Offset uint64, Length uint64, Flags libvirt.StorageVolDownloadFlags) (err error)
27+
StorageVolGetInfo(Vol libvirt.StorageVol) (rType int8, rCapacity uint64, rAllocation uint64, err error)
2728
NetworkLookupByName(Name string) (rNet libvirt.Network, err error)
2829
NetworkGetXMLDesc(Net libvirt.Network, Flags uint32) (rXML string, err error)
2930
NetworkUpdate(Net libvirt.Network, Command uint32, Section uint32, ParentIndex int32, XML string, Flags libvirt.NetworkUpdateFlags) (err error)

internal/virter/vm.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/LINBIT/virter/pkg/netcopy"
12+
"github.com/rck/unit"
1213

1314
log "github.com/sirupsen/logrus"
1415
"golang.org/x/crypto/ssh"
@@ -142,7 +143,16 @@ func (v *Virter) createVMVolume(sp libvirt.StoragePool, vmConfig VMConfig) error
142143
return fmt.Errorf("could not get backing image path: %w", err)
143144
}
144145

145-
xml, err := v.vmVolumeXML(vmName, backingPath)
146+
_, sizeB, _, err := v.libvirt.StorageVolGetInfo(backingVolume)
147+
if err != nil {
148+
return fmt.Errorf("could not get backing image info: %w", err)
149+
}
150+
minSize := uint64(10 * unit.G)
151+
if sizeB < minSize {
152+
sizeB = minSize
153+
}
154+
155+
xml, err := v.vmVolumeXML(vmName, backingPath, sizeB)
146156
if err != nil {
147157
return err
148158
}

0 commit comments

Comments
 (0)