]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
[TimeInfo] Introduce TimeInfo in TimeSync plugin
authorKaty Feng <fkaty@vmware.com>
Fri, 23 Dec 2022 00:25:50 +0000 (16:25 -0800)
committerKaty Feng <fkaty@vmware.com>
Fri, 23 Dec 2022 00:25:50 +0000 (16:25 -0800)
This change lays a foundation for upcoming changes to
support TimeInfo feature in open-vm-tools. TimeInfo feature
is introduced as part of TimeSync plugin and can be
used to query, set, subscribe, and receive updates for
time-related information from the host when guest is
using precisionclock to consume time from the host.

This change simply adds a new file and basic init/shutdown
routines which are called as part of TimeSync plugin
load/unload. The change also introduces a config option
to enable/disable this feature (default is off). The
feature is Linux-only for now.

Upcoming changes will add support for subscribing and
receiving TimeInfo updates.

open-vm-tools/lib/include/conf.h
open-vm-tools/services/plugins/timeSync/Makefile.am
open-vm-tools/services/plugins/timeSync/timeInfo.c [new file with mode: 0644]
open-vm-tools/services/plugins/timeSync/timeInfo.h [new file with mode: 0644]
open-vm-tools/services/plugins/timeSync/timeSync.c

index cad1563b6d3f15fe0ef5894eb253ce6c31637072..b696d64b7ec51faa0fe8a5345f6a9ff388435882 100644 (file)
  ******************************************************************************
  */
 
+/*
+ ******************************************************************************
+ * BEGIN timeSync plugin goodies.
+ */
+
+/**
+ * Defines the string used for the timeSync config file group.
+ */
+#define CONFGROUPNAME_TIMESYNC "timeSync"
+
+/**
+ * Enable (or disable) the TimeInfo API.
+ */
+#define CONFNAME_TIMESYNC_TIMEINFO_ENABLED "timeInfo.enabled"
+
+/*
+ * END timeSync goodies.
+ ******************************************************************************
+ */
+
 #endif /* __CONF_H__ */
index d0502851692150ed4d807a1985d84dbf5fd3bc88..40b7127b099b1275307d849b025e2d7ba6030e49 100644 (file)
@@ -1,5 +1,5 @@
 ################################################################################
-### Copyright (C) 2009-2016 VMware, Inc.  All rights reserved.
+### Copyright (C) 2009-2016, 2022 VMware, Inc.  All rights reserved.
 ###
 ### This program is free software; you can redistribute it and/or modify
 ### it under the terms of version 2 of the GNU General Public License as
@@ -42,5 +42,6 @@ endif
 if LINUX
 libtimeSync_la_SOURCES += slewLinux.c
 libtimeSync_la_SOURCES += pllLinux.c
+libtimeSync_la_SOURCES += timeInfo.c
 endif
 
diff --git a/open-vm-tools/services/plugins/timeSync/timeInfo.c b/open-vm-tools/services/plugins/timeSync/timeInfo.c
new file mode 100644 (file)
index 0000000..e36311e
--- /dev/null
@@ -0,0 +1,57 @@
+/*********************************************************
+ * Copyright (C) 2022 VMware, Inc. All rights reserved.
+ *
+ * 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
+ * by the Free Software Foundation version 2.1 and no later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
+ *
+ *********************************************************/
+
+/**
+ * @file timeInfo.c
+ *
+ * The feature allows tools to subscribe and receive updates from VMX when
+ * time related properties of the host change.
+ */
+
+#include "conf.h"
+#include "timeSync.h"
+#include "system.h"
+#include "vmware/tools/plugin.h"
+
+
+/**
+ * Initialize TimeInfo in TimeSync.
+ *
+ * @param[in] ctx The application context.
+ */
+void
+TimeInfo_Init(ToolsAppCtx *ctx)
+{
+   gboolean timeInfoEnabled =
+      g_key_file_get_boolean(ctx->config,
+                             CONFGROUPNAME_TIMESYNC,
+                             CONFNAME_TIMESYNC_TIMEINFO_ENABLED,
+                             NULL);
+   ASSERT(vmx86_linux);
+   g_debug("%s: TimeInfo support is %senabled.\n",
+           __FUNCTION__, !timeInfoEnabled ? "not " : "");
+}
+
+
+/**
+ * Cleans up internal TimeInfo state.
+ */
+void
+TimeInfo_Shutdown(void)
+{
+}
diff --git a/open-vm-tools/services/plugins/timeSync/timeInfo.h b/open-vm-tools/services/plugins/timeSync/timeInfo.h
new file mode 100644 (file)
index 0000000..8772de2
--- /dev/null
@@ -0,0 +1,32 @@
+/*********************************************************
+ * Copyright (C) 2022 VMware, Inc. All rights reserved.
+ *
+ * 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
+ * by the Free Software Foundation version 2.1 and no later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
+ *
+ *********************************************************/
+
+#ifndef _TIMEINFO_H_
+#define _TIMEINFO_H_
+
+/**
+ * @file timeInfo.h
+ *
+ * Functions and definitions related to TimeInfo.
+ */
+
+void TimeInfo_Init(ToolsAppCtx *ctx);
+void TimeInfo_Shutdown(void);
+
+#endif /* _TIMEINFO_H_ */
+
index 8c48cbd0dc6bd3aaad862edbeb8662b0ffc04df2..6ec9520665e94bd86724b8a875f5dc58c564338a 100644 (file)
 #include "vmware/guestrpc/timesync.h"
 #include "vmware/tools/plugin.h"
 #include "vmware/tools/utils.h"
+#include "timeInfo.h"
 
 #if !defined(__APPLE__)
 #include "vm_version.h"
@@ -1017,6 +1018,9 @@ TimeSyncShutdown(gpointer src,
 {
    TimeSyncData *data = plugin->_private;
 
+#if defined(__linux__) && !defined(USERWORLD)
+   TimeInfo_Shutdown();
+#endif
    if (data->state == TIMESYNC_RUNNING) {
       TimeSyncStopLoop(ctx, data);
    }
@@ -1056,6 +1060,9 @@ ToolsOnLoad(ToolsAppCtx *ctx)
       { TOOLS_APP_SIGNALS, VMTools_WrapArray(sigs, sizeof *sigs, ARRAYSIZE(sigs)) }
    };
 
+#if defined(__linux__) && !defined(USERWORLD)
+   TimeInfo_Init(ctx);
+#endif
    data->slewActive = FALSE;
    data->slewCorrection = FALSE;
    data->slewPercentCorrection = TIMESYNC_PERCENT_CORRECTION;