Changeset 39942 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Feb 1, 2012 7:50:46 PM (13 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxBalloonCtrl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxModBallooning.cpp
r39936 r39942 64 64 * The module's RTGetOpt-IDs for the command line. 65 65 */ 66 enum GETOPTDEF_BALLOONCTRL66 static enum GETOPTDEF_BALLOONCTRL 67 67 { 68 68 GETOPTDEF_BALLOONCTRL_BALLOOINC = 1000, … … 70 70 GETOPTDEF_BALLOONCTRL_BALLOONLOWERLIMIT, 71 71 GETOPTDEF_BALLOONCTRL_BALLOONMAX, 72 GETOPTDEF_BALLOONCTRL_TIMEOUTMS 72 GETOPTDEF_BALLOONCTRL_TIMEOUTMS, 73 GETOPTDEF_BALLOONCTRL_GROUPS 74 }; 75 76 /** 77 * The module's command line arguments. 78 */ 79 static const RTGETOPTDEF g_aBalloonOpts[] = { 80 { "--balloon-dec", GETOPTDEF_BALLOONCTRL_BALLOONDEC, RTGETOPT_REQ_UINT32 }, 81 { "--balloon-groups", GETOPTDEF_BALLOONCTRL_GROUPS, RTGETOPT_REQ_STRING }, 82 { "--balloon-inc", GETOPTDEF_BALLOONCTRL_BALLOOINC, RTGETOPT_REQ_UINT32 }, 83 { "--balloon-interval", GETOPTDEF_BALLOONCTRL_TIMEOUTMS, RTGETOPT_REQ_UINT32 }, 84 { "--balloon-lower-limit", GETOPTDEF_BALLOONCTRL_BALLOONLOWERLIMIT, RTGETOPT_REQ_UINT32 }, 85 { "--balloon-max", GETOPTDEF_BALLOONCTRL_BALLOONMAX, RTGETOPT_REQ_UINT32 } 73 86 }; 74 87 … … 146 159 * Legacy (VBoxBalloonCtrl): 147 160 * - per-VM parameter ("VBoxInternal/Guest/BalloonSizeMax") 161 * Global: 148 162 * - global parameter ("VBoxInternal/Guest/BalloonSizeMax") 149 163 * New: … … 188 202 * 189 203 * @return bool True if ballooning is required, false if not. 190 * @param strUuid UUID of the specified machine.204 * @param pMachine Machine to determine ballooning for. 191 205 */ 192 206 static bool balloonIsRequired(PVBOXWATCHDOG_MACHINE pMachine) … … 297 311 } 298 312 299 static DECLCALLBACK(int) VBoxModBallooningOption(PCRTGETOPTUNION pOpt, int iShort) 300 { 301 AssertPtrReturn(pOpt, -1); 302 303 int rc = 0; 304 switch (iShort) 305 { 306 case GETOPTDEF_BALLOONCTRL_BALLOOINC: 307 g_ulMemoryBalloonIncrementMB = pOpt->u32; 308 break; 309 310 case GETOPTDEF_BALLOONCTRL_BALLOONDEC: 311 g_ulMemoryBalloonDecrementMB = pOpt->u32; 312 break; 313 314 case GETOPTDEF_BALLOONCTRL_BALLOONLOWERLIMIT: 315 g_ulMemoryBalloonLowerLimitMB = pOpt->u32; 316 break; 317 318 case GETOPTDEF_BALLOONCTRL_BALLOONMAX: 319 g_ulMemoryBalloonMaxMB = pOpt->u32; 320 break; 321 322 /** @todo Add (legacy) "--inverval" setting! */ 323 /** @todo This option is a common moudle option! Put 324 * this into a utility function! */ 325 case GETOPTDEF_BALLOONCTRL_TIMEOUTMS: 326 g_ulMemoryBalloonTimeoutMS = pOpt->u32; 327 if (g_ulMemoryBalloonTimeoutMS < 500) 328 g_ulMemoryBalloonTimeoutMS = 500; 329 break; 330 331 default: 332 rc = -1; /* We don't handle this option, skip. */ 333 break; 334 } 335 336 /* (Legacy) note. */ 337 RTStrmPrintf(g_pStdErr, "\n" 338 "Set \"VBoxInternal/Guest/BalloonSizeMax\" for a per-VM maximum ballooning size.\n"); 313 static DECLCALLBACK(int) VBoxModBallooningOption(int argc, char **argv) 314 { 315 if (!argc) /* Take a shortcut. */ 316 return -1; 317 318 AssertPtrReturn(argv, VERR_INVALID_PARAMETER); 319 320 RTGETOPTSTATE GetState; 321 int rc = RTGetOptInit(&GetState, argc, argv, 322 g_aBalloonOpts, RT_ELEMENTS(g_aBalloonOpts), 323 0 /* First */, 0 /*fFlags*/); 324 if (RT_FAILURE(rc)) 325 return rc; 326 327 rc = 0; /* Set default parsing result to valid. */ 328 329 int c; 330 RTGETOPTUNION ValueUnion; 331 while ((c = RTGetOpt(&GetState, &ValueUnion))) 332 { 333 switch (c) 334 { 335 case GETOPTDEF_BALLOONCTRL_BALLOONDEC: 336 g_ulMemoryBalloonDecrementMB = ValueUnion.u32; 337 break; 338 339 case GETOPTDEF_BALLOONCTRL_BALLOOINC: 340 g_ulMemoryBalloonIncrementMB = ValueUnion.u32; 341 break; 342 343 case GETOPTDEF_BALLOONCTRL_GROUPS: 344 /** @todo Add ballooning groups cmd line arg. */ 345 break; 346 347 case GETOPTDEF_BALLOONCTRL_BALLOONLOWERLIMIT: 348 g_ulMemoryBalloonLowerLimitMB = ValueUnion.u32; 349 break; 350 351 case GETOPTDEF_BALLOONCTRL_BALLOONMAX: 352 g_ulMemoryBalloonMaxMB = ValueUnion.u32; 353 break; 354 355 /** @todo Add (legacy) "--inverval" setting! */ 356 /** @todo This option is a common moudle option! Put 357 * this into a utility function! */ 358 case GETOPTDEF_BALLOONCTRL_TIMEOUTMS: 359 g_ulMemoryBalloonTimeoutMS = ValueUnion.u32; 360 if (g_ulMemoryBalloonTimeoutMS < 500) 361 g_ulMemoryBalloonTimeoutMS = 500; 362 break; 363 364 default: 365 rc = -1; /* We don't handle this option, skip. */ 366 break; 367 } 368 } 369 339 370 return rc; 340 371 } … … 421 452 /* pszDescription. */ 422 453 "Memory Ballooning Control", 454 /* pszDepends. */ 455 NULL, 456 /* uPriority. */ 457 0 /* Not used */, 423 458 /* pszUsage. */ 424 " [--balloon- interval <ms>] [--balloon-inc <MB>]\n"425 " [--balloon- dec <MB>] [--balloon-lower-limit <MB>]"459 " [--balloon-dec <MB>] [--balloon-inc <MB>]\n" 460 " [--balloon-interval <ms>] [--balloon-lower-limit <MB>]\n" 426 461 " [--balloon-max <MB>]", 427 462 /* pszOptions. */ 428 " --balloon-interval Sets the check interval in ms (30 seconds).\n" 429 " --balloon-inc Sets the ballooning increment in MB (256 MB).\n" 430 " --balloon-dec Sets the ballooning decrement in MB (128 MB).\n" 431 " --balloon-lower-limit Sets the ballooning lower limit in MB (64 MB).\n" 432 " --balloon-max Sets the balloon maximum limit in MB (0 MB).\n" 433 " Specifying \"0\" means disabled ballooning.\n", 434 /* methods */ 463 "--balloon-dec Sets the ballooning decrement in MB (128 MB).\n" 464 "--balloon-groups Sets the VM groups for ballooning (All).\n" 465 "--balloon-inc Sets the ballooning increment in MB (256 MB).\n" 466 "--balloon-interval Sets the check interval in ms (30 seconds).\n" 467 "--balloon-lower-limit Sets the ballooning lower limit in MB (64 MB).\n" 468 "--balloon-max Sets the balloon maximum limit in MB (0 MB).\n" 469 " Specifying \"0\" means disabled ballooning.\n" 470 #if 1 471 /* (Legacy) note. */ 472 "Set \"VBoxInternal/Guest/BalloonSizeMax\" for a per-VM maximum ballooning size.\n" 473 #endif 474 , 475 /* methods. */ 435 476 VBoxModBallooningPreInit, 436 477 VBoxModBallooningOption, … … 439 480 VBoxModBallooningStop, 440 481 VBoxModBallooningTerm, 441 /* callbacks */482 /* callbacks. */ 442 483 VBoxModBallooningOnMachineRegistered, 443 484 VBoxModBallooningOnMachineUnregistered, -
trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdog.cpp
r39929 r39942 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox BalloonCtrl - VirtualBox Ballooning Control Service.3 * VBoxWatchdog.cpp - VirtualBox Watchdog. 4 4 */ 5 5 … … 70 70 ComPtr<ISession> g_pSession = NULL; 71 71 72 /** The critical section for keep our stuff in sync. */73 static RTCRITSECT g_ MapCritSect;72 /** The critical section for the machines map. */ 73 static RTCRITSECT g_csMachines; 74 74 75 75 /** Set by the signal handler. */ … … 143 143 static int machineAdd(const Bstr &strUuid); 144 144 static int machineRemove(const Bstr &strUuid); 145 static int machineUpdate(const Bstr &strUuid, MachineState_T enmState);145 //static int machineUpdate(const Bstr &strUuid, MachineState_T enmState); 146 146 static HRESULT watchdogSetup(); 147 147 static void watchdogTeardown(); … … 192 192 if (SUCCEEDED(hr)) 193 193 { 194 int rc = RTCritSectEnter(&g_ MapCritSect);194 int rc = RTCritSectEnter(&g_csMachines); 195 195 if (RT_SUCCESS(rc)) 196 196 { … … 212 212 else if (!fRegistered) 213 213 rc = machineRemove(uuid); 214 215 int rc2 = RTCritSectLeave(&g_ MapCritSect);214 #endif 215 int rc2 = RTCritSectLeave(&g_csMachines); 216 216 if (RT_SUCCESS(rc)) 217 217 rc = rc2; 218 218 AssertRC(rc); 219 #endif220 219 } 221 220 } … … 237 236 if (SUCCEEDED(hr)) 238 237 { 239 int rc = RTCritSectEnter(&g_ MapCritSect);238 int rc = RTCritSectEnter(&g_csMachines); 240 239 if (RT_SUCCESS(rc)) 241 240 { … … 252 251 253 252 //rc = machineUpdate(uuid, machineState); 254 int rc2 = RTCritSectLeave(&g_ MapCritSect);253 int rc2 = RTCritSectLeave(&g_csMachines); 255 254 if (RT_SUCCESS(rc)) 256 255 rc = rc2; … … 482 481 483 482 /* Register all module payloads. */ 484 /* TODO */ 483 for (unsigned j = 0; j < RT_ELEMENTS(g_aModules); j++) 484 { 485 if (g_aModules[j].pDesc->pszOptions) 486 RTPrintf("%s", g_aModules[j].pDesc->pszOptions); 487 } 485 488 486 489 g_mapVM.insert(std::make_pair(strUuid, m)); … … 489 492 490 493 } while (0); 494 495 /** @todo Add std exception handling! */ 491 496 492 497 return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_COM_IPRT_ERROR; /* @todo Find a better error! */ … … 524 529 } 525 530 531 #if 0 526 532 /** 527 533 * Updates a specified machine according to its current machine state. … … 583 589 return rc; 584 590 } 591 #endif 585 592 586 593 static void vmListDestroy() … … 588 595 serviceLogVerbose(("Destroying VM list ...\n")); 589 596 590 int rc = RTCritSectEnter(&g_ MapCritSect);597 int rc = RTCritSectEnter(&g_csMachines); 591 598 if (RT_SUCCESS(rc)) 592 599 { … … 603 610 g_mapVM.clear(); 604 611 605 rc = RTCritSectLeave(&g_ MapCritSect);612 rc = RTCritSectLeave(&g_csMachines); 606 613 } 607 614 AssertRC(rc); … … 612 619 serviceLogVerbose(("Building VM list ...\n")); 613 620 614 int rc = RTCritSectEnter(&g_ MapCritSect);621 int rc = RTCritSectEnter(&g_csMachines); 615 622 if (RT_SUCCESS(rc)) 616 623 { … … 656 663 } 657 664 658 int rc2 = RTCritSectLeave(&g_ MapCritSect);665 int rc2 = RTCritSectLeave(&g_csMachines); 659 666 if (RT_SUCCESS(rc)) 660 667 rc = rc2; … … 756 763 g_pEventQ = com::EventQueue::getMainEventQueue(); 757 764 758 RTCritSectInit(&g_ MapCritSect);765 RTCritSectInit(&g_csMachines); 759 766 760 767 /* … … 848 855 AssertRC(vrc); 849 856 850 RTCritSectDelete(&g_ MapCritSect);857 RTCritSectDelete(&g_csMachines); 851 858 852 859 if (RT_FAILURE(vrc)) … … 885 892 { 886 893 pfnLog(pLoggerRelease, 887 "VirtualBox Ballooning Control Service%s r%u %s (%s %s) release log\n"894 "VirtualBox Watchdog %s r%u %s (%s %s) release log\n" 888 895 #ifdef VBOX_BLEEDING_EDGE 889 896 "EXPERIMENTAL build " VBOX_BLEEDING_EDGE "\n" … … 939 946 } 940 947 948 static void displayHeader() 949 { 950 RTStrmPrintf(g_pStdErr, VBOX_PRODUCT " Watchdog " VBOX_VERSION_STRING "\n" 951 "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n" 952 "All rights reserved.\n\n"); 953 } 954 941 955 /** 942 956 * Displays the help. … … 948 962 AssertPtrReturnVoid(pszImage); 949 963 950 RTStrmPrintf(g_pStdErr, "\nUsage: %s [options]\n\nSupported options (default values in brackets):\n", 964 displayHeader(); 965 966 RTStrmPrintf(g_pStdErr, "Usage: %s [options]\n\nSupported options (default values in brackets):\n", 951 967 pszImage); 952 968 for (unsigned i = 0; … … 999 1015 } 1000 1016 1001 RTStrmPrintf(g_pStdErr, "Module options:\n"); 1002 1003 /** @todo Add module options here. */ 1017 for (unsigned j = 0; j < RT_ELEMENTS(g_aModules); j++) 1018 { 1019 if (g_aModules[j].pDesc->pszOptions) 1020 RTPrintf("%s", g_aModules[j].pDesc->pszOptions); 1021 } 1004 1022 1005 1023 /** @todo Change VBOXBALLOONCTRL_RELEASE_LOG to WATCHDOG*. */ … … 1075 1093 if (RT_FAILURE(rc)) 1076 1094 return RTMsgInitFailure(rc); 1077 1078 RTPrintf(VBOX_PRODUCT " Watchdog " VBOX_VERSION_STRING "\n"1079 "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n"1080 "All rights reserved.\n\n");1081 1095 1082 1096 /* … … 1140 1154 { 1141 1155 rc = watchdogLazyPreInit(); 1142 if ( rc != RTEXITCODE_SUCCESS)1143 return rc;1156 if (RT_SUCCESS(rc)) 1157 return RTEXITCODE_FAILURE; 1144 1158 1145 1159 for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aModules); j++) 1146 1160 { 1147 rc = g_aModules[j].pDesc->pfnOption(&ValueUnion, c); 1161 rc = g_aModules[j].pDesc->pfnOption(1 /* Current value only. */, 1162 &argv[GetState.iNext - 1]); 1148 1163 fFound = rc == 0; 1149 1164 if (fFound) … … 1160 1175 } 1161 1176 1177 /** @todo Add "--quiet/-q" option to not show the header. */ 1178 displayHeader(); 1179 1162 1180 /* create release logger */ 1163 1181 PRTLOGGER pLoggerRelease; -
trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdogInternal.h
r39936 r39942 29 29 30 30 #include <map> 31 #include <vector> 31 32 32 33 using namespace com; … … 69 70 typedef std::map<const char*, VBOXWATCHDOG_MODULE_PAYLOAD>::const_iterator mapPayloadIterConst; 70 71 71 /** A machine group entry. 72 * Currently contains on the name of the group. */ 73 typedef struct VBOXWATCHDOG_MACHINE_GROUP 74 { 75 Bstr name; 76 } VBOXWATCHDOG_MACHINE_GROUP; 77 typedef std::map<Bstr, VBOXWATCHDOG_MACHINE_GROUP> mapGroup; 78 typedef std::map<Bstr, VBOXWATCHDOG_MACHINE_GROUP>::iterator mapGroupIter; 79 typedef std::map<Bstr, VBOXWATCHDOG_MACHINE_GROUP>::const_iterator mapGroupIterConst; 80 81 /** A machine's internal entry. */ 72 struct VBOXWATCHDOG_VM_GROUP; 73 74 /** A machine's internal entry. 75 * Primary key is the machine's UUID. */ 82 76 typedef struct VBOXWATCHDOG_MACHINE 83 77 { … … 86 80 ComPtr<IPerformanceCollector> collector; 87 81 #endif 88 /** Map containing the group(s) assigned to89 * this machine. */90 mapGroup group;91 82 /** Map containing the individual 92 83 * module payloads. */ … … 97 88 typedef std::map<Bstr, VBOXWATCHDOG_MACHINE>::const_iterator mapVMIterConst; 98 89 90 /** A VM group entry. Note that a machine can belong 91 * to more than one group. */ 92 typedef struct VBOXWATCHDOG_VM_GROUP 93 { 94 /** UUIDs of machines belonging to this group. */ 95 std::vector<Bstr> machine; 96 } VBOXWATCHDOG_VM_GROUP; 97 typedef std::map<Bstr, VBOXWATCHDOG_VM_GROUP> mapGroup; 98 typedef std::map<Bstr, VBOXWATCHDOG_VM_GROUP>::iterator mapGroupIter; 99 typedef std::map<Bstr, VBOXWATCHDOG_VM_GROUP>::const_iterator mapGroupIterConst; 100 99 101 /** 100 102 * A module descriptor. … … 104 106 /** The short module name. */ 105 107 const char *pszName; 108 /** A comma-separated list of modules this module 109 * depends on. Might be NULL if no dependencies. */ 110 const char *pszDepends; 111 /** Priority (lower is higher, 0 is invalid) of 112 * module execution. */ 113 uint32_t uPriority; 106 114 /** The longer module name. */ 107 115 const char *pszDescription; … … 118 126 119 127 /** 120 * Tries to parse the given command line option .128 * Tries to parse the given command line options. 121 129 * 122 130 * @returns 0 if we parsed, -1 if it didn't and anything else means exit. 123 * @param pOpt Pointer to a value union containing the current 124 * command line value to parse. 125 * @param iShort Short version of current commad line value. 126 */ 127 DECLCALLBACKMEMBER(int, pfnOption)(PCRTGETOPTUNION pOpt, int iShort); 131 * @param argc Argument count. 132 * @param argv Arguments. 133 */ 134 DECLCALLBACKMEMBER(int, pfnOption)(int argc, char **argv); 128 135 129 136 /** … … 198 205 extern int getMetric(PVBOXWATCHDOG_MACHINE pMachine, const Bstr& strName, LONG *pulData); 199 206 void* getPayload(PVBOXWATCHDOG_MACHINE pMachine, const char *pszModule); 200 int getArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max);201 207 202 208 RT_C_DECLS_END
Note:
See TracChangeset
for help on using the changeset viewer.