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 authored and praveenkumar committed Dec 1, 2022
1 parent a3aca7b commit db63999
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/crc/constants/constants_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
PodmanRemoteExecutableName = "podman"
TrayExecutableName = "Red Hat OpenShift Local.app"
DaemonAgentLabel = "com.redhat.crc.daemon"
QemuGuestAgentPort = 1234
)

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

vfDriver.QemuGAVsockPort = constants.QemuGuestAgentPort

vfDriver.SharedDirs = configureShareDirs(machineConfig)

return vfDriver
Expand Down
15 changes: 15 additions & 0 deletions pkg/drivers/vfkit/driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Driver struct {

VsockPath string
DaemonVsockPort uint
QemuGAVsockPort uint
}

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

// when loading a VM created by a crc version predating this commit,
// d.QemuGAVsockPort will be missing from ~/.crc/machines/crc/config.json
// In such a case, assume the VM will not support time sync
if d.QemuGAVsockPort != 0 {
timesync, err := client.TimeSyncNew(d.QemuGAVsockPort)
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 db63999

Please sign in to comment.