From 192576ef1b670cc06f6f82a0b2a0d12616851451 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Fri, 6 Sep 2024 11:50:58 +0200 Subject: [PATCH] timesync: Fix automatic vsock device creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Timesync uses a vsock port for guest/host time synchronization. When timesync is in use, if the VM has no vsock device, a new one is automatically added. However this got broken in commit a5db53d as we are generating the hypervisor configuration before adding this device. The vsock device must be part of `virtualMachineConfig` before calling `cfg.SetSocketDevicesVirtualMachineConfiguration(cfg.socketDevicesConfiguration)`, and after this commit, the vsock device is only added to `virtualMachineConfig` afterwards. This means the timesync only worked if you had another vsock device configured. This fixes https://github.com/crc-org/vfkit/issues/190 Signed-off-by: Christophe Fergeau # Veuillez saisir le message de validation pour vos modifications. Les lignes # commençant par '#' seront ignorées, et un message vide abandonne la validation. # # Date : Fri Sep 6 11:50:58 2024 +0200 # # Sur la branche timesync # Votre branche est à jour avec 'teuf/timesync'. # # Modifications qui seront validées : # modifié : pkg/vf/vm.go # # Fichiers non suivis: # .goreleaser.yaml # 0001-Add-script-to-start-EFI-image.patch # 0002-misc-improvements-to-scripts.patch # 0003-setRawMode-work.patch # 0004-test-with-qemu.patch # 0005-debug-hacks.patch # cmd/vfkit/main.go.orig # cmdline.test # diff # go.mod.orig # go.mod.rej # gosec.patch # hacks.diff # lint.patch # patch # pkg/config/json.go~ # pkg/ignition/ # pkg/vf/virtionet.go.orig # pkg/vf/virtionet.go.rej # rest.md # run-sample-vm.sh # start-vm.sh # stdout/ # unixsocket.patch # vfkit # vfkit-amd64 # vfkit-arm64 # vfkit-macos12 # --- pkg/vf/vm.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/vf/vm.go b/pkg/vf/vm.go index 64aac84..8c5ef8b 100644 --- a/pkg/vf/vm.go +++ b/pkg/vf/vm.go @@ -103,6 +103,17 @@ func (cfg *VirtualMachineConfiguration) toVz() (*vz.VirtualMachineConfiguration, return nil, err } } + if cfg.config.Timesync != nil && cfg.config.Timesync.VsockPort != 0 { + // automatically add the vsock device we'll need for communication over VsockPort + vsockDev := VirtioVsock{ + Port: cfg.config.Timesync.VsockPort, + Listen: false, + } + if err := vsockDev.AddToVirtualMachineConfig(cfg); err != nil { + return nil, err + } + } + cfg.SetStorageDevicesVirtualMachineConfiguration(cfg.storageDevicesConfiguration) cfg.SetDirectorySharingDevicesVirtualMachineConfiguration(cfg.directorySharingDevicesConfiguration) cfg.SetPointingDevicesVirtualMachineConfiguration(cfg.pointingDevicesConfiguration) @@ -115,17 +126,6 @@ func (cfg *VirtualMachineConfiguration) toVz() (*vz.VirtualMachineConfiguration, // https://developer.apple.com/documentation/virtualization/vzvirtiosocketdeviceconfiguration?language=objc cfg.SetSocketDevicesVirtualMachineConfiguration(cfg.socketDevicesConfiguration) - if cfg.config.Timesync != nil && cfg.config.Timesync.VsockPort != 0 { - // automatically add the vsock device we'll need for communication over VsockPort - vsockDev := VirtioVsock{ - Port: cfg.config.Timesync.VsockPort, - Listen: false, - } - if err := vsockDev.AddToVirtualMachineConfig(cfg); err != nil { - return nil, err - } - } - valid, err := cfg.Validate() if err != nil { return nil, err