Changeset 41842 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Jun 20, 2012 11:46:31 AM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 78670
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 3 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)
Note:
See TracChangeset
for help on using the changeset viewer.