Skip to content

Commit

Permalink
vfkit: Enable timesync
Browse files Browse the repository at this point in the history
On macOS, after a host suspend, the guest clock will be out of sync.
vfkit has a --timesync feature, which resyncs the guest clock when the
host comes out of sleep.
This commit makes use of it.
  • Loading branch information
cfergeau committed Nov 15, 2022
1 parent 13999e1 commit 854dcd8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/crc/constants/constants_darwin.go
Expand Up @@ -11,6 +11,7 @@ const (
PodmanRemoteExecutableName = "podman"
TrayExecutableName = "Red Hat OpenShift Local.app"
DaemonAgentLabel = "com.redhat.crc.daemon"
QemuGAPort = 1234
)

var (
Expand Down
2 changes: 2 additions & 0 deletions pkg/crc/machine/vfkit/driver_darwin.go
Expand Up @@ -26,6 +26,8 @@ func CreateHost(machineConfig config.MachineConfig) *vfkit.Driver {
vfDriver.VsockPath = constants.TapSocketPath
vfDriver.VsockDaemonPort = constants.DaemonVsockPort

vfDriver.VsockQemuGAPort = constants.QemuGAPort

vfDriver.SharedDirs = configureShareDirs(machineConfig)

return vfDriver
Expand Down
16 changes: 16 additions & 0 deletions pkg/drivers/vfkit/driver_darwin.go
Expand Up @@ -47,6 +47,8 @@ type Driver struct {

VsockPath string
VsockDaemonPort uint

VsockQemuGAPort uint
}

func NewDriver(hostName, storePath string) *Driver {
Expand Down Expand Up @@ -252,6 +254,20 @@ func (d *Driver) Start() error {
return err
}

// when loading a VM created by a crc version predating this commit,
// d.VsockQemuGAPort will be missing from ~/.crc/machines/crc/config.json
// In such a case, assume the VM will not support time sync
if d.VsockQemuGAPort != 0 {
timesync, err := client.TimeSyncNew(d.VsockQemuGAPort)
if err != nil {
return err
}
err = vm.AddDevice(timesync)
if err != nil {
return err
}
}

args, err := vm.ToCmdLine()
if err != nil {
return err
Expand Down

0 comments on commit 854dcd8

Please sign in to comment.