]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Provide a tools.conf setting to disable timesync plugin
authorKruti Pendharkar <kp025370@broadcom.com>
Tue, 25 Feb 2025 09:29:11 +0000 (01:29 -0800)
committerKruti Pendharkar <kp025370@broadcom.com>
Tue, 25 Feb 2025 09:29:11 +0000 (01:29 -0800)
This change intends to address a customer issue that requires an
in-guest config to disable timesync without having to reboot VM or
restart. Although we have some ways to implement it from host side,
customer claimed the guest administator may not be the administrator
of vSphere so that an in-guest approach is still needed.

This change adds two config options under "timeSync" group:
- disable-all: This disables all time sync including one-time sync
  and periodic sync.
- disable-periodic: This disables periodic sync only.
  Note we cannot disable one-time sync and keep periodic sync enabled
  as this is not allowed according to the product design.

Addresses Issue: https://github.com/vmware/open-vm-tools/issues/302

open-vm-tools/lib/include/conf.h
open-vm-tools/services/plugins/timeSync/timeSync.c
open-vm-tools/tools.conf

index b48fd7754fe3aeb716c52c4380c570a328ad6ef7..eca86fe423c86b17bd2fc7f0358755350b8e86b3 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (c) 2002-2024 Broadcom. All Rights Reserved.
+ * Copyright (c) 2002-2025 Broadcom. All Rights Reserved.
  * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
  */
 #define CONFNAME_TIMESYNC_TIMEINFO_ENABLED "timeInfo.enabled"
 
+/**
+ * Defines the configuration to perform all time synchronization or not.
+ *
+ * @note Illegal values result in a @c g_warning and fallback to the default
+ * value.
+ *
+ * @param boolean If TRUE, all time synchronization is disabled.
+ *                If FALSE, one-time synchronization is enabled and periodic
+ *                synchronization is controlled by disable-periodic.
+ */
+#define CONFNAME_TIMESYNC_DISABLE_ALL "disable-all"
+
+/**
+ * Defines the configuration to perform periodic time synchronization or not.
+ *
+ * @note Illegal values result in a @c g_warning and fallback to the default
+ * value.
+ *
+ * @param boolean If TRUE, periodic time synchronization is disabled.
+ *                If FALSE, periodic time synchronization is enabled if
+ *                disable-all is also FALSE.
+ */
+#define CONFNAME_TIMESYNC_DISABLE_PERIODIC "disable-periodic"
+
 /*
  * END timeSync goodies.
  ******************************************************************************
index b97accff556377cc681eb2477df407c3555cd715..7c07614fdaf5fb110cc523748717dbd30af42a6c 100644 (file)
@@ -1,5 +1,6 @@
 /*********************************************************
- * Copyright (C) 2008-2022 VMware, Inc. All rights reserved.
+ * Copyright (c) 2008-2025 Broadcom. All Rights Reserved.
+ * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -151,6 +152,10 @@ VM_EMBED_VERSION(VMTOOLSD_VERSION_STRING);
 /* Period during which the frequency error of guest time is measured. */
 #define TIMESYNC_CALIBRATION_DURATION (15 * 60 * US_PER_SEC) /* 15min. */
 
+/* Default values for timeSync settings in tools config file. */
+#define CONFNAME_TIMESYNC_DISABLE_ALL_DEFAULT      FALSE
+#define CONFNAME_TIMESYNC_DISABLE_PERIODIC_DEFAULT FALSE
+
 typedef enum TimeSyncState {
    TIMESYNC_INITIALIZING,
    TIMESYNC_STOPPED,
@@ -612,10 +617,10 @@ TimeSyncGuestResyncTimeoutHandler(gpointer _data)
  */
 
 static gboolean
-TimeSyncDoSync(Bool slewCorrection,
-               TimeSyncType syncType,
-               Bool allowBackwardSync,
-               void *_data)
+TimeSyncDoSyncWork(Bool slewCorrection,
+                   TimeSyncType syncType,
+                   Bool allowBackwardSync,
+                   void *_data)
 {
    int64 guest, host;
    int64 gosError, apparentError, maxTimeError;
@@ -628,7 +633,7 @@ TimeSyncDoSync(Bool slewCorrection,
            syncType, slewCorrection, allowBackwardSync,
            data->guestResync, data->guestResyncTimeout);
 
-   if (!TimeSyncReadHostAndGuest(&host, &guest, &apparentError, 
+   if (!TimeSyncReadHostAndGuest(&host, &guest, &apparentError,
                                  &apparentErrorValid, &maxTimeError)) {
       return FALSE;
    }
@@ -651,7 +656,7 @@ TimeSyncDoSync(Bool slewCorrection,
        * step correction.
        */
 
-      if (gosError < -maxTimeError || 
+      if (gosError < -maxTimeError ||
           (gosError + apparentError > 0 && allowBackwardSync)) {
          if (syncType == TIMESYNC_STEP && data->guestResync &&
              TimeSync_IsGuestSyncServiceRunning()) {
@@ -660,9 +665,9 @@ TimeSyncDoSync(Bool slewCorrection,
                ASSERT(data->ctx != NULL);
                if (!TimeSync_DoGuestResync(data->ctx)) {
                   g_warning("Guest resync operation failed.\n");
-                  return TimeSyncDoSync(data->slewCorrection,
-                                        TIMESYNC_STEP_NORESYNC,
-                                        allowBackwardSync, data);
+                  return TimeSyncDoSyncWork(data->slewCorrection,
+                                            TIMESYNC_STEP_NORESYNC,
+                                            allowBackwardSync, data);
                }
                if (data->guestResyncTimeout > 0) {
                   data->guestResyncTimer =
@@ -715,6 +720,51 @@ TimeSyncDoSync(Bool slewCorrection,
 }
 
 
+/**
+ * Check the Tools config of timeSync, skip time sync if it is disabled,
+ * call TimeSyncDoSyncWork to sync time otherwise.
+ *
+ * @param[in]  slewCorrection    Is clock slewing enabled?
+ * @param[in]  syncType          Type of synchronization requested.
+ * @param[in]  allowBackwardSync Can we sync time backwards when doing
+ *    step/resync correction?
+ * @param[in]  _data             Time sync data.
+ *
+ * @return TRUE on success or when timeSync is disabled.
+ */
+
+static gboolean
+TimeSyncDoSync(Bool slewCorrection,
+               TimeSyncType syncType,
+               Bool allowBackwardSync,
+               void *_data)
+{
+   TimeSyncData *data = _data;
+   Bool disableAll =
+      VMTools_ConfigGetBoolean(data->ctx->config,
+                               CONFGROUPNAME_TIMESYNC,
+                               CONFNAME_TIMESYNC_DISABLE_ALL,
+                               CONFNAME_TIMESYNC_DISABLE_ALL_DEFAULT);
+   Bool disablePeriodic =
+      VMTools_ConfigGetBoolean(data->ctx->config,
+                               CONFGROUPNAME_TIMESYNC,
+                               CONFNAME_TIMESYNC_DISABLE_PERIODIC,
+                               CONFNAME_TIMESYNC_DISABLE_PERIODIC_DEFAULT);
+   /*
+    * Skip all time sync or the periodic type of time sync if they are
+    * configured to be disabled in the Tools config. Return TRUE so that
+    * nothing in timeSync plugin is broken and the sync can be re-enabled
+    * seamlessly, this also avoids warning logs on the FALSE returns.
+    */
+   if (disableAll || (disablePeriodic && syncType == TIMESYNC_PERIODIC)) {
+      g_debug("Time synchronization is disabled.\n");
+      return TRUE;
+   }
+   return TimeSyncDoSyncWork(slewCorrection, syncType, allowBackwardSync,
+                             _data);
+}
+
+
 /**
  * Run the "time synchronization" loop.
  *
index 52d604323db35285ffa5d106189fed6be1210571..93ab4e41ab56607cbfa8bfc57612425ad40060de 100644 (file)
 # Values lesser than the minimum will use the minimum (4096) value.
 # Values greater than the maximum will use the maximum (524288) value.
 #amsi-max-script-size-in-bytes=262144
+
+[timeSync]
+
+# The timeSync plugin synchronizes guest system time with that of the host.
+
+# The value of disable-all is a true or false; the default is false.
+# If true, all time synchronization is disabled.
+# If false, one-time synchronization is enabled and periodic synchronization
+# is controlled by disable-periodic.
+#disable-all=false
+
+# The value of disable-periodic is a true or false; the default is false.
+# If true, periodic time synchronization is disabled.
+# If false, periodic time synchronization is enabled if disable-all is also
+# false.
+#disable-periodic=false