]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Implement Set_option handler in appInfo plugin.
authorOliver Kurth <okurth@vmware.com>
Wed, 10 Jun 2020 19:05:45 +0000 (12:05 -0700)
committerOliver Kurth <okurth@vmware.com>
Wed, 10 Jun 2020 19:05:45 +0000 (12:05 -0700)
* 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'.

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 3e4a259b91bd873b62c2afe84970e194e3e1c2e1..c190c247ece82e8c902c9307ff1bf8a846ef6575 100644 (file)
@@ -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,