VirtualBox

Changeset 41422 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 23, 2012 3:59:04 PM (13 years ago)
Author:
vboxsync
Message:

VBoxBalloonCtrl: Get more options from extradata.

Location:
trunk/src/VBox/Frontends/VBoxBalloonCtrl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxModAPIMonitor.cpp

    r41361 r41422  
    458458        if (g_vecAPIMonGroups.empty()) /* Not set by command line? */
    459459        {
    460             CHECK_ERROR_BREAK(g_pVirtualBox, GetExtraData(Bstr("Watchdog/APIMonitor/Groups").raw(),
     460            CHECK_ERROR_BREAK(g_pVirtualBox, GetExtraData(Bstr("VBoxInternal2/Watchdog/APIMonitor/Groups").raw(),
    461461                                                          strValue.asOutParam()));
    462462            if (!strValue.isEmpty())
     
    468468        }
    469469
    470         /* Host isolation timeout (in ms). */
    471         if (!g_ulAPIMonIslnTimeoutMS) /* Not set by command line? */
    472         {
    473             CHECK_ERROR_BREAK(g_pVirtualBox, GetExtraData(Bstr("Watchdog/APIMonitor/IsolationTimeout").raw(),
    474                                                           strValue.asOutParam()));
    475             if (!strValue.isEmpty())
    476                 g_ulAPIMonIslnTimeoutMS = Utf8Str(strValue).toUInt32();
    477         }
    478         if (!g_ulAPIMonIslnTimeoutMS) /* Still not set? Use a default. */
    479         {
    480             serviceLogVerbose(("apimon: API monitor isolation timeout not given, defaulting to 30s\n"));
    481 
    482             /* Default is 30 seconds timeout. */
    483             g_ulAPIMonIslnTimeoutMS = 30 * 1000;
    484         }
    485 
    486         /* Host isolation command response. */
     470        if (!g_ulAPIMonIslnTimeoutMS)
     471            cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
     472                             "VBoxInternal2/Watchdog/APIMonitor/IsolationTimeoutMS", NULL /* Per-machine */,
     473                             &g_ulAPIMonIslnTimeoutMS, 30 * 1000 /* Default is 30 seconds timeout. */);
     474        g_ulAPIMonIslnTimeoutMS = RT_MIN(1000, g_ulAPIMonIslnTimeoutMS);
     475
    487476        if (g_enmAPIMonIslnResp == APIMON_RESPONSE_NONE) /* Not set by command line? */
    488477        {
    489             CHECK_ERROR_BREAK(g_pVirtualBox, GetExtraData(Bstr("Watchdog/APIMonitor/IsolationResponse").raw(),
    490                                                           strValue.asOutParam()));
    491             if (!strValue.isEmpty())
     478            Utf8Str strResp;
     479            int rc2 = cfgGetValueStr(g_pVirtualBox, NULL /* Machine */,
     480                                     "VBoxInternal2/Watchdog/APIMonitor/IsolationResponse", NULL /* Per-machine */,
     481                                     strResp, "" /* Default value. */);
     482            if (RT_SUCCESS(rc2))
    492483            {
    493                 int rc2 = apimonResponseToEnum(Utf8Str(strValue).c_str(), &g_enmAPIMonIslnResp);
     484                rc2 = apimonResponseToEnum(strResp.c_str(), &g_enmAPIMonIslnResp);
    494485                if (RT_FAILURE(rc2))
    495486                    serviceLog("apimon: Warning: API monitor response string invalid (%ls), defaulting to no action\n",
     
    498489        }
    499490
    500         /* Trigger timeout (in ms). */
    501         if (!g_ulAPIMonResponseTimeoutMS) /* Not set by command line? */
    502         {
    503             CHECK_ERROR_BREAK(g_pVirtualBox, GetExtraData(Bstr("Watchdog/APIMonitor/ResponseTimeout").raw(),
    504                                                           strValue.asOutParam()));
    505             if (!strValue.isEmpty())
    506                 g_ulAPIMonResponseTimeoutMS = Utf8Str(strValue).toUInt32();
    507         }
    508         if (!g_ulAPIMonResponseTimeoutMS) /* Still not set? Use a default. */
    509         {
    510             serviceLogVerbose(("apimon: API monitor response timeout not given, defaulting to 30s\n"));
    511 
    512             /* Default is 30 seconds timeout. */
    513             g_ulAPIMonResponseTimeoutMS = 30 * 1000;
    514         }
     491        if (!g_ulAPIMonResponseTimeoutMS)
     492            cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
     493                             "VBoxInternal2/Watchdog/APIMonitor/ResponseTimeoutMS", NULL /* Per-machine */,
     494                             &g_ulAPIMonResponseTimeoutMS, 30 * 1000 /* Default is 30 seconds timeout. */);
     495        g_ulAPIMonResponseTimeoutMS = RT_MIN(5000, g_ulAPIMonResponseTimeoutMS);
    515496
    516497#ifdef DEBUG
  • trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxModBallooning.cpp

    r41360 r41422  
    5555};
    5656
    57 static unsigned long g_ulMemoryBalloonTimeoutMS = 30 * 1000; /* Default is 30 seconds timeout. */
    58 static unsigned long g_ulMemoryBalloonIncrementMB = 256;
    59 static unsigned long g_ulMemoryBalloonDecrementMB = 128;
     57static unsigned long g_ulMemoryBalloonTimeoutMS = 0;
     58static unsigned long g_ulMemoryBalloonIncrementMB = 0;
     59static unsigned long g_ulMemoryBalloonDecrementMB = 0;
    6060/** Global balloon limit is 0, so disabled. Can be overridden by a per-VM
    6161 *  "VBoxInternal/Guest/BalloonSizeMax" value. */
    6262static unsigned long g_ulMemoryBalloonMaxMB = 0;
    63 static unsigned long g_ulMemoryBalloonLowerLimitMB = 64;
     63static unsigned long g_ulMemoryBalloonLowerLimitMB = 0;
    6464
    6565/** The ballooning module's payload. */
     
    135135     *  By default (e.g. if none of above is set), ballooning is disabled.
    136136     */
    137     unsigned long ulBalloonMax = g_ulMemoryBalloonMaxMB; /* Use global limit as default. */
    138     if (!ulBalloonMax) /* Not set by command line? */
    139     {
    140         /* Try per-VM approach. */
    141         Bstr strValue;
    142         HRESULT rc = rptrMachine->GetExtraData(Bstr("VBoxInternal/Guest/BalloonSizeMax").raw(),
    143                                                strValue.asOutParam());
    144         if (   SUCCEEDED(rc)
    145             && !strValue.isEmpty())
     137    unsigned long ulBalloonMax = g_ulMemoryBalloonMaxMB;
     138    if (!ulBalloonMax)
     139    {
     140        int rc = cfgGetValueULong(g_pVirtualBox, rptrMachine,
     141                                  "VBoxInternal/Guest/BalloonSizeMax", "VBoxInternal/Guest/BalloonSizeMax", &ulBalloonMax, 0 /* Ballooning disabled */);
     142        if (RT_FAILURE(rc))
    146143        {
    147             ulBalloonMax = Utf8Str(strValue).toUInt32();
     144            /* Try (new) VBoxWatch per-VM approach. */
     145            Bstr strValue;
     146            HRESULT rc = rptrMachine->GetExtraData(Bstr("VBoxInternal2/Watchdog/BalloonCtrl/BalloonSizeMax").raw(),
     147                                                   strValue.asOutParam());
     148            if (   SUCCEEDED(rc)
     149                && !strValue.isEmpty())
     150            {
     151                ulBalloonMax = Utf8Str(strValue).toUInt32();
     152            }
    148153        }
    149154    }
    150     if (!ulBalloonMax) /* Still not set by per-VM value? */
    151     {
    152         /* Try global approach. */
    153         Bstr strValue;
    154         HRESULT rc = g_pVirtualBox->GetExtraData(Bstr("VBoxInternal/Guest/BalloonSizeMax").raw(),
    155                                                  strValue.asOutParam());
    156         if (   SUCCEEDED(rc)
    157             && !strValue.isEmpty())
    158         {
    159             ulBalloonMax = Utf8Str(strValue).toUInt32();
    160         }
    161     }
    162     if (!ulBalloonMax)
    163     {
    164         /** @todo ("VBoxInternal2/Watchdog/BalloonCtrl/BalloonSizeMax") */
    165     }
     155
    166156    return ulBalloonMax;
    167157}
     
    398388                break;
    399389
    400             /** @todo Add (legacy) "--inverval" setting! */
    401             /** @todo This option is a common moudle option! Put
     390            /** @todo This option is a common module option! Put
    402391             *        this into a utility function! */
    403392            case GETOPTDEF_BALLOONCTRL_TIMEOUTMS:
     
    418407static DECLCALLBACK(int) VBoxModBallooningInit(void)
    419408{
    420     return VINF_SUCCESS; /* Nothing to do here right now. */
     409    if (!g_ulMemoryBalloonTimeoutMS)
     410        cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
     411                         "VBoxInternal2/Watchdog/BalloonCtrl/TimeoutMS", NULL /* Per-machine */,
     412                         &g_ulMemoryBalloonTimeoutMS, 30 * 1000 /* Default is 30 seconds timeout. */);
     413
     414    if (!g_ulMemoryBalloonIncrementMB)
     415        cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
     416                         "VBoxInternal2/Watchdog/BalloonCtrl/BalloonIncrementMB", NULL /* Per-machine */,
     417                         &g_ulMemoryBalloonIncrementMB, 256);
     418
     419    if (!g_ulMemoryBalloonDecrementMB)
     420        cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
     421                         "VBoxInternal2/Watchdog/BalloonCtrl/BalloonDecrementMB", NULL /* Per-machine */,
     422                         &g_ulMemoryBalloonDecrementMB, 128);
     423
     424    if (!g_ulMemoryBalloonLowerLimitMB)
     425        cfgGetValueULong(g_pVirtualBox, NULL /* Machine */,
     426                         "VBoxInternal2/Watchdog/BalloonCtrl/BalloonLowerLimitMB", NULL /* Per-machine */,
     427                         &g_ulMemoryBalloonLowerLimitMB, 128);
     428
     429    return VINF_SUCCESS;
    421430}
    422431
  • trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdogInternal.h

    r41286 r41422  
    232232int payloadAlloc(PVBOXWATCHDOG_MACHINE pMachine, const char *pszModule, size_t cbSize, void **ppszPayload);
    233233void payloadFree(PVBOXWATCHDOG_MACHINE pMachine, const char *pszModule);
     234
    234235PVBOXWATCHDOG_MACHINE getMachine(const Bstr& strUuid);
    235236MachineState_T getMachineState(const PVBOXWATCHDOG_MACHINE pMachine);
    236237
     238int cfgGetValueStr(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,
     239                   const char *pszGlobal, const char *pszVM, Utf8Str &strValue, Utf8Str strDefault);
     240int cfgGetValueULong(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,
     241                     const char *pszGlobal, const char *pszVM, unsigned long *pulValue, unsigned long ulDefault);
    237242RT_C_DECLS_END
    238243
  • trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdogUtils.cpp

    r41286 r41422  
    208208}
    209209
     210int cfgGetValueStr(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,
     211                   const char *pszGlobal, const char *pszVM, Utf8Str &strValue, Utf8Str strDefault)
     212{
     213    AssertReturn(!rptrVBox.isNull(), VERR_INVALID_POINTER);
     214
     215
     216    /* Try per-VM approach. */
     217    Bstr strTemp;
     218    HRESULT hr;
     219    if (!rptrMachine.isNull())
     220    {
     221        AssertPtr(pszVM);
     222        hr = rptrMachine->GetExtraData(Bstr(pszVM).raw(),
     223                                       strTemp.asOutParam());
     224        if (   SUCCEEDED(hr)
     225            && !strTemp.isEmpty())
     226        {
     227            strValue = Utf8Str(strTemp);
     228        }
     229    }
     230
     231    if (strValue.isEmpty()) /* Not set by per-VM value? */
     232    {
     233        AssertPtr(pszGlobal);
     234
     235        /* Try global approach. */
     236        hr = rptrVBox->GetExtraData(Bstr(pszGlobal).raw(),
     237                                    strTemp.asOutParam());
     238        if (   SUCCEEDED(hr)
     239            && !strTemp.isEmpty())
     240        {
     241            strValue = Utf8Str(strTemp);
     242        }
     243    }
     244
     245    if (strValue.isEmpty())
     246    {
     247        strValue = strDefault;
     248        return VERR_NOT_FOUND;
     249    }
     250
     251    return VINF_SUCCESS;
     252}
     253
     254int cfgGetValueULong(const ComPtr<IVirtualBox> &rptrVBox, const ComPtr<IMachine> &rptrMachine,
     255                     const char *pszGlobal, const char *pszVM, unsigned long *pulValue, unsigned long ulDefault)
     256{
     257    Utf8Str strValue;
     258    int rc = cfgGetValueStr(rptrVBox, rptrMachine, pszGlobal, pszVM, strValue, "" /* Default */);
     259    if (RT_SUCCESS(rc))
     260    {
     261        *pulValue = strValue.toUInt32();
     262    }
     263    else
     264        *pulValue = ulDefault;
     265
     266    return rc;
     267}
     268
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette