mirror of https://github.com/containers/podman.git
podman machine set: change options only locked
Make sure we only update the machine config when we are locked. While it doesn't make a functional differnce for cpu and memory it was a problem for disk size. The disk size must be larger than the previous one so we must have accurate data on the previous value. Thus change the settings only while locked and refresh the config so we have the current up to date values. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
56e0f063bd
commit
3c9c5be7da
|
@ -3,8 +3,6 @@
|
|||
package machine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/strongunits"
|
||||
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||
|
@ -90,10 +88,6 @@ func init() {
|
|||
}
|
||||
|
||||
func setMachine(cmd *cobra.Command, args []string) error {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
vmName := defaultMachineName
|
||||
if len(args) > 0 && len(args[0]) > 0 {
|
||||
vmName = args[0]
|
||||
|
@ -113,20 +107,14 @@ func setMachine(cmd *cobra.Command, args []string) error {
|
|||
setOpts.Rootful = &setFlags.Rootful
|
||||
}
|
||||
if cmd.Flags().Changed("cpus") {
|
||||
mc.Resources.CPUs = setFlags.CPUs
|
||||
setOpts.CPUs = &mc.Resources.CPUs
|
||||
setOpts.CPUs = &setFlags.CPUs
|
||||
}
|
||||
if cmd.Flags().Changed("memory") {
|
||||
mc.Resources.Memory = strongunits.MiB(setFlags.Memory)
|
||||
setOpts.Memory = &mc.Resources.Memory
|
||||
newMemory := strongunits.MiB(setFlags.Memory)
|
||||
setOpts.Memory = &newMemory
|
||||
}
|
||||
if cmd.Flags().Changed("disk-size") {
|
||||
newDiskSizeGB := strongunits.GiB(setFlags.DiskSize)
|
||||
if newDiskSizeGB <= mc.Resources.DiskSize {
|
||||
return fmt.Errorf("new disk size must be larger than %d GB", mc.Resources.DiskSize)
|
||||
}
|
||||
mc.Resources.DiskSize = newDiskSizeGB
|
||||
|
||||
setOpts.DiskSize = &newDiskSizeGB
|
||||
}
|
||||
if cmd.Flags().Changed("user-mode-networking") {
|
||||
|
|
|
@ -485,6 +485,25 @@ func Set(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, opts machineDefin
|
|||
mc.Lock()
|
||||
defer mc.Unlock()
|
||||
|
||||
if err := mc.Refresh(); err != nil {
|
||||
return fmt.Errorf("reload config: %w", err)
|
||||
}
|
||||
|
||||
if opts.CPUs != nil {
|
||||
mc.Resources.CPUs = *opts.CPUs
|
||||
}
|
||||
|
||||
if opts.Memory != nil {
|
||||
mc.Resources.Memory = *opts.Memory
|
||||
}
|
||||
|
||||
if opts.DiskSize != nil {
|
||||
if *opts.DiskSize <= mc.Resources.DiskSize {
|
||||
return fmt.Errorf("new disk size must be larger than %d GB", mc.Resources.DiskSize)
|
||||
}
|
||||
mc.Resources.DiskSize = *opts.DiskSize
|
||||
}
|
||||
|
||||
if err := mp.SetProviderAttrs(mc, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue