]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Implement the Set_option handler in appInfo plugin.
authorJohn Wolfe <jwolfe@vmware.com>
Wed, 19 Aug 2020 17:01:17 +0000 (10:01 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Wed, 19 Aug 2020 17:01:17 +0000 (10:01 -0700)
* 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.

open-vm-tools/lib/include/vmware/guestrpc/tclodefs.h
open-vm-tools/services/plugins/appInfo/appInfo.c

index 564e5fd0248497a00bfac579633a300a4f9c1070..716e38195fe859adbfe29536de4f2f0282a022fb 100644 (file)
@@ -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.
index 4e64799b628bf4de72feebf93316532be4149663..a722f7bcf5f621b57f6816bdb9411f083af538f6 100644 (file)
@@ -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,