From: John Wolfe Date: Wed, 19 Aug 2020 17:01:17 +0000 (-0700) Subject: Implement the Set_option handler in appInfo plugin. X-Git-Tag: stable-11.1.5~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=858534048c1036dfc8049e781f9cd6f989188b69;p=thirdparty%2Fopen-vm-tools.git Implement the Set_option handler in appInfo plugin. * Add a handler for Set_option in the 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. * Add code to handle VM vmotion to an older host that doesn't have logic to send 'set_option'. * Fix some miscellaneous issues in the appinfo plugin. Use the proper @param and @return statements in the function documentation for AppInfoServerSetOption. Reorganize an "if" code block. --- 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 4e64799b6..a722f7bcf 100644 --- a/open-vm-tools/services/plugins/appInfo/appInfo.c +++ b/open-vm-tools/services/plugins/appInfo/appInfo.c @@ -38,6 +38,7 @@ #include "util.h" #include "vm_atomic.h" #include "vmcheck.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,58 @@ AppInfoServerShutdown(gpointer src, // IN } +/* + *---------------------------------------------------------------------------- + * + * AppInfoServerSetOption -- + * + * Handle TOOLSOPTION_ENABLE_APPINFO Set_Option callback. + * + * @param[in] src The source object. + * @param[in] ctx The app context. + * @param[in] option Option being set. + * @param[in] value Option value. + * @param[in] plugin Plugin registration data. + * + * @return TRUE if the specified option is TOOLSOPTION_ENABLE_APPINFO and + * the AppInfo Gather poll loop is reconfigured. + * FALSE if the specified option is not TOOLSOPTION_ENABLE_APPINFO + * or AppInfo Gather poll loop is not reconfigured. + *---------------------------------------------------------------------------- + */ + +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("%s: Tools set option %s=%s.\n", + __FUNCTION__, 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 +691,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 +754,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,