VirtualBox

Changeset 93628 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Feb 6, 2022 11:44:05 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
149773
Message:

VMM/PDMNetShaper,Main,DrvNetShaper: Moved the network shaper data off the hyper heap and into the VM structure. bugref:10093 bugref:5582

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r93561 r93628  
    14641464         * Bandwidth groups.
    14651465         */
     1466        ComPtr<IBandwidthControl> bwCtrl;
     1467        hrc = pMachine->COMGETTER(BandwidthControl)(bwCtrl.asOutParam());                   H();
     1468
     1469        com::SafeIfaceArray<IBandwidthGroup> bwGroups;
     1470        hrc = bwCtrl->GetAllBandwidthGroups(ComSafeArrayAsOutParam(bwGroups));              H();
     1471
    14661472        PCFGMNODE pAc;
     1473        InsertConfigNode(pPDM, "AsyncCompletion", &pAc);
    14671474        PCFGMNODE pAcFile;
     1475        InsertConfigNode(pAc,  "File", &pAcFile);
    14681476        PCFGMNODE pAcFileBwGroups;
    1469         ComPtr<IBandwidthControl> bwCtrl;
    1470         com::SafeIfaceArray<IBandwidthGroup> bwGroups;
    1471 
    1472         hrc = pMachine->COMGETTER(BandwidthControl)(bwCtrl.asOutParam());                   H();
    1473 
    1474         hrc = bwCtrl->GetAllBandwidthGroups(ComSafeArrayAsOutParam(bwGroups));              H();
    1475 
    1476         InsertConfigNode(pPDM, "AsyncCompletion", &pAc);
    1477         InsertConfigNode(pAc,  "File", &pAcFile);
    14781477        InsertConfigNode(pAcFile,  "BwGroups", &pAcFileBwGroups);
    14791478#ifdef VBOX_WITH_NETSHAPER
    14801479        PCFGMNODE pNetworkShaper;
     1480        InsertConfigNode(pPDM, "NetworkShaper",  &pNetworkShaper);
    14811481        PCFGMNODE pNetworkBwGroups;
    1482 
    1483         InsertConfigNode(pPDM, "NetworkShaper",  &pNetworkShaper);
    14841482        InsertConfigNode(pNetworkShaper, "BwGroups", &pNetworkBwGroups);
    14851483#endif /* VBOX_WITH_NETSHAPER */
     
    14881486        {
    14891487            Bstr strName;
    1490             LONG64 cMaxBytesPerSec;
    1491             BandwidthGroupType_T enmType;
    1492 
    14931488            hrc = bwGroups[i]->COMGETTER(Name)(strName.asOutParam());                       H();
    1494             hrc = bwGroups[i]->COMGETTER(Type)(&enmType);                                   H();
    1495             hrc = bwGroups[i]->COMGETTER(MaxBytesPerSec)(&cMaxBytesPerSec);                 H();
    1496 
    14971489            if (strName.isEmpty())
    14981490                return pVMM->pfnVMR3SetError(pUVM, VERR_CFGM_NO_NODE, RT_SRC_POS, N_("No bandwidth group name specified"));
     1491            BandwidthGroupType_T enmType = BandwidthGroupType_Null;
     1492            hrc = bwGroups[i]->COMGETTER(Type)(&enmType);                                   H();
     1493            LONG64 cMaxBytesPerSec = 0;
     1494            hrc = bwGroups[i]->COMGETTER(MaxBytesPerSec)(&cMaxBytesPerSec);                 H();
    14991495
    15001496            if (enmType == BandwidthGroupType_Disk)
  • trunk/src/VBox/Main/src-server/BandwidthControlImpl.cpp

    r93115 r93628  
    2828#include <iprt/cpp/utils.h>
    2929#include <VBox/com/array.h>
     30#include <VBox/param.h>
    3031#include <algorithm>
    3132
     
    392393                                               LONG64 aMaxBytesPerSec)
    393394{
     395    /*
     396     * Validate input.
     397     */
    394398    if (aMaxBytesPerSec < 0)
    395         return setError(E_INVALIDARG,
    396                         tr("Bandwidth group limit cannot be negative"));
    397 
    398     /* the machine needs to be mutable */
     399        return setError(E_INVALIDARG, tr("Bandwidth group limit cannot be negative"));
     400    switch (aType)
     401    {
     402        case BandwidthGroupType_Null: /*??*/
     403        case BandwidthGroupType_Disk:
     404            break;
     405        case BandwidthGroupType_Network:
     406            if (aName.length() > PDM_NET_SHAPER_MAX_NAME_LEN)
     407                return setError(E_INVALIDARG, tr("Bandwidth name is too long: %zu, max %u"),
     408                                aName.length(), PDM_NET_SHAPER_MAX_NAME_LEN);
     409            break;
     410        default:
     411            AssertFailedReturn(setError(E_INVALIDARG, tr("Invalid group type: %d"), aType));
     412    }
     413    if (aName.isEmpty())
     414        return setError(E_INVALIDARG, tr("Bandwidth group name must not be empty")); /* ConsoleImpl2.cpp fails then */
     415
     416    /*
     417     * The machine needs to be mutable:
     418     */
    399419    AutoMutableOrSavedStateDependency adep(m->pParent);
    400     if (FAILED(adep.rc())) return adep.rc();
    401 
    402     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    403 
    404     /* try to find one with the name first. */
    405     ComObjPtr<BandwidthGroup> group;
    406     HRESULT rc = i_getBandwidthGroupByName(aName, group, false /* aSetError */);
    407 
    408     if (SUCCEEDED(rc))
    409         return setError(VBOX_E_OBJECT_IN_USE,
    410                         tr("Bandwidth group named '%s' already exists"),
    411                         aName.c_str());
    412 
    413     group.createObject();
    414 
    415     rc = group->init(this, aName, aType, aMaxBytesPerSec);
    416     if (FAILED(rc)) return rc;
    417 
    418     m->pParent->i_setModified(Machine::IsModified_BandwidthControl);
    419     m->llBandwidthGroups.backup();
    420     m->llBandwidthGroups->push_back(group);
    421 
    422     return S_OK;
     420    HRESULT hrc = adep.rc();
     421    if (SUCCEEDED(hrc))
     422    {
     423        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     424
     425        /*
     426         * Check that the group doesn't already exist:
     427         */
     428        ComObjPtr<BandwidthGroup> group;
     429        hrc = i_getBandwidthGroupByName(aName, group, false /* aSetError */);
     430        if (FAILED(hrc))
     431        {
     432            /*
     433             * There is an upper limit of the number of network groups imposed by PDM.
     434             */
     435            size_t cNetworkGroups = 0;
     436            if (aType == BandwidthGroupType_Network)
     437                for (BandwidthGroupList::const_iterator it = m->llBandwidthGroups->begin();
     438                     it != m->llBandwidthGroups->end();
     439                     ++it)
     440                    if ((*it)->i_getType() == BandwidthGroupType_Network)
     441                        cNetworkGroups++;
     442            if (cNetworkGroups < PDM_NET_SHAPER_MAX_GROUPS)
     443            {
     444                /*
     445                 * Create the new group.
     446                 */
     447                hrc = group.createObject();
     448                if (SUCCEEDED(hrc))
     449                {
     450                    hrc = group->init(this, aName, aType, aMaxBytesPerSec);
     451                    if (SUCCEEDED(hrc))
     452                    {
     453                        /*
     454                         * Add it to the settings.
     455                         */
     456                        m->pParent->i_setModified(Machine::IsModified_BandwidthControl);
     457                        m->llBandwidthGroups.backup();
     458                        m->llBandwidthGroups->push_back(group);
     459                        hrc = S_OK;
     460                    }
     461                }
     462            }
     463            else
     464                hrc = setError(E_FAIL, tr("Too many network bandwidth groups (max %u)"), PDM_NET_SHAPER_MAX_GROUPS);
     465        }
     466        else
     467            hrc = setError(VBOX_E_OBJECT_IN_USE, tr("Bandwidth group named '%s' already exists"), aName.c_str());
     468    }
     469    return hrc;
    423470}
    424471
Note: See TracChangeset for help on using the changeset viewer.

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