Changeset 93628 in vbox for trunk/src/VBox/Main
- Timestamp:
- Feb 6, 2022 11:44:05 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 149773
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
r93561 r93628 1464 1464 * Bandwidth groups. 1465 1465 */ 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 1466 1472 PCFGMNODE pAc; 1473 InsertConfigNode(pPDM, "AsyncCompletion", &pAc); 1467 1474 PCFGMNODE pAcFile; 1475 InsertConfigNode(pAc, "File", &pAcFile); 1468 1476 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);1478 1477 InsertConfigNode(pAcFile, "BwGroups", &pAcFileBwGroups); 1479 1478 #ifdef VBOX_WITH_NETSHAPER 1480 1479 PCFGMNODE pNetworkShaper; 1480 InsertConfigNode(pPDM, "NetworkShaper", &pNetworkShaper); 1481 1481 PCFGMNODE pNetworkBwGroups; 1482 1483 InsertConfigNode(pPDM, "NetworkShaper", &pNetworkShaper);1484 1482 InsertConfigNode(pNetworkShaper, "BwGroups", &pNetworkBwGroups); 1485 1483 #endif /* VBOX_WITH_NETSHAPER */ … … 1488 1486 { 1489 1487 Bstr strName; 1490 LONG64 cMaxBytesPerSec;1491 BandwidthGroupType_T enmType;1492 1493 1488 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 1497 1489 if (strName.isEmpty()) 1498 1490 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(); 1499 1495 1500 1496 if (enmType == BandwidthGroupType_Disk) -
trunk/src/VBox/Main/src-server/BandwidthControlImpl.cpp
r93115 r93628 28 28 #include <iprt/cpp/utils.h> 29 29 #include <VBox/com/array.h> 30 #include <VBox/param.h> 30 31 #include <algorithm> 31 32 … … 392 393 LONG64 aMaxBytesPerSec) 393 394 { 395 /* 396 * Validate input. 397 */ 394 398 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 */ 399 419 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; 423 470 } 424 471
Note:
See TracChangeset
for help on using the changeset viewer.