From 187f57a0aa411a1888425ebe2df1286d7cc7f6d0 Mon Sep 17 00:00:00 2001 From: Karel Van Hecke <25814162+karelvanhecke@users.noreply.github.com> Date: Sat, 25 Feb 2023 15:22:22 +0100 Subject: [PATCH 1/2] coreos-platform-chrony-config: use `ptp_kvm` when available on QEMU KVM supports a `ptp_kvm` kernel module which allows the guest to query the host clock for synchronization purposes. Configure chrony to make use of it if it's available. Don't disable the default pool; it'll be used by chrony to determine whether the host clock is accurate or a falseticker. Don't disable `PEERNTP` as we do on other platforms since we historically haven't done so on QEMU and it's possible users have been using their own DHCP servers (e.g. dnsmasq) to feed NTP configuration. Closes: https://github.com/coreos/fedora-coreos-tracker/issues/1433 Co-authored-by: Jonathan Lebon --- .../coreos-platform-chrony-config.service | 1 + .../usr/libexec/coreos-platform-chrony-config | 24 +++++++++++++++---- .../chrony/coreos-platform-chrony-generator | 8 ++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/overlay.d/20platform-chrony/usr/lib/systemd/system/coreos-platform-chrony-config.service b/overlay.d/20platform-chrony/usr/lib/systemd/system/coreos-platform-chrony-config.service index f64f84da58..6a1bce8823 100644 --- a/overlay.d/20platform-chrony/usr/lib/systemd/system/coreos-platform-chrony-config.service +++ b/overlay.d/20platform-chrony/usr/lib/systemd/system/coreos-platform-chrony-config.service @@ -4,6 +4,7 @@ ConditionKernelCommandLine=|ignition.platform.id=azurestack ConditionKernelCommandLine=|ignition.platform.id=azure ConditionKernelCommandLine=|ignition.platform.id=aws ConditionKernelCommandLine=|ignition.platform.id=gcp +ConditionKernelCommandLine=|ignition.platform.id=qemu Before=NetworkManager.service Before=chronyd.service diff --git a/overlay.d/20platform-chrony/usr/libexec/coreos-platform-chrony-config b/overlay.d/20platform-chrony/usr/libexec/coreos-platform-chrony-config index 4f69312f74..686d583bad 100755 --- a/overlay.d/20platform-chrony/usr/libexec/coreos-platform-chrony-config +++ b/overlay.d/20platform-chrony/usr/libexec/coreos-platform-chrony-config @@ -19,9 +19,6 @@ if ! cmp {/usr,}/etc/chrony.conf >/dev/null; then exit 0 fi -mkdir -p /run/coreos -confpath=/run/coreos/platform-chrony.conf -altenvfilepath=/run/coreos/sysconfig-chrony cmdline=( $(> /etc/sysconfig/network + # Historically on QEMU, we haven't been disabling PEERNTP. Let's keep doing + # that even if we have ptp_kvm. chrony will just use the NTP servers as + # additional sources. + if [[ ${platform} != "qemu" ]]; then + cat <> /etc/sysconfig/network # PEERNTP=no is automatically added by default when a platform-provided time # source is available, but this behavior may be overridden through an Ignition # config specifying PEERNTP=yes. See https://github.com/coreos/fedora-coreos-config/pull/412. PEERNTP=no EOF + fi fi (echo "# Generated by $self - do not edit directly" @@ -77,6 +88,11 @@ case "${platform}" in echo '# and https://cloud.google.com/compute/docs/images/configuring-imported-images' echo 'server metadata.google.internal prefer iburst' ) >> "${confpath}" ;; + qemu) + sed -i s,'^#pool,pool,' "${confpath}" + (echo '# KVM virtual PHC' + echo 'refclock PHC /dev/ptp0 poll 2' + ) >> "${confpath}" ;; *) echo "should not be reached" 1>&2; exit 1 ;; esac # Policy doesn't allow chronyd to read run_t diff --git a/tests/kola/ntp/chrony/coreos-platform-chrony-generator b/tests/kola/ntp/chrony/coreos-platform-chrony-generator index 7460509dc1..04ad465a73 100755 --- a/tests/kola/ntp/chrony/coreos-platform-chrony-generator +++ b/tests/kola/ntp/chrony/coreos-platform-chrony-generator @@ -1,7 +1,7 @@ #!/bin/bash ## kola: ## exclusive: false -## platforms: "aws azure gce" +## platforms: "aws azure gce qemu" # # Test the coreos-platform-chrony generator. @@ -14,5 +14,11 @@ case "${platform}" in aws) chronyc sources |grep '169.254.169.123'; echo "ok chrony aws" ;; azure) chronyc sources |grep 'PHC'; echo "ok chrony azure" ;; gcp) chronyc sources | grep '169.254.169.254'; echo "ok chrony gcp" ;; + qemu) + # ptp_kvm isn't available on all arches nor all hosts, so don't assume it's always there; see + # https://github.com/coreos/fedora-coreos-config/pull/2263#discussion_r1157694192 + if lsmod | grep -q ptp_kvm; then + chronyc sources | grep 'PHC0'; echo "ok chrony qemu" + fi ;; *) echo "unhandled platform ${platform} ?"; exit 1 ;; esac From edb36fbee970eeb909f5ad1e1a680d46ed8596f6 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 23 Mar 2023 17:17:52 -0400 Subject: [PATCH 2/2] Rename coreos-platform-chrony-generator to coreos-platform-chrony-config The chrony generator was converted to a regular systemd unit in 5e4f40c0 ("Move chrony config from generator to systemd service"). Let's rename the test to reflect this. --- ...os-platform-chrony-generator => coreos-platform-chrony-config} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/kola/ntp/chrony/{coreos-platform-chrony-generator => coreos-platform-chrony-config} (100%) diff --git a/tests/kola/ntp/chrony/coreos-platform-chrony-generator b/tests/kola/ntp/chrony/coreos-platform-chrony-config similarity index 100% rename from tests/kola/ntp/chrony/coreos-platform-chrony-generator rename to tests/kola/ntp/chrony/coreos-platform-chrony-config