From: Katy Feng Date: Fri, 23 Dec 2022 00:25:50 +0000 (-0800) Subject: [TimeInfo] Introduce TimeInfo in TimeSync plugin X-Git-Tag: stable-12.2.0~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e5ff11a5927ebf711656d30166914725fd811f9;p=thirdparty%2Fopen-vm-tools.git [TimeInfo] Introduce TimeInfo in TimeSync plugin 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. --- diff --git a/open-vm-tools/lib/include/conf.h b/open-vm-tools/lib/include/conf.h index cad1563b6..b696d64b7 100644 --- a/open-vm-tools/lib/include/conf.h +++ b/open-vm-tools/lib/include/conf.h @@ -761,4 +761,24 @@ ****************************************************************************** */ +/* + ****************************************************************************** + * 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__ */ diff --git a/open-vm-tools/services/plugins/timeSync/Makefile.am b/open-vm-tools/services/plugins/timeSync/Makefile.am index d05028516..40b7127b0 100644 --- a/open-vm-tools/services/plugins/timeSync/Makefile.am +++ b/open-vm-tools/services/plugins/timeSync/Makefile.am @@ -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 index 000000000..e36311e4d --- /dev/null +++ b/open-vm-tools/services/plugins/timeSync/timeInfo.c @@ -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 index 000000000..8772de24f --- /dev/null +++ b/open-vm-tools/services/plugins/timeSync/timeInfo.h @@ -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_ */ + diff --git a/open-vm-tools/services/plugins/timeSync/timeSync.c b/open-vm-tools/services/plugins/timeSync/timeSync.c index 8c48cbd0d..6ec952066 100644 --- a/open-vm-tools/services/plugins/timeSync/timeSync.c +++ b/open-vm-tools/services/plugins/timeSync/timeSync.c @@ -120,6 +120,7 @@ #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;