VirtualBox

Ignore:
Timestamp:
Mar 4, 2016 9:36:37 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105843
Message:

VBoxBalloonCtrl/VBoxModBallooning.cpp: Implemented global "VBoxInternal/Guest/BalloonEnable" or per-VM "VBoxInternal2/Watchdog/BalloonCtrl/BalloonEnabled" extra-data for disabling ballooning when set to "0" (disabled).

File:
1 edited

Legend:

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

    r59909 r59916  
    6565typedef struct VBOXWATCHDOG_BALLOONCTRL_PAYLOAD
    6666{
     67    /** Last (most recent) ballooning size reported by the guest. */
     68    unsigned long ulBalloonCurLast;
    6769    /** Last (most recent) ballooning request received. */
    6870    unsigned long ulBalloonReqLast;
     
    288290
    289291/**
     292 * Determines whether ballooning for the specified machine is enabled or not.
     293 * This can be specified on a per-VM basis or as a globally set value for all VMs.
     294 *
     295 * @return  bool                    Whether ballooning is enabled or not.
     296 * @param   pMachine                Machine to determine enable status for.
     297 */
     298static bool balloonIsEnabled(PVBOXWATCHDOG_MACHINE pMachine)
     299{
     300    const ComPtr<IMachine> &rptrMachine = pMachine->machine;
     301
     302    bool fEnabled = true; /* By default ballooning is enabled. */
     303    char szSource[64];
     304
     305    Bstr strValue;
     306    HRESULT hr = g_pVirtualBox->GetExtraData(Bstr("VBoxInternal/Guest/BalloonEnabled").raw(),
     307                                             strValue.asOutParam());
     308    if (   SUCCEEDED(hr)
     309        && strValue.isNotEmpty())
     310    {
     311       if (g_fVerbose)
     312            RTStrPrintf(szSource, sizeof(szSource), "global extra-data");
     313    }
     314    else
     315    {
     316        hr = rptrMachine->GetExtraData(Bstr("VBoxInternal2/Watchdog/BalloonCtrl/BalloonEnabled").raw(),
     317                                       strValue.asOutParam());
     318        if (SUCCEEDED(hr))
     319        {
     320            if (g_fVerbose)
     321                RTStrPrintf(szSource, sizeof(szSource), "per-VM extra-data");
     322        }
     323    }
     324
     325    if (strValue.isNotEmpty())
     326    {
     327        fEnabled = RT_BOOL(Utf8Str(strValue).toUInt32());
     328        serviceLogVerbose(("[%ls] Ballooning is forced to %s (%s)\n",
     329                           pMachine->strName.raw(), fEnabled ? "enabled" : "disabled", szSource));
     330    }
     331
     332    return fEnabled;
     333}
     334
     335/**
    290336 * Indicates whether ballooning on the specified machine state is
    291337 * possible -- this only is true if the machine is up and running.
     
    398444        AssertPtr(pData);
    399445
     446        /* Determine if ballooning is enabled or disabled. */
     447        bool fEnabled = balloonIsEnabled(pMachine);
     448
    400449        /* Determine the current set maximum balloon size. */
    401450        unsigned long ulBalloonMax = balloonGetMaxSize(pMachine);
     
    425474            ulBalloonCur = ulBalloonCur + lBalloonDelta;
    426475
    427             serviceLog("[%ls] %s balloon by %RU32MB to %RU32MB ...\n",
    428                        pMachine->strName.raw(), lBalloonDelta > 0 ? "Inflating" : "Deflating", RT_ABS(lBalloonDelta), ulBalloonCur);
    429 
    430             vrc = balloonSetSize(pMachine, ulBalloonCur);
    431         }
    432 
     476            if (fEnabled)
     477            {
     478                serviceLog("[%ls] %s balloon by %RU32MB to %RU32MB ...\n",
     479                           pMachine->strName.raw(), lBalloonDelta > 0 ? "Inflating" : "Deflating", RT_ABS(lBalloonDelta), ulBalloonCur);
     480                vrc = balloonSetSize(pMachine, ulBalloonCur);
     481            }
     482            else
     483                serviceLogVerbose(("[%ls] Requested %s balloon by %RU32MB to %RU32MB, but ballooning is disabled\n",
     484                                   pMachine->strName.raw(), lBalloonDelta > 0 ? "inflating" : "deflating",
     485                                   RT_ABS(lBalloonDelta), ulBalloonCur));
     486        }
     487
     488        if (ulBalloonCur != pData->ulBalloonCurLast)
     489        {
     490            /* If ballooning is disabled, always bolt down the ballooning size to 0. */
     491            if (!fEnabled)
     492            {
     493                serviceLogVerbose(("[%ls] Ballooning is disabled, forcing to 0\n", pMachine->strName.raw()));
     494                int vrc2 = balloonSetSize(pMachine, 0);
     495                if (RT_FAILURE(vrc2))
     496                    serviceLog("[%ls] Error disabling ballooning, rc=%Rrc\n", pMachine->strName.raw(), vrc2);
     497            }
     498        }
     499
     500        pData->ulBalloonCurLast = ulBalloonCur;
    433501        pData->ulBalloonReqLast = ulBalloonReq;
    434502    }
    435503    else
    436         serviceLog("Error: Unable to retrieve metrics for machine '%ls', rc=%Rrc\n",
    437                    pMachine->strName.raw(), vrc);
     504        serviceLog("[%ls] Error retrieving metrics, rc=%Rrc\n", pMachine->strName.raw(), vrc);
     505
    438506    return vrc;
    439507}
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