diff --git a/pkg/machine/qemu/config.go b/pkg/machine/qemu/config.go index 730dc4f038b8..3f55f5bee551 100644 --- a/pkg/machine/qemu/config.go +++ b/pkg/machine/qemu/config.go @@ -6,47 +6,18 @@ import ( "github.com/containers/podman/v4/pkg/machine" ) +var ( + // defaultQMPTimeout is the timeout duration for the + // qmp monitor interactions. + defaultQMPTimeout = 2 * time.Second +) + type Virtualization struct { artifact machine.Artifact compression machine.ImageCompression format machine.ImageFormat } -// Deprecated: MachineVMV1 is being deprecated in favor a more flexible and informative -// structure -type MachineVMV1 struct { - // CPUs to be assigned to the VM - CPUs uint64 - // The command line representation of the qemu command - CmdLine []string - // Mounts is the list of remote filesystems to mount - Mounts []machine.Mount - // IdentityPath is the fq path to the ssh priv key - IdentityPath string - // IgnitionFilePath is the fq path to the .ign file - IgnitionFilePath string - // ImageStream is the update stream for the image - ImageStream string - // ImagePath is the fq path to - ImagePath string - // Memory in megabytes assigned to the vm - Memory uint64 - // Disk size in gigabytes assigned to the vm - DiskSize uint64 - // Name of the vm - Name string - // SSH port for user networking - Port int - // QMPMonitor is the qemu monitor object for sending commands - QMPMonitor Monitorv1 - // RemoteUsername of the vm user - RemoteUsername string - // Whether this machine should run in a rootful or rootless manner - Rootful bool - // UID is the numerical id of the user that called machine - UID int -} - type MachineVM struct { // ConfigPath is the path to the configuration file ConfigPath machine.VMFile @@ -80,15 +51,6 @@ type MachineVM struct { LastUp time.Time } -type Monitorv1 struct { - // Address portion of the qmp monitor (/tmp/tmp.sock) - Address string - // Network portion of the qmp monitor (unix) - Network string - // Timeout in seconds for qmp monitor transactions - Timeout time.Duration -} - type Monitor struct { // Address portion of the qmp monitor (/tmp/tmp.sock) Address machine.VMFile @@ -97,9 +59,3 @@ type Monitor struct { // Timeout in seconds for qmp monitor transactions Timeout time.Duration } - -var ( - // defaultQMPTimeout is the timeout duration for the - // qmp monitor interactions. - defaultQMPTimeout = 2 * time.Second -) diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 390d23f078ec..0fd78645653c 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -141,89 +141,6 @@ func (p *Virtualization) NewMachine(opts machine.InitOptions) (machine.VM, error return vm, nil } -// migrateVM takes the old configuration structure and migrates it -// to the new structure and writes it to the filesystem -func migrateVM(configPath string, config []byte, vm *MachineVM) error { - fmt.Printf("Migrating machine %q\n", vm.Name) - var old MachineVMV1 - err := json.Unmarshal(config, &old) - if err != nil { - return err - } - // Looks like we loaded the older structure; now we need to migrate - // from the old structure to the new structure - _, pidFile, err := vm.getSocketandPid() - if err != nil { - return err - } - - pidFilePath := machine.VMFile{Path: pidFile} - qmpMonitor := Monitor{ - Address: machine.VMFile{Path: old.QMPMonitor.Address}, - Network: old.QMPMonitor.Network, - Timeout: old.QMPMonitor.Timeout, - } - socketPath, err := getRuntimeDir() - if err != nil { - return err - } - virtualSocketPath := filepath.Join(socketPath, "podman", vm.Name+"_ready.sock") - readySocket := machine.VMFile{Path: virtualSocketPath} - - vm.HostUser = machine.HostUser{} - vm.ImageConfig = machine.ImageConfig{} - vm.ResourceConfig = machine.ResourceConfig{} - vm.SSHConfig = machine.SSHConfig{} - - ignitionFilePath, err := machine.NewMachineFile(old.IgnitionFilePath, nil) - if err != nil { - return err - } - imagePath, err := machine.NewMachineFile(old.ImagePath, nil) - if err != nil { - return err - } - - // setReadySocket will stick the entry into the new struct - if err := vm.setReadySocket(); err != nil { - return err - } - - vm.CPUs = old.CPUs - vm.CmdLine = old.CmdLine - vm.DiskSize = old.DiskSize - vm.IdentityPath = old.IdentityPath - vm.IgnitionFile = *ignitionFilePath - vm.ImagePath = *imagePath - vm.ImageStream = old.ImageStream - vm.Memory = old.Memory - vm.Mounts = old.Mounts - vm.Name = old.Name - vm.PidFilePath = pidFilePath - vm.Port = old.Port - vm.QMPMonitor = qmpMonitor - vm.ReadySocket = readySocket - vm.RemoteUsername = old.RemoteUsername - vm.Rootful = old.Rootful - vm.UID = old.UID - - // Back up the original config file - if err := os.Rename(configPath, configPath+".orig"); err != nil { - return err - } - // Write the config file - if err := vm.writeConfig(); err != nil { - // If the config file fails to be written, put the original - // config file back before erroring - if renameError := os.Rename(configPath+".orig", configPath); renameError != nil { - logrus.Warn(renameError) - } - return err - } - // Remove the backup file - return os.Remove(configPath + ".orig") -} - // LoadVMByName reads a json file that describes a known qemu vm // and returns a vm instance func (p *Virtualization) LoadVMByName(name string) (machine.VM, error) { @@ -1139,14 +1056,8 @@ func getVMInfos() ([]*machine.ListResponse, error) { if err != nil { return err } - err = json.Unmarshal(b, vm) - if err != nil { - // Checking if the file did not unmarshal because it is using - // the deprecated config file format. - migrateErr := migrateVM(fullPath, b, vm) - if migrateErr != nil { - return migrateErr - } + if err = json.Unmarshal(b, vm); err != nil { + return err } listEntry := new(machine.ListResponse) @@ -1423,22 +1334,6 @@ func (v *MachineVM) setPIDSocket() error { return nil } -// Deprecated: getSocketandPid is being replaced by setPIDSocket and -// machinefiles. -func (v *MachineVM) getSocketandPid() (string, string, error) { - rtPath, err := getRuntimeDir() - if err != nil { - return "", "", err - } - if isRootful() { - rtPath = "/run" - } - socketDir := filepath.Join(rtPath, "podman") - pidFile := filepath.Join(socketDir, fmt.Sprintf("%s.pid", v.Name)) - qemuSocket := filepath.Join(socketDir, fmt.Sprintf("qemu_%s.sock", v.Name)) - return qemuSocket, pidFile, nil -} - func checkSockInUse(sock string) bool { if info, err := os.Stat(sock); err == nil && info.Mode()&fs.ModeSocket == fs.ModeSocket { _, err = net.DialTimeout("unix", dockerSock, dockerConnectTimeout) @@ -1560,14 +1455,7 @@ func (v *MachineVM) update() error { if err != nil { return err } - err = json.Unmarshal(b, v) - if err != nil { - err = migrateVM(v.ConfigPath.GetPath(), b, v) - if err != nil { - return err - } - } - return err + return json.Unmarshal(b, v) } func (v *MachineVM) writeConfig() error {