From: Oliver Kurth Date: Wed, 10 Jun 2020 19:05:45 +0000 (-0700) Subject: Implement Set_option handler in appInfo plugin. X-Git-Tag: stable-11.2.0~163 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dca1937e894674fa41e7e0e2f622fb297ab74c08;p=thirdparty%2Fopen-vm-tools.git Implement Set_option handler in appInfo plugin. * Added a handler for the Set_option for appInfo plugin. The poll loop will be immediately turned off when the feature is turned off at the host side. The poll loop will be immediately turned on when the feature is turned on at the host side. * Added the code to handle VM vmotion to an older host that doesn't have logic to send 'set_option'. --- diff --git a/open-vm-tools/lib/include/vmware/guestrpc/tclodefs.h b/open-vm-tools/lib/include/vmware/guestrpc/tclodefs.h index 564e5fd02..716e38195 100644 --- a/open-vm-tools/lib/include/vmware/guestrpc/tclodefs.h +++ b/open-vm-tools/lib/include/vmware/guestrpc/tclodefs.h @@ -65,6 +65,7 @@ #define TOOLSOPTION_LINK_ROOT_HGFS_SHARE "linkRootHgfsShare" #define TOOLSOPTION_ENABLE_MESSAGE_BUS_TUNNEL "enableMessageBusTunnel" #define TOOLSOPTION_GUEST_LOG_LEVEL "guestLogLevel" +#define TOOLSOPTION_ENABLE_APPINFO "enableAppInfo" /* * Auto-upgrade commands. diff --git a/open-vm-tools/services/plugins/appInfo/appInfo.c b/open-vm-tools/services/plugins/appInfo/appInfo.c index 3e4a259b9..c190c247e 100644 --- a/open-vm-tools/services/plugins/appInfo/appInfo.c +++ b/open-vm-tools/services/plugins/appInfo/appInfo.c @@ -38,6 +38,7 @@ #include "vm_atomic.h" #include "vmcheck.h" #include "vmware/guestrpc/appInfo.h" +#include "vmware/guestrpc/tclodefs.h" #include "vmware/tools/log.h" #include "vmware/tools/threadPool.h" #include "vmware/tools/utils.h" @@ -88,6 +89,11 @@ VM_EMBED_VERSION(VMTOOLSD_VERSION_STRING); */ static guint gAppInfoPollInterval = 0; +/** + * Defines the state of the App Info at the host side. + */ +static gboolean gAppInfoEnabledInHost = TRUE; + /** * AppInfo gather loop timeout source. */ @@ -500,9 +506,9 @@ TweakGatherLoop(ToolsAppCtx *ctx, // IN CONFNAME_APPINFO_DISABLED, APP_INFO_CONF_DEFAULT_DISABLED_VALUE); - gint pollInterval = 0; + gint pollInterval; - if (!disabled) { + if (gAppInfoEnabledInHost && !disabled) { pollInterval = VMTools_ConfigGetInteger(ctx->config, CONFGROUPNAME_APPINFO, CONFNAME_APPINFO_POLLINTERVAL, @@ -513,6 +519,8 @@ TweakGatherLoop(ToolsAppCtx *ctx, // IN __FUNCTION__, pollInterval, APP_INFO_POLL_INTERVAL); pollInterval = APP_INFO_POLL_INTERVAL; } + } else { + pollInterval = 0; } if (force || (gAppInfoPollInterval != pollInterval)) { @@ -576,6 +584,54 @@ AppInfoServerShutdown(gpointer src, // IN } +/* + *---------------------------------------------------------------------------- + * + * AppInfoServerSetOption -- + * + * Handle TOOLSOPTION_ENABLE_APPINFO Set_Option callback. + * + * Results: + * TRUE on success. + * + * Side-effects: + * None + * + *---------------------------------------------------------------------------- + */ + +static gboolean +AppInfoServerSetOption(gpointer src, // IN + ToolsAppCtx *ctx, // IN + const gchar *option, // IN + const gchar *value, // IN + gpointer data) // IN +{ + gboolean retVal = FALSE; + + if (strcmp(option, TOOLSOPTION_ENABLE_APPINFO) == 0) { + g_debug("Tools set option %s=%s.\n", + TOOLSOPTION_ENABLE_APPINFO, value); + + if (strcmp(value, "1") == 0 && !gAppInfoEnabledInHost) { + gAppInfoEnabledInHost = TRUE; + retVal = TRUE; + } else if (strcmp(value, "0") == 0 && gAppInfoEnabledInHost) { + gAppInfoEnabledInHost = FALSE; + retVal = TRUE; + } + } + + if (retVal) { + g_info("%s: State of AppInfo is changed to '%s' at host side.\n", + __FUNCTION__, gAppInfoEnabledInHost ? "enabled" : "disabled"); + TweakGatherLoop(ctx, TRUE); + } + + return retVal; +} + + /* ****************************************************************************** * AppInfoServerReset -- @@ -631,7 +687,18 @@ AppInfoServerReset(gpointer src, TweakGatherLoopEx(ctx, interval); } else { - g_debug("%s: Poll loop disabled. Ignoring.\n", __FUNCTION__); + /* + * Channel got reset. VM might have vMotioned to an older host + * that doesn't send the 'Set_Option enableAppInfo'. + * Set gAppInfoEnabledInHost to TRUE and tweak the gather loop. + * Else, the application information may never be captured. + */ + if (!gAppInfoEnabledInHost) { + gAppInfoEnabledInHost = TRUE; + TweakGatherLoop(ctx, TRUE); + } else { + g_debug("%s: Poll loop disabled. Ignoring.\n", __FUNCTION__); + } } } @@ -683,7 +750,8 @@ ToolsOnLoad(ToolsAppCtx *ctx) // IN ToolsPluginSignalCb sigs[] = { { TOOLS_CORE_SIG_CONF_RELOAD, AppInfoServerConfReload, NULL }, { TOOLS_CORE_SIG_SHUTDOWN, AppInfoServerShutdown, NULL }, - { TOOLS_CORE_SIG_RESET, AppInfoServerReset, NULL } + { TOOLS_CORE_SIG_RESET, AppInfoServerReset, NULL }, + { TOOLS_CORE_SIG_SET_OPTION, AppInfoServerSetOption, NULL } }; ToolsAppReg regs[] = { { TOOLS_APP_SIGNALS,