mirror of
https://github.com/containers/podman.git
synced 2025-06-23 10:38:20 +08:00
Merge pull request #19964 from baude/resizeDisk
Enable disk resizing for applehv
This commit is contained in:
@ -19,8 +19,8 @@ import (
|
|||||||
|
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
gvproxy "github.com/containers/gvisor-tap-vsock/pkg/types"
|
gvproxy "github.com/containers/gvisor-tap-vsock/pkg/types"
|
||||||
"github.com/containers/podman/v4/libpod/define"
|
|
||||||
"github.com/containers/podman/v4/pkg/machine"
|
"github.com/containers/podman/v4/pkg/machine"
|
||||||
|
"github.com/containers/podman/v4/pkg/strongunits"
|
||||||
"github.com/containers/podman/v4/pkg/util"
|
"github.com/containers/podman/v4/pkg/util"
|
||||||
"github.com/containers/podman/v4/utils"
|
"github.com/containers/podman/v4/utils"
|
||||||
vfConfig "github.com/crc-org/vfkit/pkg/config"
|
vfConfig "github.com/crc-org/vfkit/pkg/config"
|
||||||
@ -123,7 +123,7 @@ func (m *MacMachine) setVfkitInfo(cfg *config.Config, readySocket machine.VMFile
|
|||||||
// addMountsToVM converts the volumes passed through the CLI to virtio-fs mounts
|
// addMountsToVM converts the volumes passed through the CLI to virtio-fs mounts
|
||||||
// and adds them to the machine
|
// and adds them to the machine
|
||||||
func (m *MacMachine) addMountsToVM(opts machine.InitOptions, virtiofsMnts *[]machine.VirtIoFs) error {
|
func (m *MacMachine) addMountsToVM(opts machine.InitOptions, virtiofsMnts *[]machine.VirtIoFs) error {
|
||||||
mounts := []machine.Mount{}
|
var mounts []machine.Mount
|
||||||
for _, volume := range opts.Volumes {
|
for _, volume := range opts.Volumes {
|
||||||
source, target, _, readOnly, err := machine.ParseVolumeFromPath(volume)
|
source, target, _, readOnly, err := machine.ParseVolumeFromPath(volume)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -264,7 +264,7 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Until the disk resize can be fixed, we ignore it
|
// Until the disk resize can be fixed, we ignore it
|
||||||
if err := m.resizeDisk(opts.DiskSize); err != nil && !errors.Is(err, define.ErrNotImplemented) {
|
if err := m.resizeDisk(strongunits.GiB(opts.DiskSize)); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ func (m *MacMachine) Set(name string, opts machine.SetOptions) ([]error, error)
|
|||||||
setErrors = append(setErrors, errors.New("new disk size smaller than existing disk size: cannot shrink disk size"))
|
setErrors = append(setErrors, errors.New("new disk size smaller than existing disk size: cannot shrink disk size"))
|
||||||
} else {
|
} else {
|
||||||
m.DiskSize = *newSize
|
m.DiskSize = *newSize
|
||||||
if err := m.resizeDisk(*opts.DiskSize); err != nil {
|
if err := m.resizeDisk(strongunits.GiB(*opts.DiskSize)); err != nil {
|
||||||
setErrors = append(setErrors, err)
|
setErrors = append(setErrors, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -944,15 +944,15 @@ func (m *MacMachine) forwardSocketPath() (*machine.VMFile, error) {
|
|||||||
return machine.NewMachineFile(filepath.Join(path, sockName), &sockName)
|
return machine.NewMachineFile(filepath.Join(path, sockName), &sockName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MacMachine) resizeDisk(newSize uint64) error {
|
// resizeDisk uses os truncate to resize (only larger) a raw disk. the input size
|
||||||
// TODO truncating is not enough; we may not be able to support resizing with raw image?
|
// is assumed GiB
|
||||||
// Leaving for now but returning an unimplemented error
|
func (m *MacMachine) resizeDisk(newSize strongunits.GiB) error {
|
||||||
|
if uint64(newSize) < m.DiskSize {
|
||||||
//if newSize < m.DiskSize {
|
// TODO this error needs to be changed to the common error. would do now but the PR for the common
|
||||||
// return fmt.Errorf("invalid disk size %d: new disk must be larger than %dGB", newSize, m.DiskSize)
|
// error has not merged
|
||||||
//}
|
return fmt.Errorf("invalid disk size %d: new disk must be larger than %dGB", newSize, m.DiskSize)
|
||||||
//return os.Truncate(m.ImagePath.GetPath(), int64(newSize))
|
}
|
||||||
return define.ErrNotImplemented
|
return os.Truncate(m.ImagePath.GetPath(), int64(newSize.ToBytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// isFirstBoot returns a bool reflecting if the machine has been booted before
|
// isFirstBoot returns a bool reflecting if the machine has been booted before
|
||||||
|
Reference in New Issue
Block a user