Files
podman/pkg/machine/lock/lock.go
Matt Heon 34166fc004 Bump Go version to v6
Tremendous amount of changes in here, but all should amount to
the same thing: changing Go import paths from v5 to v6.

Also bumped go.mod to github.com/containers/podman/v6 and updated
version to v6.0.0-dev.

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-10-23 11:00:15 -04:00

37 lines
995 B
Go

package lock
import (
"fmt"
"path/filepath"
"github.com/containers/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
}