Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use timesync option? #190

Closed
seanenck opened this issue Sep 5, 2024 · 3 comments
Closed

How to use timesync option? #190

seanenck opened this issue Sep 5, 2024 · 3 comments

Comments

@seanenck
Copy link

seanenck commented Sep 5, 2024

I've read the usage and understand the intention of the --timesync flag and maybe have qemu guest agent setup properly in my (Alpine Linux) VM but I don't get time sync (getting errors, see below), and am just trying to understand what specific values to specify for vfkit invocation and qemu-ga to see time sync actually work

If I simply specify --timesync without a corresponding --device virtio-vsock during vfkit, I get the following error:
error connecting to vsock port 7890: VM has too many/not enough virtio-vsock devices (0)

Which, I think, makes sense given I think I do need to specify a --device virtio-vsock from what it seems. Though I think this should likely be a configuration error as the user is asking for something that will potentially never work (and --timesync erroring here is at debug level by default so time sync will just silently fail).

So, to get time sync to work, I'd be interested to see a working vfkit host invocation with --timesync and --device virtio-vsock (and associated options for each) and the guest's qemu-ga invocation, can someone provide this?

@cfergeau
Copy link
Collaborator

cfergeau commented Sep 6, 2024

The timesync option should add a virtio-vsock device if needed.
crc is using -timesync vsockPort=1234 together with this qemu-guest-agent unit file:

$ cat /etc/systemd/system/qemu-guest-agent.service
[Unit]
Description=QEMU Guest Agent
IgnoreOnIsolate=True

[Service]
UMask=0077
EnvironmentFile=/etc/sysconfig/qemu-ga
ExecStart=/usr/bin/qemu-ga \
  --method=vsock-listen \
  --path=3:1234 \
  --blacklist=${BLACKLIST_RPC} \
  -F${FSFREEZE_HOOK_PATHNAME}
Restart=always
RestartSec=0

[Install]
WantedBy=default.target

An alternative to -timesync is to have chronyd in the guest, and to add makestep 1 -1 to its configuration.

cfergeau added a commit to cfergeau/vfkit that referenced this issue Sep 6, 2024
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 were generating the
hypervisor configuration before adding this device.

This means timesync only worked if you had another vsock device
configured.

This fixes crc-org#190

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
@cfergeau
Copy link
Collaborator

cfergeau commented Sep 6, 2024

The timesync option should add a virtio-vsock device if needed.

This automatic addition is currently broken in git, #191 should fix it. In the mean time, you can add another virtio-vsock device to your VM, this should workaround the issue and allow timesync to work.

@seanenck
Copy link
Author

seanenck commented Sep 6, 2024

Thanks for putting the pieces together for me.

cfergeau added a commit to cfergeau/vfkit that referenced this issue Sep 20, 2024
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 crc-org#190

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>

# 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
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants