From cbc6946544e57447afb7a4bfd3474e58399001f9 Mon Sep 17 00:00:00 2001 From: Balaji Vijayakumar Date: Fri, 18 Nov 2022 15:06:39 +0530 Subject: [PATCH] support for driver specific pid files Signed-off-by: Balaji Vijayakumar --- cmd/limactl/stop.go | 6 +++--- docs/internal.md | 1 + pkg/qemu/qemu.go | 2 +- pkg/qemu/qemu_driver.go | 2 +- pkg/store/filenames/filenames.go | 5 ++++- pkg/store/instance.go | 12 ++++++------ pkg/vz/vm_darwin.go | 2 +- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cmd/limactl/stop.go b/cmd/limactl/stop.go index 43682352ab4..7f0a1d576a9 100644 --- a/cmd/limactl/stop.go +++ b/cmd/limactl/stop.go @@ -104,9 +104,9 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begi } func stopInstanceForcibly(inst *store.Instance) { - if inst.QemuPID > 0 { - logrus.Infof("Sending SIGKILL to the %s driver process %d", inst.VMType, inst.QemuPID) - if err := osutil.SysKill(inst.QemuPID, osutil.SigKill); err != nil { + if inst.DriverPID > 0 { + logrus.Infof("Sending SIGKILL to the %s driver process %d", inst.VMType, inst.DriverPID) + if err := osutil.SysKill(inst.DriverPID, osutil.SigKill); err != nil { logrus.Error(err) } } else { diff --git a/docs/internal.md b/docs/internal.md index 6b52f94ef2d..64dbe264aeb 100644 --- a/docs/internal.md +++ b/docs/internal.md @@ -48,6 +48,7 @@ QEMU: - `serial.sock`: QEMU serial socket, for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`) VZ: +- `vz.pid`: VZ PID - `vz-identifier`: Unique machine identifier file for a VM - `vz-efi`: EFIVariable store file for a VM diff --git a/pkg/qemu/qemu.go b/pkg/qemu/qemu.go index feaa06730a7..8a5c8b8ed30 100644 --- a/pkg/qemu/qemu.go +++ b/pkg/qemu/qemu.go @@ -622,7 +622,7 @@ func Cmdline(cfg Config) (string, []string, error) { // QEMU process args = append(args, "-name", "lima-"+cfg.Name) - args = append(args, "-pidfile", filepath.Join(cfg.InstanceDir, filenames.QemuPID)) + args = append(args, "-pidfile", filepath.Join(cfg.InstanceDir, filenames.PIDFile(*y.VMType))) return exe, args, nil } diff --git a/pkg/qemu/qemu_driver.go b/pkg/qemu/qemu_driver.go index fb2f82a9e25..2c69abd71d4 100644 --- a/pkg/qemu/qemu_driver.go +++ b/pkg/qemu/qemu_driver.go @@ -142,7 +142,7 @@ func (l *LimaQemuDriver) killQEMU(_ context.Context, _ time.Duration, qCmd *exec } qWaitErr := <-qWaitCh logrus.WithError(qWaitErr).Info("QEMU has exited, after killing forcibly") - qemuPIDPath := filepath.Join(l.Instance.Dir, filenames.QemuPID) + qemuPIDPath := filepath.Join(l.Instance.Dir, filenames.PIDFile(*l.Yaml.VMType)) _ = os.RemoveAll(qemuPIDPath) return qWaitErr } diff --git a/pkg/store/filenames/filenames.go b/pkg/store/filenames/filenames.go index 853da279da8..18c2bcee882 100644 --- a/pkg/store/filenames/filenames.go +++ b/pkg/store/filenames/filenames.go @@ -33,7 +33,6 @@ const ( Kernel = "kernel" KernelCmdline = "kernel.cmdline" Initrd = "initrd" - QemuPID = "qemu.pid" QMPSock = "qmp.sock" SerialLog = "serial.log" SerialSock = "serial.sock" @@ -66,3 +65,7 @@ const ( // ssh appends 16 bytes of random characters when it first creates the socket: // https://github.com/openssh/openssh-portable/blob/V_8_7_P1/mux.c#L1271-L1285 const LongestSock = SSHSock + ".1234567890123456" + +func PIDFile(name string) string { + return name + ".pid" +} diff --git a/pkg/store/instance.go b/pkg/store/instance.go index 1914ed090d7..fa11210c137 100644 --- a/pkg/store/instance.go +++ b/pkg/store/instance.go @@ -44,7 +44,7 @@ type Instance struct { Networks []limayaml.Network `json:"network,omitempty"` SSHLocalPort int `json:"sshLocalPort,omitempty"` HostAgentPID int `json:"hostAgentPID,omitempty"` - QemuPID int `json:"qemuPID,omitempty"` + DriverPID int `json:"driverPID,omitempty"` Errors []error `json:"errors,omitempty"` } @@ -121,19 +121,19 @@ func Inspect(instName string) (*Instance, error) { } } - inst.QemuPID, err = ReadPIDFile(filepath.Join(instDir, filenames.QemuPID)) + inst.DriverPID, err = ReadPIDFile(filepath.Join(instDir, filenames.PIDFile(*y.VMType))) if err != nil { inst.Status = StatusBroken inst.Errors = append(inst.Errors, err) } if inst.Status == StatusUnknown { - if inst.HostAgentPID > 0 && inst.QemuPID > 0 { + if inst.HostAgentPID > 0 && inst.DriverPID > 0 { inst.Status = StatusRunning - } else if inst.HostAgentPID == 0 && inst.QemuPID == 0 { + } else if inst.HostAgentPID == 0 && inst.DriverPID == 0 { inst.Status = StatusStopped - } else if inst.HostAgentPID > 0 && inst.QemuPID == 0 { - inst.Errors = append(inst.Errors, errors.New("host agent is running but qemu is not")) + } else if inst.HostAgentPID > 0 && inst.DriverPID == 0 { + inst.Errors = append(inst.Errors, errors.New("host agent is running but driver is not")) inst.Status = StatusBroken } else { inst.Errors = append(inst.Errors, fmt.Errorf("%s driver is running but host agent is not", inst.VMType)) diff --git a/pkg/vz/vm_darwin.go b/pkg/vz/vm_darwin.go index 1581dda5ac1..ffa503dae54 100644 --- a/pkg/vz/vm_darwin.go +++ b/pkg/vz/vm_darwin.go @@ -64,7 +64,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine case newState := <-machine.StateChangedNotify(): switch newState { case vz.VirtualMachineStateRunning: - pidFile := filepath.Join(driver.Instance.Dir, filenames.QemuPID) + pidFile := filepath.Join(driver.Instance.Dir, filenames.PIDFile(*driver.Yaml.VMType)) if _, err := os.Stat(pidFile); !errors.Is(err, os.ErrNotExist) { logrus.Errorf("pidfile %q already exists", pidFile) errCh <- err