From: Oliver Kurth Date: Fri, 2 Nov 2018 22:28:25 +0000 (-0700) Subject: Update the tools side code to send VMX the health status event. X-Git-Tag: stable-11.0.0~321 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1917eaa8c088363cb4470b929081f6036f3edcc;p=thirdparty%2Fopen-vm-tools.git Update the tools side code to send VMX the health status event. --- diff --git a/open-vm-tools/services/vmtoolsd/mainLoop.c b/open-vm-tools/services/vmtoolsd/mainLoop.c index bf6dde84a..7e0d337a8 100644 --- a/open-vm-tools/services/vmtoolsd/mainLoop.c +++ b/open-vm-tools/services/vmtoolsd/mainLoop.c @@ -355,6 +355,8 @@ ToolsCoreResetSignalCb(gpointer src, // IN { g_info("Reinitialize the Vmx Guest Logger with a new RPC channel.\n"); VMTools_SetupVmxGuestLog(TRUE, ctx->config, NULL); /* New RPC channel */ + g_info("Clear out the tools hang detector RPC cache state\n"); + ToolsCoreHangDetector_RpcReset(); } diff --git a/open-vm-tools/services/vmtoolsd/toolsHangDetector.c b/open-vm-tools/services/vmtoolsd/toolsHangDetector.c index 62386750d..25fb8cd29 100644 --- a/open-vm-tools/services/vmtoolsd/toolsHangDetector.c +++ b/open-vm-tools/services/vmtoolsd/toolsHangDetector.c @@ -28,7 +28,8 @@ #include "vmware/tools/log.h" #include "vmware/tools/threadPool.h" #include "toolsHangDetector.h" - +#include "vmware/guestrpc/tclodefs.h" +#include "vmware/tools/guestrpc.h" #define SLEEP_INTERVAL 1 /* approximately 1 second */ #define CHECKIN_INTERVAL 1 /* approximately 1 second */ @@ -55,6 +56,7 @@ typedef struct HangDetectorState { * a resource contention. */ gint64 timeSeq[COUNTER_RESET_VALUE+1]; + gboolean vmxRejectedHealthUpdate; } HangDetectorState; static HangDetectorState gDetectorState; @@ -80,6 +82,7 @@ DetectorInit(void) state->terminate = FALSE; state->mode = NORMAL; + state->vmxRejectedHealthUpdate = FALSE; g_atomic_int_set(&state->atomic, COUNTER_RESET_VALUE); } @@ -149,7 +152,36 @@ DetectorTerminate(ToolsAppCtx *ctx, static void UpdateVmx(const char *event) { - /* TBD */ + HangDetectorState *state = &gDetectorState; + RpcChannel *chan; + gchar *msg; + + if (state->vmxRejectedHealthUpdate) { + return; + } + + chan = BackdoorChannel_New(); + if (NULL == chan) { + g_warning("Failed to create a RPCI channel to send tools health event.\n"); + return; + } + + if (!RpcChannel_Start(chan)) { + g_warning("Failed to start a RPCI channel to send tools health event.\n"); + RpcChannel_Destroy(chan); + return; + } + + msg = g_strdup_printf("%s %s", UPDATE_TOOLS_HEALTH_CMD, event); + ASSERT(NULL != msg); + + if(!RpcChannel_Send(chan, msg, strlen(msg), NULL, NULL)) { + g_warning("Failed to send RPCI message: %s\n", msg); + state->vmxRejectedHealthUpdate = TRUE; + } + + g_free(msg); + RpcChannel_Destroy(chan); } @@ -224,11 +256,11 @@ UpdateStateToHung(void) if (elapsed > SLEEP_INTERVAL * COUNTER_RESET_VALUE * STARVE_THRESHOLD) { g_info("tools service was slow for the last %.2f seconds.", elapsed); - UpdateVmx("slow"); + UpdateVmx(TOOLS_HEALTH_GUEST_SLOW_KEY); } else { g_info("tools service hung."); - UpdateVmx("hang"); + UpdateVmx(TOOLS_HEALTH_HUNG_KEY); } } @@ -251,7 +283,7 @@ UpdateStateToNormal(void) g_info("tools service recovered from a hang."); - UpdateVmx("recover"); + UpdateVmx(TOOLS_HEALTH_NORMAL_KEY); } @@ -477,3 +509,24 @@ exit: return ret; } + + +/* + ****************************************************************************** + * ToolsCoreHangDetector_RpcReset -- */ /** + * + * Rpc Reset Handler for the tools hang detector module. + * Just reset the vmxRejectedHealthUpdate boolean flag in case + * the VM is migrated to a newer version of host that now supports the + * health update. + * + ****************************************************************************** + */ + +void +ToolsCoreHangDetector_RpcReset(void) +{ + HangDetectorState *state = &gDetectorState; + + state->vmxRejectedHealthUpdate = FALSE; +} diff --git a/open-vm-tools/services/vmtoolsd/toolsHangDetector.h b/open-vm-tools/services/vmtoolsd/toolsHangDetector.h index 89150d210..21c2ae782 100644 --- a/open-vm-tools/services/vmtoolsd/toolsHangDetector.h +++ b/open-vm-tools/services/vmtoolsd/toolsHangDetector.h @@ -26,5 +26,6 @@ */ gboolean ToolsCoreHangDetector_Start(ToolsAppCtx *ctx); +void ToolsCoreHangDetector_RpcReset(void); #endif /* _TOOLS_HANG_DETECTOR_H_ */