Changeset 41842 in vbox for trunk/src/VBox
- Timestamp:
- Jun 20, 2012 11:46:31 AM (13 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageBandwidthControl.cpp
r40541 r41842 44 44 45 45 /** 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 */ 53 static 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 /** 46 94 * Handles the 'bandwidthctl myvm add' sub-command. 47 95 * @returns Exit code. … … 55 103 { 56 104 { "--type", 't', RTGETOPT_REQ_STRING }, 57 { "--limit", 'l', RTGETOPT_REQ_ UINT32}105 { "--limit", 'l', RTGETOPT_REQ_STRING } 58 106 }; 59 107 … … 61 109 Bstr name(a->argv[2]); 62 110 const char *pszType = NULL; 63 ULONG cMaxMbPerSec = UINT32_MAX;111 LONG64 cMaxBytesPerSec = INT64_MAX; 64 112 65 113 int c; … … 85 133 case 'l': // limit 86 134 { 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; 88 146 break; 89 147 } … … 110 168 } 111 169 112 CHECK_ERROR2_RET(bwCtrl, CreateBandwidthGroup(name.raw(), enmType, cMax MbPerSec), RTEXITCODE_FAILURE);170 CHECK_ERROR2_RET(bwCtrl, CreateBandwidthGroup(name.raw(), enmType, cMaxBytesPerSec), RTEXITCODE_FAILURE); 113 171 114 172 return RTEXITCODE_SUCCESS; … … 126 184 static const RTGETOPTDEF g_aBWCtlAddOptions[] = 127 185 { 128 { "--limit", 'l', RTGETOPT_REQ_ UINT32}186 { "--limit", 'l', RTGETOPT_REQ_STRING } 129 187 }; 130 188 131 189 132 190 Bstr name(a->argv[2]); 133 ULONG cMaxMbPerSec = UINT32_MAX;191 LONG64 cMaxBytesPerSec = INT64_MAX; 134 192 135 193 int c; … … 146 204 case 'l': // limit 147 205 { 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; 149 217 break; 150 218 } … … 160 228 161 229 162 if (cMax MbPerSec != UINT32_MAX)230 if (cMaxBytesPerSec != INT64_MAX) 163 231 { 164 232 ComPtr<IBandwidthGroup> bwGroup; 165 233 CHECK_ERROR2_RET(bwCtrl, GetBandwidthGroup(name.raw(), bwGroup.asOutParam()), RTEXITCODE_FAILURE); 166 234 if (SUCCEEDED(rc)) 167 CHECK_ERROR2_RET(bwGroup, COMSETTER(Max MbPerSec)(cMaxMbPerSec), RTEXITCODE_FAILURE);235 CHECK_ERROR2_RET(bwGroup, COMSETTER(MaxBytesPerSec)(cMaxBytesPerSec), RTEXITCODE_FAILURE); 168 236 } 169 237 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r41371 r41842 514 514 RTStrmPrintf(pStrm, 515 515 "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" 518 518 " remove <name> |\n" 519 519 " list [--machinereadable]\n" 520 " (limit units: k=kilobit, m=megabit, g=gigabit, K=kilobyte, M=megabyte, G=gigabyte)\n" 520 521 "\n"); 521 522 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
r41584 r41842 260 260 { 261 261 Bstr strName; 262 ULONG cMaxMbPerSec;262 LONG64 cMaxBytesPerSec; 263 263 BandwidthGroupType_T enmType; 264 264 265 265 CHECK_ERROR_RET(bwGroups[i], COMGETTER(Name)(strName.asOutParam()), rc); 266 266 CHECK_ERROR_RET(bwGroups[i], COMGETTER(Type)(&enmType), rc); 267 CHECK_ERROR_RET(bwGroups[i], COMGETTER(Max MbPerSec)(&cMaxMbPerSec), rc);267 CHECK_ERROR_RET(bwGroups[i], COMGETTER(MaxBytesPerSec)(&cMaxBytesPerSec), rc); 268 268 269 269 const char *pszType = bwGroupTypeToString(enmType); 270 270 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); 272 272 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 } 274 320 } 275 321 if (details != VMINFO_MACHINEREADABLE) -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r41404 r41842 16495 16495 </attribute> 16496 16496 16497 <attribute name="max MbPerSec" type="unsignedlong">16498 <desc>The maximum number of MBytes which can be transfered by all16497 <attribute name="maxBytesPerSec" type="long long"> 16498 <desc>The maximum number of bytes which can be transfered by all 16499 16499 entities attached to this group during one second.</desc> 16500 16500 </attribute> … … 16533 16533 <desc>The type of the bandwidth group (network or disk).</desc> 16534 16534 </param> 16535 <param name="max MbPerSec" type="unsignedlong" dir="in">16536 <desc>The maximum number of MBytes which can be transfered by all16535 <param name="maxBytesPerSec" type="long long" dir="in"> 16536 <desc>The maximum number of bytes which can be transfered by all 16537 16537 entities attached to this group during one second.</desc> 16538 16538 </param> -
trunk/src/VBox/Main/include/BandwidthControlImpl.h
r35638 r41842 52 52 void uninit(); 53 53 54 STDMETHOD(CreateBandwidthGroup) (IN_BSTR aName, BandwidthGroupType_T aType, ULONG aMaxMbPerSec);54 STDMETHOD(CreateBandwidthGroup) (IN_BSTR aName, BandwidthGroupType_T aType, LONG64 aMaxBytesPerSec); 55 55 STDMETHOD(DeleteBandwidthGroup) (IN_BSTR aName); 56 56 STDMETHOD(COMGETTER(NumGroups)) (ULONG *aGroups); -
trunk/src/VBox/Main/include/BandwidthGroupImpl.h
r35638 r41842 44 44 const Utf8Str &aName, 45 45 BandwidthGroupType_T aType, 46 ULONG aMaxMbPerSec);46 LONG64 aMaxBytesPerSec); 47 47 HRESULT init(BandwidthControl *aParent, BandwidthGroup *aThat, bool aReshare = false); 48 48 HRESULT initCopy(BandwidthControl *aParent, BandwidthGroup *aThat); … … 55 55 STDMETHOD(COMGETTER(Type))(BandwidthGroupType_T *aType); 56 56 STDMETHOD(COMGETTER(Reference))(ULONG *aReferences); 57 STDMETHOD(COMGETTER(Max MbPerSec))(ULONG *aMaxMbPerSec);58 STDMETHOD(COMSETTER(Max MbPerSec))(ULONG aMaxMbPerSec);57 STDMETHOD(COMGETTER(MaxBytesPerSec))(LONG64 *aMaxBytesPerSec); 58 STDMETHOD(COMSETTER(MaxBytesPerSec))(LONG64 aMaxBytesPerSec); 59 59 60 60 // public methods only for internal purposes … … 65 65 const Utf8Str &getName() const; 66 66 BandwidthGroupType_T getType() const; 67 ULONG getMaxMbPerSec() const;67 LONG64 getMaxBytesPerSec() const; 68 68 ULONG getReferences() const; 69 69 -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r41528 r41842 5158 5158 { 5159 5159 /* No need to call in the EMT thread. */ 5160 ULONGcMax;5160 LONG64 cMax; 5161 5161 Bstr strName; 5162 5162 BandwidthGroupType_T enmType; 5163 5163 rc = aBandwidthGroup->COMGETTER(Name)(strName.asOutParam()); 5164 5164 if (SUCCEEDED(rc)) 5165 rc = aBandwidthGroup->COMGETTER(Max MbPerSec)(&cMax);5165 rc = aBandwidthGroup->COMGETTER(MaxBytesPerSec)(&cMax); 5166 5166 if (SUCCEEDED(rc)) 5167 5167 rc = aBandwidthGroup->COMGETTER(Type)(&enmType); … … 5172 5172 if (enmType == BandwidthGroupType_Disk) 5173 5173 vrc = PDMR3AsyncCompletionBwMgrSetMaxForFile(ptrVM, Utf8Str(strName).c_str(), 5174 cMax * _1M);5174 cMax); 5175 5175 #ifdef VBOX_WITH_NETSHAPER 5176 5176 else if (enmType == BandwidthGroupType_Network) 5177 5177 vrc = PDMR3NsBwGroupSetLimit(ptrVM, Utf8Str(strName).c_str(), 5178 cMax * 1000);5178 cMax); 5179 5179 else 5180 5180 rc = E_NOTIMPL; -
trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
r41774 r41842 1032 1032 { 1033 1033 Bstr strName; 1034 ULONG cMaxMbPerSec;1034 LONG64 cMaxBytesPerSec; 1035 1035 BandwidthGroupType_T enmType; 1036 1036 1037 1037 hrc = bwGroups[i]->COMGETTER(Name)(strName.asOutParam()); H(); 1038 1038 hrc = bwGroups[i]->COMGETTER(Type)(&enmType); H(); 1039 hrc = bwGroups[i]->COMGETTER(Max MbPerSec)(&cMaxMbPerSec); H();1039 hrc = bwGroups[i]->COMGETTER(MaxBytesPerSec)(&cMaxBytesPerSec); H(); 1040 1040 1041 1041 if (enmType == BandwidthGroupType_Disk) … … 1043 1043 PCFGMNODE pBwGroup; 1044 1044 InsertConfigNode(pAcFileBwGroups, Utf8Str(strName).c_str(), &pBwGroup); 1045 InsertConfigInteger(pBwGroup, "Max", cMax MbPerSec * _1M);1046 InsertConfigInteger(pBwGroup, "Start", cMax MbPerSec * _1M);1045 InsertConfigInteger(pBwGroup, "Max", cMaxBytesPerSec); 1046 InsertConfigInteger(pBwGroup, "Start", cMaxBytesPerSec); 1047 1047 InsertConfigInteger(pBwGroup, "Step", 0); 1048 1048 } … … 1053 1053 PCFGMNODE pBwGroup; 1054 1054 InsertConfigNode(pNetworkBwGroups, Utf8Str(strName).c_str(), &pBwGroup); 1055 InsertConfigInteger(pBwGroup, "Max", cMax MbPerSec * 1000); // @todo: _1M);1055 InsertConfigInteger(pBwGroup, "Max", cMaxBytesPerSec); 1056 1056 } 1057 1057 #endif /* VBOX_WITH_NETSHAPER */ -
trunk/src/VBox/Main/src-server/BandwidthControlImpl.cpp
r40257 r41842 410 410 } 411 411 412 STDMETHODIMP BandwidthControl::CreateBandwidthGroup(IN_BSTR aName, BandwidthGroupType_T aType, ULONG aMaxMbPerSec)412 STDMETHODIMP BandwidthControl::CreateBandwidthGroup(IN_BSTR aName, BandwidthGroupType_T aType, LONG64 aMaxBytesPerSec) 413 413 { 414 414 AutoCaller autoCaller(this); … … 432 432 group.createObject(); 433 433 434 rc = group->init(this, aName, aType, aMax MbPerSec);434 rc = group->init(this, aName, aType, aMaxBytesPerSec); 435 435 if (FAILED(rc)) return rc; 436 436 … … 537 537 { 538 538 const settings::BandwidthGroup &gr = *it; 539 rc = CreateBandwidthGroup(Bstr(gr.strName).raw(), gr.enmType, gr.cMax MbPerSec);539 rc = CreateBandwidthGroup(Bstr(gr.strName).raw(), gr.enmType, gr.cMaxBytesPerSec); 540 540 if (FAILED(rc)) break; 541 541 } … … 562 562 group.strName = (*it)->getName(); 563 563 group.enmType = (*it)->getType(); 564 group.cMax MbPerSec = (*it)->getMaxMbPerSec();564 group.cMaxBytesPerSec = (*it)->getMaxBytesPerSec(); 565 565 566 566 data.llBandwidthGroups.push_back(group); -
trunk/src/VBox/Main/src-server/BandwidthGroupImpl.cpp
r40257 r41842 35 35 BackupableBandwidthGroupData() 36 36 : enmType(BandwidthGroupType_Null), 37 aMax MbPerSec(0),37 aMaxBytesPerSec(0), 38 38 cReferences(0) 39 39 { } … … 41 41 Utf8Str strName; 42 42 BandwidthGroupType_T enmType; 43 ULONG aMaxMbPerSec;43 LONG64 aMaxBytesPerSec; 44 44 ULONG cReferences; 45 45 }; … … 87 87 const Utf8Str &aName, 88 88 BandwidthGroupType_T aType, 89 ULONG aMaxMbPerSec)89 LONG64 aMaxBytesPerSec) 90 90 { 91 91 LogFlowThisFunc(("aParent=%p aName=\"%s\"\n", … … 111 111 m->bd->enmType = aType; 112 112 m->bd->cReferences = 0; 113 m->bd->aMax MbPerSec = aMaxMbPerSec;113 m->bd->aMaxBytesPerSec = aMaxBytesPerSec; 114 114 115 115 /* Confirm a successful initialization */ … … 268 268 } 269 269 270 STDMETHODIMP BandwidthGroup::COMGETTER(Max MbPerSec)(ULONG *aMaxMbPerSec)271 { 272 CheckComArgOutPointerValid(aMax MbPerSec);270 STDMETHODIMP BandwidthGroup::COMGETTER(MaxBytesPerSec)(LONG64 *aMaxBytesPerSec) 271 { 272 CheckComArgOutPointerValid(aMaxBytesPerSec); 273 273 274 274 AutoCaller autoCaller(this); … … 277 277 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 278 278 279 *aMax MbPerSec = m->bd->aMaxMbPerSec;280 281 return S_OK; 282 } 283 284 STDMETHODIMP BandwidthGroup::COMSETTER(Max MbPerSec)(ULONG aMaxMbPerSec)279 *aMaxBytesPerSec = m->bd->aMaxBytesPerSec; 280 281 return S_OK; 282 } 283 284 STDMETHODIMP BandwidthGroup::COMSETTER(MaxBytesPerSec)(LONG64 aMaxBytesPerSec) 285 285 { 286 286 AutoCaller autoCaller(this); … … 290 290 291 291 m->bd.backup(); 292 m->bd->aMax MbPerSec = aMaxMbPerSec;292 m->bd->aMaxBytesPerSec = aMaxBytesPerSec; 293 293 294 294 /* inform direct session if any. */ … … 392 392 } 393 393 394 ULONG BandwidthGroup::getMaxMbPerSec() const395 { 396 return m->bd->aMax MbPerSec;394 LONG64 BandwidthGroup::getMaxBytesPerSec() const 395 { 396 return m->bd->aMaxBytesPerSec; 397 397 } 398 398 -
trunk/src/VBox/Main/xml/Settings.cpp
r41371 r41842 2796 2796 throw ConfigFileError(this, pelmBandwidthGroup, N_("Missing BandwidthGroup/@type attribute")); 2797 2797 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 } 2799 2803 hw.ioSettings.llBandwidthGroups.push_back(gr); 2800 2804 } … … 4029 4033 } 4030 4034 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); 4032 4039 } 4033 4040 } … … 4665 4672 } 4666 4673 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 4667 4691 if (m->sv < SettingsVersion_v1_12) 4668 4692 {
Note:
See TracChangeset
for help on using the changeset viewer.