Changeset 25930 in vbox for trunk/src/VBox/Main
- Timestamp:
- Jan 20, 2010 12:59:47 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56765
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r25913 r25930 97 97 98 98 Machine::Data::Data() 99 : mSnapshotsTreeLockHandle(LOCKCLASS_LISTOFSNAPSHOTS)100 99 { 101 100 mRegistered = FALSE; … … 604 603 605 604 /* rollback all changes */ 606 rollback 605 rollback(false /* aNotify */); 607 606 608 607 /* uninitialize the common part to make sure all data is reset to … … 740 739 if (mData->m_pMachineConfigFile) 741 740 { 742 // @todo why are we parsing this several times?743 // t his is hugely inefficient741 // reset the XML file to force loadSettings() (called from registeredInit()) 742 // to parse it again; the file might have changed 744 743 delete mData->m_pMachineConfigFile; 745 744 mData->m_pMachineConfigFile = NULL; … … 5700 5699 { 5701 5700 AutoCaller autoCaller(this); 5702 AssertComRCReturnVoid 5703 AssertComRCReturnVoid (autoCaller.state() == InUninit ||5704 autoCaller.state() == Limited);5701 AssertComRCReturnVoid(autoCaller.rc()); 5702 AssertComRCReturnVoid( autoCaller.state() == InUninit 5703 || autoCaller.state() == Limited); 5705 5704 5706 5705 /* uninit all children using addDependentChild()/removeDependentChild() … … 5710 5709 /* tell all our other child objects we've been uninitialized */ 5711 5710 5712 for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); slot++)5711 for (ULONG slot = 0; slot < RT_ELEMENTS(mNetworkAdapters); slot++) 5713 5712 { 5714 5713 if (mNetworkAdapters[slot]) … … 5731 5730 } 5732 5731 5733 for (ULONG slot = 0; slot < RT_ELEMENTS (mParallelPorts); slot++)5732 for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); slot++) 5734 5733 { 5735 5734 if (mParallelPorts[slot]) … … 5740 5739 } 5741 5740 5742 for (ULONG slot = 0; slot < RT_ELEMENTS (mSerialPorts); slot++)5741 for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); slot++) 5743 5742 { 5744 5743 if (mSerialPorts[slot]) … … 5771 5770 * disk attachments will already be uninitialized and deleted, so this 5772 5771 * code will not affect them. */ 5773 if (!!mMediaData && (getClassID() == clsidMachine || getClassID() == clsidSnapshotMachine)) 5772 VBoxClsID clsid = getClassID(); 5773 if ( !!mMediaData 5774 && (clsid == clsidMachine || clsid == clsidSnapshotMachine) 5775 ) 5774 5776 { 5775 5777 for (MediaData::AttachmentList::const_iterator it = mMediaData->mAttachments.begin(); … … 6025 6027 6026 6028 /* Snapshot node (optional) */ 6027 if (mData->m_pMachineConfigFile->llFirstSnapshot.size()) 6028 { 6029 // there can only be one root snapshot 6030 Assert(mData->m_pMachineConfigFile->llFirstSnapshot.size() == 1); 6029 size_t cRootSnapshots; 6030 if ((cRootSnapshots = mData->m_pMachineConfigFile->llFirstSnapshot.size())) 6031 { 6032 // there must be only one root snapshot 6033 Assert(cRootSnapshots == 1); 6031 6034 6032 6035 settings::Snapshot &snap = mData->m_pMachineConfigFile->llFirstSnapshot.front(); … … 6075 6078 catch (...) 6076 6079 { 6077 rc = VirtualBox::handleUnexpectedExceptions 6080 rc = VirtualBox::handleUnexpectedExceptions(RT_SRC_POS); 6078 6081 } 6079 6082 … … 6539 6542 if (FAILED(rc)) 6540 6543 { 6541 if (getClassID() == clsidSnapshotMachine) 6544 VBoxClsID clsid = getClassID(); 6545 if (clsid == clsidSnapshotMachine) 6542 6546 { 6543 6547 // wrap another error message around the "cannot find hard disk" set by findHardDisk … … 6630 6634 rc = medium->attachTo(mData->mUuid); 6631 6635 } 6636 6632 6637 if (FAILED(rc)) 6633 6638 break; 6634 6639 6635 /* back up mMediaData to let registeredInit() properly rollback on failure6640 /* back up mMediaData to let registeredInit() properly rollback on failure 6636 6641 * (= limited accessibility) */ 6637 6638 6642 mMediaData.backup(); 6639 6643 mMediaData->mAttachments.push_back(pAttachment); … … 6654 6658 bool aSetError /* = false */) 6655 6659 { 6656 AutoReadLock chlock( snapshotsTreeLockHandle()COMMA_LOCKVAL_SRC_POS);6660 AutoReadLock chlock(this COMMA_LOCKVAL_SRC_POS); 6657 6661 6658 6662 if (!mData->mFirstSnapshot) … … 6694 6698 AssertReturn(aName, E_INVALIDARG); 6695 6699 6696 AutoReadLock chlock( snapshotsTreeLockHandle()COMMA_LOCKVAL_SRC_POS);6700 AutoReadLock chlock(this COMMA_LOCKVAL_SRC_POS); 6697 6701 6698 6702 if (!mData->mFirstSnapshot) … … 8280 8284 * @note Locks objects for writing! 8281 8285 */ 8282 void Machine::rollback 8286 void Machine::rollback(bool aNotify) 8283 8287 { 8284 8288 AutoCaller autoCaller(this); … … 8293 8297 if (aNotify && mHWData.isBackedUp()) 8294 8298 { 8295 if (mHWData->mSharedFolders.size() != 8296 mHWData.backedUpData()->mSharedFolders.size()) 8299 if (mHWData->mSharedFolders.size() != mHWData.backedUpData()->mSharedFolders.size()) 8297 8300 sharedFoldersChanged = true; 8298 8301 else 8299 8302 { 8300 for (HWData::SharedFolderList::iterator rit = 8301 mHWData->mSharedFolders.begin(); 8303 for (HWData::SharedFolderList::iterator rit = mHWData->mSharedFolders.begin(); 8302 8304 rit != mHWData->mSharedFolders.end() && !sharedFoldersChanged; 8303 8305 ++rit) 8304 8306 { 8305 for (HWData::SharedFolderList::iterator cit = 8306 mHWData.backedUpData()->mSharedFolders.begin(); 8307 for (HWData::SharedFolderList::iterator cit = mHWData.backedUpData()->mSharedFolders.begin(); 8307 8308 cit != mHWData.backedUpData()->mSharedFolders.end(); 8308 8309 ++cit) 8309 8310 { 8310 if ((*cit)->getName() != (*rit)->getName() || 8311 (*cit)->getHostPath() != (*rit)->getHostPath()) 8311 if ( (*cit)->getName() != (*rit)->getName() 8312 || (*cit)->getHostPath() != (*rit)->getHostPath() 8313 ) 8312 8314 { 8313 8315 sharedFoldersChanged = true; … … 8328 8330 while (it != mStorageControllers->end()) 8329 8331 { 8330 if (std::find (backedList->begin(), backedList->end(), *it ) == 8331 backedList->end()) 8332 if ( std::find(backedList->begin(), backedList->end(), *it) 8333 == backedList->end() 8334 ) 8332 8335 { 8333 8336 (*it)->uninit(); … … 8359 8362 8360 8363 /* check for changes in child objects */ 8361 8362 8364 bool vrdpChanged = false, usbChanged = false; 8363 8365 8364 ComPtr<INetworkAdapter> networkAdapters [RT_ELEMENTS(mNetworkAdapters)];8365 ComPtr<ISerialPort> serialPorts [RT_ELEMENTS(mSerialPorts)];8366 ComPtr<IParallelPort> parallelPorts [RT_ELEMENTS(mParallelPorts)];8366 ComPtr<INetworkAdapter> networkAdapters[RT_ELEMENTS(mNetworkAdapters)]; 8367 ComPtr<ISerialPort> serialPorts[RT_ELEMENTS(mSerialPorts)]; 8368 ComPtr<IParallelPort> parallelPorts[RT_ELEMENTS(mParallelPorts)]; 8367 8369 8368 8370 if (mBIOSSettings) … … 8380 8382 usbChanged = mUSBController->rollback(); 8381 8383 8382 for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); slot++)8383 if (mNetworkAdapters 8384 if (mNetworkAdapters 8385 networkAdapters [slot] = mNetworkAdapters[slot];8386 8387 for (ULONG slot = 0; slot < RT_ELEMENTS (mSerialPorts); slot++)8388 if (mSerialPorts 8389 if (mSerialPorts 8390 serialPorts [slot] = mSerialPorts[slot];8391 8392 for (ULONG slot = 0; slot < RT_ELEMENTS (mParallelPorts); slot++)8393 if (mParallelPorts 8394 if (mParallelPorts 8395 parallelPorts [slot] = mParallelPorts[slot];8384 for (ULONG slot = 0; slot < RT_ELEMENTS(mNetworkAdapters); slot++) 8385 if (mNetworkAdapters[slot]) 8386 if (mNetworkAdapters[slot]->rollback()) 8387 networkAdapters[slot] = mNetworkAdapters[slot]; 8388 8389 for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); slot++) 8390 if (mSerialPorts[slot]) 8391 if (mSerialPorts[slot]->rollback()) 8392 serialPorts[slot] = mSerialPorts[slot]; 8393 8394 for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); slot++) 8395 if (mParallelPorts[slot]) 8396 if (mParallelPorts[slot]->rollback()) 8397 parallelPorts[slot] = mParallelPorts[slot]; 8396 8398 8397 8399 if (aNotify) … … 8410 8412 that->onUSBControllerChange(); 8411 8413 8412 for (ULONG slot = 0; slot < RT_ELEMENTS 8413 if (networkAdapters 8414 that->onNetworkAdapterChange (networkAdapters[slot], FALSE);8415 for (ULONG slot = 0; slot < RT_ELEMENTS 8416 if (serialPorts 8417 that->onSerialPortChange (serialPorts[slot]);8418 for (ULONG slot = 0; slot < RT_ELEMENTS 8419 if (parallelPorts 8420 that->onParallelPortChange (parallelPorts[slot]);8414 for (ULONG slot = 0; slot < RT_ELEMENTS(networkAdapters); slot ++) 8415 if (networkAdapters[slot]) 8416 that->onNetworkAdapterChange(networkAdapters[slot], FALSE); 8417 for (ULONG slot = 0; slot < RT_ELEMENTS(serialPorts); slot ++) 8418 if (serialPorts[slot]) 8419 that->onSerialPortChange(serialPorts[slot]); 8420 for (ULONG slot = 0; slot < RT_ELEMENTS(parallelPorts); slot ++) 8421 if (parallelPorts[slot]) 8422 that->onParallelPortChange(parallelPorts[slot]); 8421 8423 8422 8424 if (storageChanged) -
trunk/src/VBox/Main/MediumImpl.cpp
r25907 r25930 2732 2732 m->numCreateDiffTasks); 2733 2733 2734 BackRefList::iterator it = 2735 std::find_if(m->backRefs.begin(),m->backRefs.end(),2736 BackRef::EqualsTo(aMachineId));2734 BackRefList::iterator it = std::find_if(m->backRefs.begin(), 2735 m->backRefs.end(), 2736 BackRef::EqualsTo(aMachineId)); 2737 2737 if (it == m->backRefs.end()) 2738 2738 { … … 2765 2765 2766 2766 if (idOldSnapshot == aSnapshotId) 2767 { 2768 #ifdef DEBUG 2769 dumpBackRefs(); 2770 #endif 2767 2771 return setError(E_FAIL, 2768 tr("Cannot attach medium '%s' {%RTuuid} from snapshot '%RTuuid': medium is already in use by snapshot '%RTuuid'"),2772 tr("Cannot attach medium '%s' {%RTuuid} from snapshot '%RTuuid': medium is already in use by this snapshot!"), 2769 2773 m->strLocationFull.raw(), 2770 2774 m->id.raw(), 2771 2775 aSnapshotId.raw(), 2772 2776 idOldSnapshot.raw()); 2777 } 2773 2778 } 2774 2779 … … 3177 3182 * if no real merge is necessary). 3178 3183 * 3179 * @note Locks getTreeLock() for reading. Locks this object, aTarget and all3180 * intermediate hard disksfor writing.3184 * @note Caller must hold media tree lock for writing. This locks this object 3185 * and every medium object on the merge chain for writing. 3181 3186 */ 3182 3187 HRESULT Medium::prepareDiscard(MergeChain * &aChain) … … 3189 3194 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3190 3195 3191 /* we access mParent & children() */ 3192 AutoReadLock treeLock(m->pVirtualBox->getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 3196 Assert(m->pVirtualBox->getMediaTreeLockHandle().isWriteLockOnCurrentThread()); 3193 3197 3194 3198 AssertReturn(m->type == MediumType_Normal, E_FAIL); -
trunk/src/VBox/Main/SnapshotImpl.cpp
r25907 r25930 448 448 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 449 449 450 AutoReadLock alock(m->pMachine->snapshotsTreeLockHandle() COMMA_LOCKVAL_SRC_POS);451 AutoReadLock block(this->lockHandle()COMMA_LOCKVAL_SRC_POS);450 // snapshots tree is protected by machine lock 451 AutoReadLock alock(m->pMachine COMMA_LOCKVAL_SRC_POS); 452 452 453 453 SafeIfaceArray<ISnapshot> collection(m->llChildren); … … 491 491 AssertComRC(autoCaller.rc()); 492 492 493 AutoReadLock treeLock(m->pMachine->snapshotsTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 493 // snapshots tree is protected by machine lock 494 AutoReadLock alock(m->pMachine COMMA_LOCKVAL_SRC_POS); 495 494 496 return (ULONG)m->llChildren.size(); 495 497 } … … 526 528 AssertComRC(autoCaller.rc()); 527 529 528 AutoReadLock treeLock(m->pMachine->snapshotsTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 530 // snapshots tree is protected by machine lock 531 AutoReadLock alock(m->pMachine COMMA_LOCKVAL_SRC_POS); 532 529 533 return getAllChildrenCountImpl(); 530 534 } … … 686 690 AssertComRC(autoCaller.rc()); 687 691 688 AutoWriteLock chLock(m->pMachine->snapshotsTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 692 // snapshots tree is protected by machine lock 693 AutoWriteLock alock(m->pMachine COMMA_LOCKVAL_SRC_POS); 694 689 695 // call the implementation under the tree lock 690 696 updateSavedStatePathsImpl(aOldPath, aNewPath); … … 692 698 693 699 /** 694 * Internal implementation for Snapshot::saveSnapshot (below). 700 * Internal implementation for Snapshot::saveSnapshot (below). Caller has 701 * requested the snapshots tree (machine) lock. 702 * 695 703 * @param aNode 696 704 * @param aAttrsOnly … … 753 761 HRESULT Snapshot::saveSnapshot(settings::Snapshot &data, bool aAttrsOnly) 754 762 { 755 AutoWriteLock listLock(m->pMachine->snapshotsTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 763 // snapshots tree is protected by machine lock 764 AutoReadLock alock(m->pMachine COMMA_LOCKVAL_SRC_POS); 756 765 757 766 return saveSnapshotImpl(data, aAttrsOnly); … … 966 975 967 976 unconst(mBIOSSettings).createObject(); 968 mBIOSSettings->init 977 mBIOSSettings->init(this); 969 978 970 979 #ifdef VBOX_WITH_VRDP 971 980 unconst(mVRDPServer).createObject(); 972 mVRDPServer->init 981 mVRDPServer->init(this); 973 982 #endif 974 983 975 984 unconst(mAudioAdapter).createObject(); 976 mAudioAdapter->init 985 mAudioAdapter->init(this); 977 986 978 987 unconst(mUSBController).createObject(); 979 mUSBController->init 980 981 for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); slot++)982 { 983 unconst(mNetworkAdapters 984 mNetworkAdapters [slot]->init(this, slot);985 } 986 987 for (ULONG slot = 0; slot < RT_ELEMENTS (mSerialPorts); slot++)988 { 989 unconst(mSerialPorts 990 mSerialPorts [slot]->init(this, slot);991 } 992 993 for (ULONG slot = 0; slot < RT_ELEMENTS (mParallelPorts); slot++)994 { 995 unconst(mParallelPorts 996 mParallelPorts [slot]->init(this, slot);988 mUSBController->init(this); 989 990 for (ULONG slot = 0; slot < RT_ELEMENTS(mNetworkAdapters); slot++) 991 { 992 unconst(mNetworkAdapters[slot]).createObject(); 993 mNetworkAdapters[slot]->init(this, slot); 994 } 995 996 for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); slot++) 997 { 998 unconst(mSerialPorts[slot]).createObject(); 999 mSerialPorts[slot]->init(this, slot); 1000 } 1001 1002 for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); slot++) 1003 { 1004 unconst(mParallelPorts[slot]).createObject(); 1005 mParallelPorts[slot]->init(this, slot); 997 1006 } 998 1007 … … 1939 1948 ComAssertRet(!Global::IsOnlineOrTransient(mData->mMachineState), E_FAIL); 1940 1949 1941 AutoWriteLock treeLock(snapshotsTreeLockHandle() COMMA_LOCKVAL_SRC_POS);1942 1943 1950 ComObjPtr<Snapshot> pSnapshot; 1944 1951 HRESULT rc = findSnapshot(id, pSnapshot, true /* aSetError */); … … 2113 2120 /* Locking order: */ 2114 2121 AutoMultiWriteLock3 alock(this->lockHandle(), 2115 this->snapshotsTreeLockHandle(),2116 aTask.pSnapshot->lockHandle()2122 aTask.pSnapshot->lockHandle(), 2123 &mParent->getMediaTreeLockHandle() 2117 2124 COMMA_LOCKVAL_SRC_POS); 2118 2125 -
trunk/src/VBox/Main/VirtualBoxBase.cpp
r25860 r25930 1013 1013 * Do some checks to avoid endless loops when the user is forgetful */ 1014 1014 -- count; 1015 Assert 1015 Assert(count == mDependentChildren.size()); 1016 1016 if (count != mDependentChildren.size()) 1017 1017 mDependentChildren.erase (it); -
trunk/src/VBox/Main/glue/AutoLock.cpp
r25906 r25930 75 75 { LOCKCLASS_LISTOFMACHINES, "4-LISTOFMACHINES" }, 76 76 { LOCKCLASS_MACHINEOBJECT, "5-MACHINEOBJECT" }, 77 { LOCKCLASS_LISTOFSNAPSHOTS, "6-LISTOFSNAPSHOTS" }, 78 { LOCKCLASS_SNAPSHOTOBJECT, "7-SNAPSHOTOBJECT" }, 79 { LOCKCLASS_LISTOFMEDIA, "8-LISTOFMEDIA" }, 80 { LOCKCLASS_LISTOFOTHEROBJECTS, "9-LISTOFOTHEROBJECTS" }, 81 { LOCKCLASS_OTHEROBJECT, "10-OTHEROBJECT" }, 82 { LOCKCLASS_USBLIST, "11-USBLIST" }, 83 { LOCKCLASS_PROGRESSLIST, "12-PROGRESSLIST" }, 84 { LOCKCLASS_OBJECTSTATE, "13-OBJECTSTATE" } 77 { LOCKCLASS_SNAPSHOTOBJECT, "6-SNAPSHOTOBJECT" }, 78 { LOCKCLASS_LISTOFMEDIA, "7-LISTOFMEDIA" }, 79 { LOCKCLASS_LISTOFOTHEROBJECTS, "8-LISTOFOTHEROBJECTS" }, 80 { LOCKCLASS_OTHEROBJECT, "9-OTHEROBJECT" }, 81 { LOCKCLASS_USBLIST, "10-USBLIST" }, 82 { LOCKCLASS_PROGRESSLIST, "11-PROGRESSLIST" }, 83 { LOCKCLASS_OBJECTSTATE, "12-OBJECTSTATE" } 85 84 }; 86 85 -
trunk/src/VBox/Main/include/MachineImpl.h
r25903 r25930 188 188 ComObjPtr<Snapshot> mFirstSnapshot; 189 189 ComObjPtr<Snapshot> mCurrentSnapshot; 190 191 // protectes the snapshots tree of this machine192 RWLockHandle mSnapshotsTreeLockHandle;193 190 }; 194 191 … … 800 797 static const wchar_t *getComponentName() { return L"Machine"; } 801 798 802 /**803 * Returns the handle of the snapshots tree lock. This lock is804 * machine-specific because there is one snapshots tree per805 * IMachine; the lock protects the "first snapshot" member in806 * IMachine and all the children and parent links in snapshot807 * objects pointed to therefrom.808 *809 * Locking order:810 * a) object lock of the machine;811 * b) snapshots tree lock of the machine;812 * c) individual snapshot object locks in parent->child order,813 * if needed; they are _not_ needed for the tree itself814 * (as defined above).815 */816 RWLockHandle* snapshotsTreeLockHandle() const817 {818 return &mData->mSnapshotsTreeLockHandle;819 }820 821 799 protected: 822 800 … … 932 910 // so they cannot be a part of HWData 933 911 934 const ComObjPtr<VRDPServer> mVRDPServer; 935 const ComObjPtr<SerialPort> 936 mSerialPorts [SchemaDefs::SerialPortCount]; 937 const ComObjPtr<ParallelPort> 938 mParallelPorts [SchemaDefs::ParallelPortCount]; 939 const ComObjPtr<AudioAdapter> mAudioAdapter; 940 const ComObjPtr<USBController> mUSBController; 941 const ComObjPtr<BIOSSettings> mBIOSSettings; 942 const ComObjPtr<NetworkAdapter> 943 mNetworkAdapters [SchemaDefs::NetworkAdapterCount]; 912 const ComObjPtr<VRDPServer> mVRDPServer; 913 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount]; 914 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount]; 915 const ComObjPtr<AudioAdapter> mAudioAdapter; 916 const ComObjPtr<USBController> mUSBController; 917 const ComObjPtr<BIOSSettings> mBIOSSettings; 918 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount]; 944 919 945 920 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
Note:
See TracChangeset
for help on using the changeset viewer.