Skip to content

Commit

Permalink
libhvee: Use libhvee APIs for disk resize
Browse files Browse the repository at this point in the history
Disk handling API was added to libhvee since the first iteration of the
libhvee support, we can now make use of it.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
  • Loading branch information
cfergeau committed May 29, 2024
1 parent f3a8f07 commit 0a0ad63
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 50 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/cavaliergopher/grab/v3 v3.0.1
github.com/cheggaaa/pb/v3 v3.1.5
github.com/containers/common v0.59.0
github.com/containers/gvisor-tap-vsock v0.7.4-0.20240320091526-a0238e52b61f
github.com/containers/image/v5 v5.31.0
github.com/containers/libhvee v0.7.1
Expand All @@ -31,7 +32,7 @@ require (
github.com/kofalt/go-memoize v0.0.0-20220914132407-0b5d6a304579
github.com/mattn/go-colorable v0.1.13
github.com/mdlayher/vsock v1.2.1
github.com/onsi/ginkgo/v2 v2.17.3
github.com/onsi/ginkgo/v2 v2.18.0
github.com/onsi/gomega v1.33.1
github.com/opencontainers/image-spec v1.1.0
github.com/openshift/api v0.0.0-20240228005710-4511c790cc60
Expand Down Expand Up @@ -77,7 +78,6 @@ require (
github.com/areYouLazy/libhosty v1.1.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/containers/common v0.57.1-0.20240205132223-de5cb00e891c // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
github.com/containers/ocicrypt v1.1.10 // indirect
github.com/containers/storage v1.54.0 // indirect
Expand Down Expand Up @@ -172,7 +172,7 @@ require (
github.com/sigstore/sigstore v1.8.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980 // indirect
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vc
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/containers/common v0.57.1-0.20240205132223-de5cb00e891c h1:Xzo9t4eIalkeilcmYTz0YEgL7hMrGQ12GK6UlSHrEsU=
github.com/containers/common v0.57.1-0.20240205132223-de5cb00e891c/go.mod h1:s1gEyucR3ryIex1aDMo1KzbfpvRl0CaGER6s5jqXRkI=
github.com/containers/common v0.59.0 h1:fy9Jz0B7Qs1C030bm73YJtVddaiFSZD3558EV1tgN2g=
github.com/containers/common v0.59.0/go.mod h1:53VicJCZ2AD0O+Br7VVoyrS7viXF4YmwlTIocWUT8XE=
github.com/containers/gvisor-tap-vsock v0.7.4-0.20240320091526-a0238e52b61f h1:NOq4UwN3M4rvN44CPznCqQlOvim7Ja1RZ082ORAJjVQ=
github.com/containers/gvisor-tap-vsock v0.7.4-0.20240320091526-a0238e52b61f/go.mod h1:hZrvqbYhTIUQCREov+M8u7sMhzGbB6umiDuVpnwtJcI=
github.com/containers/image/v5 v5.31.0 h1:eDFVlz5XaYICxe9dXpf23htEKvyosgkl62mJlIATXE4=
Expand Down Expand Up @@ -315,8 +315,8 @@ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.17.3 h1:oJcvKpIb7/8uLpDDtnQuf18xVnwKp8DTD7DQ6gTd/MU=
github.com/onsi/ginkgo/v2 v2.17.3/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc=
github.com/onsi/ginkgo/v2 v2.18.0 h1:W9Y7IWXxPUpAit9ieMOLI7PJZGaW22DTKgiVAuhDTLc=
github.com/onsi/ginkgo/v2 v2.18.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
Expand Down Expand Up @@ -410,8 +410,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980 h1:lIOOHPEbXzO3vnmx2gok1Tfs31Q8GQqKLc8vVqyQq/I=
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8=
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 h1:pnnLyeX7o/5aX8qUQ69P/mLojDqwda8hFOCBTmP/6hw=
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6/go.mod h1:39R/xuhNgVhi+K0/zst4TLrJrVmbm6LVgl4A0+ZFS5M=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
31 changes: 13 additions & 18 deletions pkg/drivers/libhvee/libhvee_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"

"github.com/containers/libhvee/pkg/hypervctl"
log "github.com/crc-org/crc/v2/pkg/crc/logging"
crcos "github.com/crc-org/crc/v2/pkg/os"
"github.com/crc-org/machine/libmachine/drivers"
"github.com/crc-org/machine/libmachine/state"

"github.com/containers/common/pkg/strongunits"
"github.com/containers/libhvee/pkg/hypervctl"
)

type Driver struct {
Expand Down Expand Up @@ -283,28 +283,23 @@ func (d *Driver) getDiskPath() string {
return d.ResolveStorePath(fmt.Sprintf("%s.%s", d.MachineName, d.ImageFormat))
}

func (d *Driver) resizeDisk(newSize int64) error {
func (d *Driver) resizeDisk(newSizeBytes int64) error {

newSize := strongunits.B(newSizeBytes)

diskPath := d.getDiskPath()
out, err := cmdOut(fmt.Sprintf("@(Get-VHD -Path %s).Size", quote(diskPath)))
currentSize, err := hypervctl.GetDiskSize(diskPath)
if err != nil {
return fmt.Errorf("unable to get current size of crc.vhdx: %w", err)
}
currentSize, err := strconv.ParseInt(strings.TrimSpace(out), 10, 64)
if err != nil {
return fmt.Errorf("unable to convert disk size to int: %w", err)
}
if newSize == currentSize {
if newSize == currentSize.ToBytes() {
log.Debugf("%s is already %d bytes", diskPath, newSize)
return nil
}
if newSize < currentSize {
return fmt.Errorf("current disk image capacity is bigger than the requested size (%d > %d)", currentSize, newSize)
if newSize < currentSize.ToBytes() {
return fmt.Errorf("current disk image capacity is bigger than the requested size (%d > %d)", currentSize.ToBytes(), newSize)
}

log.Debugf("Resizing disk from %d bytes to %d bytes", currentSize, newSize)
return cmd("Hyper-V\\Resize-VHD",
"-Path",
quote(diskPath),
"-SizeBytes",
fmt.Sprintf("%d", newSize))
log.Debugf("Resizing disk from %d bytes to %d bytes", currentSize.ToBytes(), newSize.ToBytes())
return hypervctl.ResizeDisk(diskPath, strongunits.ToGiB(newSize))
}
4 changes: 0 additions & 4 deletions pkg/drivers/libhvee/powershell_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ func isWindowsAdministrator() (bool, error) {
return resp == "True", nil
}

func quote(text string) string {
return fmt.Sprintf("'%s'", text)
}

func smbShareExists(name string) bool {
if err := cmd(fmt.Sprintf("Get-SmbShare -Name %s", name)); err != nil {
return false
Expand Down
14 changes: 14 additions & 0 deletions vendor/github.com/onsi/ginkgo/v2/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions vendor/github.com/onsi/ginkgo/v2/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/onsi/ginkgo/v2/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion vendor/github.com/onsi/ginkgo/v2/internal/suite.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion vendor/github.com/onsi/ginkgo/v2/reporters/default_reporter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/onsi/ginkgo/v2/reporters/junit_report.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions vendor/github.com/onsi/ginkgo/v2/table_dsl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/onsi/ginkgo/v2/types/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/onsi/ginkgo/v2/types/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/stefanberger/go-pkcs11uri/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 34 additions & 3 deletions vendor/github.com/stefanberger/go-pkcs11uri/pkcs11uri.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a0ad63

Please sign in to comment.