Skip to content

Commit

Permalink
No longer support deprecated legacy QEMU machine structures
Browse files Browse the repository at this point in the history
Removes the `MachineVMV1` and `MonitorV1` structures that have been
deprecated for a long enough period of time that it makes sense to no
longer support them.

Results in the removal of deprecated `getSocketAndPid` as well.

The migration code was added in commit
`6e0e1cbddd5e1c5dff51215ad2b41a99d890fad8` and made it into release `v4.1.0`

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <[email protected]>
  • Loading branch information
jakecorrenti committed Nov 21, 2023
1 parent ee5f582 commit 2b95700
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 166 deletions.
66 changes: 8 additions & 58 deletions pkg/machine/qemu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import (
"github.com/sirupsen/logrus"
)

var (
// defaultQMPTimeout is the timeout duration for the
// qmp monitor interactions.
defaultQMPTimeout = 2 * time.Second
)

type QEMUVirtualization struct {
machine.Virtualization
}
Expand Down Expand Up @@ -238,14 +244,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)

Expand Down Expand Up @@ -400,53 +400,3 @@ func VirtualizationProvider() machine.VirtProvider {
machine.NewVirtualization(define.Qemu, compression.Xz, define.Qcow, vmtype),
}
}

// 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 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
}

var (
// defaultQMPTimeout is the timeout duration for the
// qmp monitor interactions.
defaultQMPTimeout = 2 * time.Second
)
109 changes: 1 addition & 108 deletions pkg/machine/qemu/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,90 +107,6 @@ type Monitor struct {
Timeout time.Duration
}

// 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 := define.VMFile{Path: pidFile}
qmpMonitor := Monitor{
Address: define.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 := define.VMFile{Path: virtualSocketPath}

vm.HostUser = machine.HostUser{}
vm.ImageConfig = machine.ImageConfig{}
vm.ResourceConfig = machine.ResourceConfig{}
vm.SSHConfig = machine.SSHConfig{}

ignitionFilePath, err := define.NewMachineFile(old.IgnitionFilePath, nil)
if err != nil {
return err
}
imagePath, err := define.NewMachineFile(old.ImagePath, nil)
if err != nil {
return err
}

// setReadySocket will stick the entry into the new struct
symlink := vm.Name + "_ready.sock"
if err := machine.SetSocket(&vm.ReadySocket, machine.ReadySocketPath(socketPath+"/podman/", vm.Name), &symlink); 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")
}

// addMountsToVM converts the volumes passed through the CLI into the specified
// volume driver and adds them to the machine
func (v *MachineVM) addMountsToVM(opts machine.InitOptions) error {
Expand Down Expand Up @@ -1398,22 +1314,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)
Expand Down Expand Up @@ -1444,14 +1344,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 {
Expand Down

0 comments on commit 2b95700

Please sign in to comment.