Skip to content

Commit

Permalink
boot volume: use size of backing volume
Browse files Browse the repository at this point in the history
So far this was hard coded to 10G, which for example did not allow to
boot bigger images like - haha - "Micro"OS.
  • Loading branch information
rck committed Jul 7, 2020
1 parent 41318e7 commit 6fcd198
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
9 changes: 9 additions & 0 deletions internal/virter/libvirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ func (l *FakeLibvirtConnection) StorageVolDownload(Vol libvirt.StorageVol, inStr
return nil
}

func (l *FakeLibvirtConnection) StorageVolGetInfo(Vol libvirt.StorageVol) (rType int8, rCapacity uint64, rAllocation uint64, err error) {
_, ok := l.vols[Vol.Name]
if !ok {
return 0, 0, 0, mockLibvirtError(errNoStorageVol)
}

return 0, 42, 23, nil
}

func (l *FakeLibvirtConnection) NetworkLookupByName(Name string) (rNet libvirt.Network, err error) {
if Name != networkName {
return libvirt.Network{}, errors.New("unknown network")
Expand Down
4 changes: 2 additions & 2 deletions internal/virter/libvirtxml.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ func (v *Virter) ciDataVolumeXML(name string) (string, error) {
return v.diskVolumeXML(name, 0, "B", "raw")
}

func (v *Virter) vmVolumeXML(name string, backingPath string) (string, error) {
volume := v.diskVolume(name, 10, "GiB", "qcow2")
func (v *Virter) vmVolumeXML(name string, backingPath string, sizeB uint64) (string, error) {
volume := v.diskVolume(name, sizeB, "B", "qcow2")
volume.BackingStore = &lx.StorageVolumeBackingStore{
Path: backingPath,
Format: &lx.StorageVolumeTargetFormat{Type: "qcow2"},
Expand Down
1 change: 1 addition & 0 deletions internal/virter/virter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type LibvirtConnection interface {
StorageVolGetXMLDesc(Vol libvirt.StorageVol, Flags uint32) (rXML string, err error)
StorageVolCreateXMLFrom(Pool libvirt.StoragePool, XML string, Clonevol libvirt.StorageVol, Flags libvirt.StorageVolCreateFlags) (rVol libvirt.StorageVol, err error)
StorageVolDownload(Vol libvirt.StorageVol, inStream io.Writer, Offset uint64, Length uint64, Flags libvirt.StorageVolDownloadFlags) (err error)
StorageVolGetInfo(Vol libvirt.StorageVol) (rType int8, rCapacity uint64, rAllocation uint64, err error)
NetworkLookupByName(Name string) (rNet libvirt.Network, err error)
NetworkGetXMLDesc(Net libvirt.Network, Flags uint32) (rXML string, err error)
NetworkUpdate(Net libvirt.Network, Command uint32, Section uint32, ParentIndex int32, XML string, Flags libvirt.NetworkUpdateFlags) (err error)
Expand Down
12 changes: 11 additions & 1 deletion internal/virter/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/LINBIT/virter/pkg/netcopy"
"github.com/rck/unit"

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

xml, err := v.vmVolumeXML(vmName, backingPath)
_, sizeB, _, err := v.libvirt.StorageVolGetInfo(backingVolume)
if err != nil {
return fmt.Errorf("could not get backing image info: %w", err)
}
minSize := uint64(10 * unit.G)
if sizeB < minSize {
sizeB = minSize
}

xml, err := v.vmVolumeXML(vmName, backingPath, sizeB)
if err != nil {
return err
}
Expand Down

0 comments on commit 6fcd198

Please sign in to comment.