Files
podman/pkg/machine/lock/lock.go
Brent Baude 2cc3be7332 RUN-4539: Change podman module paths
The podman module paths are moving from github.com/containers/podman to
go.podman.io/podman.  This will help with future mobility.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2026-04-22 14:02:25 -05:00

37 lines
986 B
Go

package lock
import (
"fmt"
"path/filepath"
"go.podman.io/podman/v6/pkg/machine/env"
"go.podman.io/storage/pkg/lockfile"
)
func GetMachineLock(name string, machineConfigDir string) (*lockfile.LockFile, error) {
lockPath := filepath.Join(machineConfigDir, name+".lock")
lock, err := lockfile.GetLockFile(lockPath)
if err != nil {
return nil, fmt.Errorf("creating lockfile for VM: %w", err)
}
return lock, nil
}
const machineStartLockName = "machine-start.lock"
// GetMachineStartLock is a lock only used to prevent starting different machines at the same time,
// This is required as most provides support at max 1 running VM and to check this race free we
// cannot allows starting two machine.
func GetMachineStartLock() (*lockfile.LockFile, error) {
lockDir, err := env.GetGlobalDataDir()
if err != nil {
return nil, err
}
lock, err := lockfile.GetLockFile(filepath.Join(lockDir, machineStartLockName))
if err != nil {
return nil, err
}
return lock, nil
}