VirtualBox

Changeset 41842 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 20, 2012 11:46:31 AM (13 years ago)
Author:
vboxsync
Message:

Main,VBoxManage,docs: bandwidth units changed to bytes (#5582)

Location:
trunk/src/VBox
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageBandwidthControl.cpp

    r40541 r41842  
    4444
    4545/**
     46 * Parses a string in the following format "n[k|m|g|K|M|G]". Stores the value
     47 * of n expressed in bytes to *pLimit. k meas kilobit, while K means kilobyte.
     48 *
     49 * @returns Error message or NULL if successful.
     50 * @param   pcszLimit       The string to parse.
     51 * @param   pLimit          Where to store the result.
     52 */
     53static const char *parseLimit(const char *pcszLimit, LONG64 *pLimit)
     54{
     55    int iMultiplier = _1M;
     56    char *pszNext = NULL;
     57    int rc = RTStrToInt64Ex(pcszLimit, &pszNext, 10, pLimit);
     58
     59    switch (rc)
     60    {
     61        case VINF_SUCCESS:
     62            break;
     63        case VWRN_NUMBER_TOO_BIG:
     64            return "Limit is too big\n";
     65        case VWRN_TRAILING_CHARS:
     66            switch (*pszNext)
     67            {
     68                case 'G': iMultiplier = _1G;       break;
     69                case 'M': iMultiplier = _1M;       break;
     70                case 'K': iMultiplier = _1K;       break;
     71                case 'g': iMultiplier = 125000000; break;
     72                case 'm': iMultiplier = 125000;    break;
     73                case 'k': iMultiplier = 125;       break;
     74                default:  return "Invalid unit suffix. Valid suffixes are: k, m, g, K, M, G\n";
     75            }
     76            break;
     77        case VWRN_TRAILING_SPACES:
     78            return "Trailing spaces in limit!\n";
     79        case VERR_NO_DIGITS:
     80            return "No digits in limit specifier\n";
     81        default:
     82            return "Invalid limit specifier\n";
     83    }
     84    if (*pLimit <= 0)
     85        return "Limit must be positive\n";
     86    if (*pLimit > INT64_MAX / iMultiplier)
     87        return "Limit is too big\n";
     88    *pLimit *= iMultiplier;
     89
     90    return NULL;
     91}
     92
     93/**
    4694 * Handles the 'bandwidthctl myvm add' sub-command.
    4795 * @returns Exit code.
     
    55103        {
    56104            { "--type",   't', RTGETOPT_REQ_STRING },
    57             { "--limit",  'l', RTGETOPT_REQ_UINT32 }
     105            { "--limit",  'l', RTGETOPT_REQ_STRING }
    58106        };
    59107
     
    61109    Bstr name(a->argv[2]);
    62110    const char *pszType  = NULL;
    63     ULONG cMaxMbPerSec   = UINT32_MAX;
     111    LONG64 cMaxBytesPerSec   = INT64_MAX;
    64112
    65113    int c;
     
    85133            case 'l': // limit
    86134            {
    87                 cMaxMbPerSec = ValueUnion.u32;
     135                if (ValueUnion.psz)
     136                {
     137                    const char *pcszError = parseLimit(ValueUnion.psz, &cMaxBytesPerSec);
     138                    if (pcszError)
     139                    {
     140                        errorArgument(pcszError);
     141                        return RTEXITCODE_FAILURE;
     142                    }
     143                }
     144                else
     145                    rc = E_FAIL;
    88146                break;
    89147            }
     
    110168    }
    111169   
    112     CHECK_ERROR2_RET(bwCtrl, CreateBandwidthGroup(name.raw(), enmType, cMaxMbPerSec), RTEXITCODE_FAILURE);
     170    CHECK_ERROR2_RET(bwCtrl, CreateBandwidthGroup(name.raw(), enmType, cMaxBytesPerSec), RTEXITCODE_FAILURE);
    113171
    114172    return RTEXITCODE_SUCCESS;
     
    126184    static const RTGETOPTDEF g_aBWCtlAddOptions[] =
    127185        {
    128             { "--limit",  'l', RTGETOPT_REQ_UINT32 }
     186            { "--limit",  'l', RTGETOPT_REQ_STRING }
    129187        };
    130188
    131189
    132190    Bstr name(a->argv[2]);
    133     ULONG cMaxMbPerSec   = UINT32_MAX;
     191    LONG64 cMaxBytesPerSec   = INT64_MAX;
    134192
    135193    int c;
     
    146204            case 'l': // limit
    147205            {
    148                 cMaxMbPerSec = ValueUnion.u32;
     206                if (ValueUnion.psz)
     207                {
     208                    const char *pcszError = parseLimit(ValueUnion.psz, &cMaxBytesPerSec);
     209                    if (pcszError)
     210                    {
     211                        errorArgument(pcszError);
     212                        return RTEXITCODE_FAILURE;
     213                    }
     214                }
     215                else
     216                    rc = E_FAIL;
    149217                break;
    150218            }
     
    160228
    161229   
    162     if (cMaxMbPerSec != UINT32_MAX)
     230    if (cMaxBytesPerSec != INT64_MAX)
    163231    {
    164232        ComPtr<IBandwidthGroup> bwGroup;
    165233        CHECK_ERROR2_RET(bwCtrl, GetBandwidthGroup(name.raw(), bwGroup.asOutParam()), RTEXITCODE_FAILURE);
    166234        if (SUCCEEDED(rc))
    167             CHECK_ERROR2_RET(bwGroup, COMSETTER(MaxMbPerSec)(cMaxMbPerSec), RTEXITCODE_FAILURE);
     235            CHECK_ERROR2_RET(bwGroup, COMSETTER(MaxBytesPerSec)(cMaxBytesPerSec), RTEXITCODE_FAILURE);
    168236    }
    169237
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r41371 r41842  
    514514        RTStrmPrintf(pStrm,
    515515                     "VBoxManage bandwidthctl     <uuid|vmname>\n"
    516                      "                            add <name> --type <disk|network> --limit <megabytes per second> |\n"
    517                      "                            set <name> --limit <megabytes per second> |\n"
     516                     "                            add <name> --type disk|network --limit <megabytes per second>[k|m|g|K|M|G] |\n"
     517                     "                            set <name> --limit <megabytes per second>[k|m|g|K|M|G] |\n"
    518518                     "                            remove <name> |\n"
    519519                     "                            list [--machinereadable]\n"
     520                     "                            (limit units: k=kilobit, m=megabit, g=gigabit, K=kilobyte, M=megabyte, G=gigabyte)\n"
    520521                     "\n");
    521522
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp

    r41584 r41842  
    260260    {
    261261        Bstr strName;
    262         ULONG cMaxMbPerSec;
     262        LONG64 cMaxBytesPerSec;
    263263        BandwidthGroupType_T enmType;
    264264
    265265        CHECK_ERROR_RET(bwGroups[i], COMGETTER(Name)(strName.asOutParam()), rc);
    266266        CHECK_ERROR_RET(bwGroups[i], COMGETTER(Type)(&enmType), rc);
    267         CHECK_ERROR_RET(bwGroups[i], COMGETTER(MaxMbPerSec)(&cMaxMbPerSec), rc);
     267        CHECK_ERROR_RET(bwGroups[i], COMGETTER(MaxBytesPerSec)(&cMaxBytesPerSec), rc);
    268268
    269269        const char *pszType = bwGroupTypeToString(enmType);
    270270        if (details == VMINFO_MACHINEREADABLE)
    271             RTPrintf("BandwidthGroup%zu=%ls,%s,%d\n", i, strName.raw(), pszType, cMaxMbPerSec);
     271            RTPrintf("BandwidthGroup%zu=%ls,%s,%lld\n", i, strName.raw(), pszType, cMaxBytesPerSec);
    272272        else
    273             RTPrintf("Name: '%ls', Type: %s, Limit: %d Mbytes/sec\n", strName.raw(), pszType, cMaxMbPerSec);
     273        {
     274            const char *pszUnits = "";
     275            LONG64 cBytes = cMaxBytesPerSec;
     276            if (!(cBytes % _1G))
     277            {
     278                pszUnits = "G";
     279                cBytes /= _1G;
     280            }
     281            else if (!(cBytes % _1M))
     282            {
     283                pszUnits = "M";
     284                cBytes /= _1M;
     285            }
     286            else if (!(cBytes % _1K))
     287            {
     288                pszUnits = "K";
     289                cBytes /= _1K;
     290            }
     291            const char *pszNetUnits = NULL;
     292            if (enmType == BandwidthGroupType_Network)
     293            {
     294                /*
     295                 * We want to report network rate limit in bits/s, not bytes.
     296                 * Only if it cannot be express it in kilobits we will fall
     297                 * back to reporting it in bytes.
     298                 */
     299                LONG64 cBits = cMaxBytesPerSec;
     300                if (!(cBits % 125))
     301                {
     302                    cBits /= 125;
     303                    pszNetUnits = "k";
     304                    if (!(cBits % 1000000))
     305                    {
     306                        cBits /= 1000000;
     307                        pszNetUnits = "g";
     308                    }
     309                    else if (!(cBits % 1000))
     310                    {
     311                        cBits /= 1000;
     312                        pszNetUnits = "m";
     313                    }
     314                    RTPrintf("Name: '%ls', Type: %s, Limit: %lld %sbits/sec (%lld %sbytes/sec)\n", strName.raw(), pszType, cBits, pszNetUnits, cBytes, pszUnits);
     315                }
     316            }
     317            if (!pszNetUnits)
     318                RTPrintf("Name: '%ls', Type: %s, Limit: %lld %sbytes/sec\n", strName.raw(), pszType, cBytes, pszUnits);
     319        }
    274320    }
    275321    if (details != VMINFO_MACHINEREADABLE)
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r41404 r41842  
    1649516495    </attribute>
    1649616496
    16497     <attribute name="maxMbPerSec" type="unsigned long">
    16498       <desc>The maximum number of MBytes which can be transfered by all
     16497    <attribute name="maxBytesPerSec" type="long long">
     16498      <desc>The maximum number of bytes which can be transfered by all
    1649916499        entities attached to this group during one second.</desc>
    1650016500    </attribute>
     
    1653316533        <desc>The type of the bandwidth group (network or disk).</desc>
    1653416534      </param>
    16535       <param name="maxMbPerSec" type="unsigned long" dir="in">
    16536         <desc>The maximum number of MBytes which can be transfered by all
     16535      <param name="maxBytesPerSec" type="long long" dir="in">
     16536        <desc>The maximum number of bytes which can be transfered by all
    1653716537          entities attached to this group during one second.</desc>
    1653816538      </param>
  • trunk/src/VBox/Main/include/BandwidthControlImpl.h

    r35638 r41842  
    5252    void uninit();
    5353
    54     STDMETHOD(CreateBandwidthGroup) (IN_BSTR aName, BandwidthGroupType_T aType, ULONG aMaxMbPerSec);
     54    STDMETHOD(CreateBandwidthGroup) (IN_BSTR aName, BandwidthGroupType_T aType, LONG64 aMaxBytesPerSec);
    5555    STDMETHOD(DeleteBandwidthGroup) (IN_BSTR aName);
    5656    STDMETHOD(COMGETTER(NumGroups)) (ULONG *aGroups);
  • trunk/src/VBox/Main/include/BandwidthGroupImpl.h

    r35638 r41842  
    4444                 const Utf8Str &aName,
    4545                 BandwidthGroupType_T aType,
    46                  ULONG aMaxMbPerSec);
     46                 LONG64 aMaxBytesPerSec);
    4747    HRESULT init(BandwidthControl *aParent, BandwidthGroup *aThat, bool aReshare = false);
    4848    HRESULT initCopy(BandwidthControl *aParent, BandwidthGroup *aThat);
     
    5555    STDMETHOD(COMGETTER(Type))(BandwidthGroupType_T *aType);
    5656    STDMETHOD(COMGETTER(Reference))(ULONG *aReferences);
    57     STDMETHOD(COMGETTER(MaxMbPerSec))(ULONG *aMaxMbPerSec);
    58     STDMETHOD(COMSETTER(MaxMbPerSec))(ULONG aMaxMbPerSec);
     57    STDMETHOD(COMGETTER(MaxBytesPerSec))(LONG64 *aMaxBytesPerSec);
     58    STDMETHOD(COMSETTER(MaxBytesPerSec))(LONG64 aMaxBytesPerSec);
    5959
    6060    // public methods only for internal purposes
     
    6565    const Utf8Str &getName() const;
    6666    BandwidthGroupType_T getType() const;
    67     ULONG getMaxMbPerSec() const;
     67    LONG64 getMaxBytesPerSec() const;
    6868    ULONG getReferences() const;
    6969
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r41528 r41842  
    51585158        {
    51595159            /* No need to call in the EMT thread. */
    5160             ULONG cMax;
     5160            LONG64 cMax;
    51615161            Bstr strName;
    51625162            BandwidthGroupType_T enmType;
    51635163            rc = aBandwidthGroup->COMGETTER(Name)(strName.asOutParam());
    51645164            if (SUCCEEDED(rc))
    5165                 rc = aBandwidthGroup->COMGETTER(MaxMbPerSec)(&cMax);
     5165                rc = aBandwidthGroup->COMGETTER(MaxBytesPerSec)(&cMax);
    51665166            if (SUCCEEDED(rc))
    51675167                rc = aBandwidthGroup->COMGETTER(Type)(&enmType);
     
    51725172                if (enmType == BandwidthGroupType_Disk)
    51735173                    vrc = PDMR3AsyncCompletionBwMgrSetMaxForFile(ptrVM, Utf8Str(strName).c_str(),
    5174                                                                  cMax * _1M);
     5174                                                                 cMax);
    51755175#ifdef VBOX_WITH_NETSHAPER
    51765176                else if (enmType == BandwidthGroupType_Network)
    51775177                    vrc = PDMR3NsBwGroupSetLimit(ptrVM, Utf8Str(strName).c_str(),
    5178                                                                  cMax * 1000);
     5178                                                 cMax);
    51795179                else
    51805180                    rc = E_NOTIMPL;
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r41774 r41842  
    10321032        {
    10331033            Bstr strName;
    1034             ULONG cMaxMbPerSec;
     1034            LONG64 cMaxBytesPerSec;
    10351035            BandwidthGroupType_T enmType;
    10361036
    10371037            hrc = bwGroups[i]->COMGETTER(Name)(strName.asOutParam());                       H();
    10381038            hrc = bwGroups[i]->COMGETTER(Type)(&enmType);                                   H();
    1039             hrc = bwGroups[i]->COMGETTER(MaxMbPerSec)(&cMaxMbPerSec);                       H();
     1039            hrc = bwGroups[i]->COMGETTER(MaxBytesPerSec)(&cMaxBytesPerSec);                       H();
    10401040
    10411041            if (enmType == BandwidthGroupType_Disk)
     
    10431043                PCFGMNODE pBwGroup;
    10441044                InsertConfigNode(pAcFileBwGroups, Utf8Str(strName).c_str(), &pBwGroup);
    1045                 InsertConfigInteger(pBwGroup, "Max", cMaxMbPerSec * _1M);
    1046                 InsertConfigInteger(pBwGroup, "Start", cMaxMbPerSec * _1M);
     1045                InsertConfigInteger(pBwGroup, "Max", cMaxBytesPerSec);
     1046                InsertConfigInteger(pBwGroup, "Start", cMaxBytesPerSec);
    10471047                InsertConfigInteger(pBwGroup, "Step", 0);
    10481048            }
     
    10531053                PCFGMNODE pBwGroup;
    10541054                InsertConfigNode(pNetworkBwGroups, Utf8Str(strName).c_str(), &pBwGroup);
    1055                 InsertConfigInteger(pBwGroup, "Max", cMaxMbPerSec * 1000); // @todo: _1M);
     1055                InsertConfigInteger(pBwGroup, "Max", cMaxBytesPerSec);
    10561056            }
    10571057#endif /* VBOX_WITH_NETSHAPER */
  • trunk/src/VBox/Main/src-server/BandwidthControlImpl.cpp

    r40257 r41842  
    410410}
    411411
    412 STDMETHODIMP BandwidthControl::CreateBandwidthGroup(IN_BSTR aName, BandwidthGroupType_T aType, ULONG aMaxMbPerSec)
     412STDMETHODIMP BandwidthControl::CreateBandwidthGroup(IN_BSTR aName, BandwidthGroupType_T aType, LONG64 aMaxBytesPerSec)
    413413{
    414414    AutoCaller autoCaller(this);
     
    432432    group.createObject();
    433433
    434     rc = group->init(this, aName, aType, aMaxMbPerSec);
     434    rc = group->init(this, aName, aType, aMaxBytesPerSec);
    435435    if (FAILED(rc)) return rc;
    436436
     
    537537    {
    538538        const settings::BandwidthGroup &gr = *it;
    539         rc = CreateBandwidthGroup(Bstr(gr.strName).raw(), gr.enmType, gr.cMaxMbPerSec);
     539        rc = CreateBandwidthGroup(Bstr(gr.strName).raw(), gr.enmType, gr.cMaxBytesPerSec);
    540540        if (FAILED(rc)) break;
    541541    }
     
    562562        group.strName      = (*it)->getName();
    563563        group.enmType      = (*it)->getType();
    564         group.cMaxMbPerSec = (*it)->getMaxMbPerSec();
     564        group.cMaxBytesPerSec = (*it)->getMaxBytesPerSec();
    565565
    566566        data.llBandwidthGroups.push_back(group);
  • trunk/src/VBox/Main/src-server/BandwidthGroupImpl.cpp

    r40257 r41842  
    3535    BackupableBandwidthGroupData()
    3636        : enmType(BandwidthGroupType_Null),
    37           aMaxMbPerSec(0),
     37          aMaxBytesPerSec(0),
    3838          cReferences(0)
    3939    { }
     
    4141    Utf8Str                 strName;
    4242    BandwidthGroupType_T    enmType;
    43     ULONG                   aMaxMbPerSec;
     43    LONG64                  aMaxBytesPerSec;
    4444    ULONG                   cReferences;
    4545};
     
    8787                             const Utf8Str &aName,
    8888                             BandwidthGroupType_T aType,
    89                              ULONG aMaxMbPerSec)
     89                             LONG64 aMaxBytesPerSec)
    9090{
    9191    LogFlowThisFunc(("aParent=%p aName=\"%s\"\n",
     
    111111    m->bd->enmType = aType;
    112112    m->bd->cReferences = 0;
    113     m->bd->aMaxMbPerSec = aMaxMbPerSec;
     113    m->bd->aMaxBytesPerSec = aMaxBytesPerSec;
    114114
    115115    /* Confirm a successful initialization */
     
    268268}
    269269
    270 STDMETHODIMP BandwidthGroup::COMGETTER(MaxMbPerSec)(ULONG *aMaxMbPerSec)
    271 {
    272     CheckComArgOutPointerValid(aMaxMbPerSec);
     270STDMETHODIMP BandwidthGroup::COMGETTER(MaxBytesPerSec)(LONG64 *aMaxBytesPerSec)
     271{
     272    CheckComArgOutPointerValid(aMaxBytesPerSec);
    273273
    274274    AutoCaller autoCaller(this);
     
    277277    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    278278
    279     *aMaxMbPerSec = m->bd->aMaxMbPerSec;
    280 
    281     return S_OK;
    282 }
    283 
    284 STDMETHODIMP BandwidthGroup::COMSETTER(MaxMbPerSec)(ULONG aMaxMbPerSec)
     279    *aMaxBytesPerSec = m->bd->aMaxBytesPerSec;
     280
     281    return S_OK;
     282}
     283
     284STDMETHODIMP BandwidthGroup::COMSETTER(MaxBytesPerSec)(LONG64 aMaxBytesPerSec)
    285285{
    286286    AutoCaller autoCaller(this);
     
    290290
    291291    m->bd.backup();
    292     m->bd->aMaxMbPerSec = aMaxMbPerSec;
     292    m->bd->aMaxBytesPerSec = aMaxBytesPerSec;
    293293
    294294    /* inform direct session if any. */
     
    392392}
    393393
    394 ULONG BandwidthGroup::getMaxMbPerSec() const
    395 {
    396     return m->bd->aMaxMbPerSec;
     394LONG64 BandwidthGroup::getMaxBytesPerSec() const
     395{
     396    return m->bd->aMaxBytesPerSec;
    397397}
    398398
  • trunk/src/VBox/Main/xml/Settings.cpp

    r41371 r41842  
    27962796                        throw ConfigFileError(this, pelmBandwidthGroup, N_("Missing BandwidthGroup/@type attribute"));
    27972797
    2798                     pelmBandwidthGroup->getAttributeValue("maxMbPerSec", gr.cMaxMbPerSec);
     2798                    if (!pelmBandwidthGroup->getAttributeValue("maxBytesPerSec", gr.cMaxBytesPerSec))
     2799                    {
     2800                        pelmBandwidthGroup->getAttributeValue("maxMbPerSec", gr.cMaxBytesPerSec);
     2801                        gr.cMaxBytesPerSec *= _1M;
     2802                    }
    27992803                    hw.ioSettings.llBandwidthGroups.push_back(gr);
    28002804                }
     
    40294033                }
    40304034                pelmThis->setAttribute("type", pcszType);
    4031                 pelmThis->setAttribute("maxMbPerSec", gr.cMaxMbPerSec);
     4035                if (m->sv >= SettingsVersion_v1_13)
     4036                    pelmThis->setAttribute("maxBytesPerSec", gr.cMaxBytesPerSec);
     4037                else
     4038                    pelmThis->setAttribute("maxMbPerSec", gr.cMaxBytesPerSec / _1M);
    40324039            }
    40334040        }
     
    46654672    }
    46664673
     4674    if (m->sv < SettingsVersion_v1_13)
     4675    {
     4676        // VirtualBox 4.2 changes the units for bandwidth group limits.
     4677        for (BandwidthGroupList::const_iterator it = hardwareMachine.ioSettings.llBandwidthGroups.begin();
     4678             it != hardwareMachine.ioSettings.llBandwidthGroups.end();
     4679             ++it)
     4680        {
     4681            const BandwidthGroup &gr = *it;
     4682            if (gr.cMaxBytesPerSec % _1M)
     4683            {
     4684                // Bump version if a limit cannot be expressed in megabytes
     4685                m->sv = SettingsVersion_v1_13;
     4686                break;
     4687            }
     4688        }
     4689    }
     4690
    46674691    if (m->sv < SettingsVersion_v1_12)
    46684692    {
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