Changeset 61137 in vbox
- Timestamp:
- May 23, 2016 3:55:49 PM (9 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/idl/VirtualBox.xidl
r61042 r61137 14583 14583 </attribute> 14584 14584 14585 <attribute name="type" type="MediumType" >14585 <attribute name="type" type="MediumType" wrap-hint-server="passcaller"> 14586 14586 <desc> 14587 14587 Type (role) of this medium. … … 14647 14647 </attribute> 14648 14648 14649 <attribute name="readOnly" type="boolean" readonly="yes" >14649 <attribute name="readOnly" type="boolean" readonly="yes" wrap-hint-server="passcaller"> 14650 14650 <desc> 14651 14651 Returns @c true if this medium is read-only and @c false otherwise. … … 15201 15201 <!-- diff methods --> 15202 15202 15203 <method name="createDiffStorage" >15203 <method name="createDiffStorage" wrap-hint-server="passcaller"> 15204 15204 <desc> 15205 15205 Starts creating an empty differencing storage unit based on this … … 15509 15509 </method> 15510 15510 15511 <method name="reset" >15511 <method name="reset" wrap-hint-server="passcaller"> 15512 15512 <desc> 15513 15513 Starts erasing the contents of this differencing medium. -
trunk/src/VBox/Main/include/MediumImpl.h
r60627 r61137 237 237 HRESULT getFormat(com::Utf8Str &aFormat); 238 238 HRESULT getMediumFormat(ComPtr<IMediumFormat> &aMediumFormat); 239 HRESULT getType( MediumType_T *aType);240 HRESULT setType( MediumType_T aType);239 HRESULT getType(AutoCaller &autoCaller, MediumType_T *aType); 240 HRESULT setType(AutoCaller &autoCaller, MediumType_T aType); 241 241 HRESULT getAllowedTypes(std::vector<MediumType_T> &aAllowedTypes); 242 242 HRESULT getParent(AutoCaller &autoCaller, ComPtr<IMedium> &aParent); 243 243 HRESULT getChildren(AutoCaller &autoCaller, std::vector<ComPtr<IMedium> > &aChildren); 244 244 HRESULT getBase(AutoCaller &autoCaller, ComPtr<IMedium> &aBase); 245 HRESULT getReadOnly( BOOL *aReadOnly);245 HRESULT getReadOnly(AutoCaller &autoCaller, BOOL *aReadOnly); 246 246 HRESULT getLogicalSize(LONG64 *aLogicalSize); 247 247 HRESULT getAutoReset(BOOL *aAutoReset); … … 276 276 ComPtr<IProgress> &aProgress); 277 277 HRESULT deleteStorage(ComPtr<IProgress> &aProgress); 278 HRESULT createDiffStorage(const ComPtr<IMedium> &aTarget, 278 HRESULT createDiffStorage(AutoCaller &autoCaller, 279 const ComPtr<IMedium> &aTarget, 279 280 const std::vector<MediumVariant_T> &aVariant, 280 281 ComPtr<IProgress> &aProgress); … … 293 294 HRESULT resize(LONG64 aLogicalSize, 294 295 ComPtr<IProgress> &aProgress); 295 HRESULT reset( ComPtr<IProgress> &aProgress);296 HRESULT reset(AutoCaller &autoCaller, ComPtr<IProgress> &aProgress); 296 297 HRESULT changeEncryption(const com::Utf8Str &aCurrentPassword, const com::Utf8Str &aCipher, 297 298 const com::Utf8Str &aNewPassword, const com::Utf8Str &aNewPasswordId, -
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r61009 r61137 1524 1524 /* It is possible that some previous/concurrent uninit has already cleared 1525 1525 * the pVirtualBox reference, and in this case we don't need to continue. 1526 * Normally this would be handled through the AutoUninitSpan magic, 1527 * however this cannot be done at this point as the media tree must be 1528 * locked before reaching the AutoUninitSpan, otherwise deadlocks can 1529 * happen due to*/ 1526 * Normally this would be handled through the AutoUninitSpan magic, however 1527 * this cannot be done at this point as the media tree must be locked 1528 * before reaching the AutoUninitSpan, otherwise deadlocks can happen. 1529 * 1530 * NOTE: The tree lock is higher priority than the medium caller and medium 1531 * object locks, i.e. the medium caller may have to be released and be 1532 * re-acquired in the right place later. See Medium::getParent() for sample 1533 * code how to do this safely. */ 1530 1534 ComObjPtr<VirtualBox> pVirtualBox(m->pVirtualBox); 1531 1535 if (!pVirtualBox) … … 1731 1735 } 1732 1736 1733 HRESULT Medium::getType(MediumType_T *aType) 1734 { 1737 HRESULT Medium::getType(AutoCaller &autoCaller, MediumType_T *aType) 1738 { 1739 NOREF(autoCaller); 1735 1740 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1736 1741 … … 1740 1745 } 1741 1746 1742 HRESULT Medium::setType(MediumType_T aType) 1743 { 1744 // we access mParent and members 1745 AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 1747 HRESULT Medium::setType(AutoCaller &autoCaller, MediumType_T aType) 1748 { 1749 autoCaller.release(); 1750 1751 /* It is possible that some previous/concurrent uninit has already cleared 1752 * the pVirtualBox reference, see #uninit(). */ 1753 ComObjPtr<VirtualBox> pVirtualBox(m->pVirtualBox); 1754 1755 // we access m->pParent 1756 AutoReadLock treeLock(!pVirtualBox.isNull() ? &pVirtualBox->i_getMediaTreeLockHandle() : NULL COMMA_LOCKVAL_SRC_POS); 1757 1758 autoCaller.add(); 1759 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1760 1746 1761 AutoWriteLock mlock(this COMMA_LOCKVAL_SRC_POS); 1747 1762 … … 1885 1900 ComObjPtr<VirtualBox> pVirtualBox(m->pVirtualBox); 1886 1901 1887 /* we access m Parent */1902 /* we access m->pParent */ 1888 1903 AutoReadLock treeLock(!pVirtualBox.isNull() ? &pVirtualBox->i_getMediaTreeLockHandle() : NULL COMMA_LOCKVAL_SRC_POS); 1889 1904 … … 1928 1943 } 1929 1944 1930 HRESULT Medium::getReadOnly(BOOL *aReadOnly) 1931 { 1945 HRESULT Medium::getReadOnly(AutoCaller &autoCaller, BOOL *aReadOnly) 1946 { 1947 autoCaller.release(); 1948 1932 1949 /* isReadOnly() will do locking */ 1933 1950 *aReadOnly = i_isReadOnly(); … … 2587 2604 } 2588 2605 2589 HRESULT Medium::createDiffStorage(const ComPtr<IMedium> &aTarget, 2606 HRESULT Medium::createDiffStorage(AutoCaller &autoCaller, 2607 const ComPtr<IMedium> &aTarget, 2590 2608 const std::vector<MediumVariant_T> &aVariant, 2591 2609 ComPtr<IProgress> &aProgress) 2592 2610 { 2611 /** @todo r=klaus The code below needs to be double checked with regard 2612 * to lock order violations, it probably causes lock order issues related 2613 * to the AutoCaller usage. */ 2593 2614 IMedium *aT = aTarget; 2594 2615 ComObjPtr<Medium> diff = static_cast<Medium*>(aT); 2595 2616 2596 // locking: we need the tree lock first because we access parent pointers 2597 AutoMultiWriteLock3 alock(&m->pVirtualBox->i_getMediaTreeLockHandle(), 2598 this->lockHandle(), diff->lockHandle() COMMA_LOCKVAL_SRC_POS); 2617 autoCaller.release(); 2618 2619 /* It is possible that some previous/concurrent uninit has already cleared 2620 * the pVirtualBox reference, see #uninit(). */ 2621 ComObjPtr<VirtualBox> pVirtualBox(m->pVirtualBox); 2622 2623 // we access m->pParent 2624 AutoReadLock treeLock(!pVirtualBox.isNull() ? &pVirtualBox->i_getMediaTreeLockHandle() : NULL COMMA_LOCKVAL_SRC_POS); 2625 2626 autoCaller.add(); 2627 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2628 2629 AutoMultiWriteLock2 alock(this->lockHandle(), diff->lockHandle() COMMA_LOCKVAL_SRC_POS); 2599 2630 2600 2631 if (m->type == MediumType_Writethrough) … … 2614 2645 MediumLockList *pMediumLockList(new MediumLockList()); 2615 2646 alock.release(); 2647 treeLock.release(); 2616 2648 HRESULT rc = diff->i_createMediumLockList(true /* fFailIfInaccessible */, 2617 2649 diff /* pToLockWrite */, … … 2619 2651 this, 2620 2652 *pMediumLockList); 2653 treeLock.acquire(); 2621 2654 alock.acquire(); 2622 2655 if (FAILED(rc)) … … 2627 2660 2628 2661 alock.release(); 2662 treeLock.release(); 2629 2663 rc = pMediumLockList->Lock(); 2664 treeLock.acquire(); 2630 2665 alock.acquire(); 2631 2666 if (FAILED(rc)) … … 2643 2678 diff->m->llRegistryIDs.push_back(parentMachineRegistry); 2644 2679 alock.release(); 2680 treeLock.release(); 2645 2681 diff->i_markRegistriesModified(); 2682 treeLock.acquire(); 2646 2683 alock.acquire(); 2647 2684 } 2648 2685 2649 2686 alock.release(); 2687 treeLock.release(); 2650 2688 2651 2689 ComObjPtr<Progress> pProgress; … … 2673 2711 { 2674 2712 2713 /** @todo r=klaus The code below needs to be double checked with regard 2714 * to lock order violations, it probably causes lock order issues related 2715 * to the AutoCaller usage. */ 2675 2716 IMedium *aT = aTarget; 2676 2717 … … 2717 2758 ComPtr<IProgress> &aProgress) 2718 2759 { 2760 /** @todo r=klaus The code below needs to be double checked with regard 2761 * to lock order violations, it probably causes lock order issues related 2762 * to the AutoCaller usage. */ 2719 2763 ComAssertRet(aTarget != this, E_INVALIDARG); 2720 2764 … … 3010 3054 } 3011 3055 3012 HRESULT Medium::reset( ComPtr<IProgress> &aProgress)3056 HRESULT Medium::reset(AutoCaller &autoCaller, ComPtr<IProgress> &aProgress) 3013 3057 { 3014 3058 HRESULT rc = S_OK; … … 3018 3062 try 3019 3063 { 3064 autoCaller.release(); 3065 3066 /* It is possible that some previous/concurrent uninit has already 3067 * cleared the pVirtualBox reference, see #uninit(). */ 3068 ComObjPtr<VirtualBox> pVirtualBox(m->pVirtualBox); 3069 3020 3070 /* canClose() needs the tree lock */ 3021 AutoMultiWriteLock2 multilock( &m->pVirtualBox->i_getMediaTreeLockHandle(),3071 AutoMultiWriteLock2 multilock(!pVirtualBox.isNull() ? &pVirtualBox->i_getMediaTreeLockHandle() : NULL, 3022 3072 this->lockHandle() 3023 3073 COMMA_LOCKVAL_SRC_POS); 3074 3075 autoCaller.add(); 3076 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3024 3077 3025 3078 LogFlowThisFunc(("ENTER for medium %s\n", m->strLocationFull.c_str())); … … 4034 4087 return pBase; 4035 4088 4036 /* we access m Parent */4089 /* we access m->pParent */ 4037 4090 AutoReadLock treeLock(pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 4038 4091 … … 4077 4130 return 1; 4078 4131 4079 /* we access m Parent */4132 /* we access m->pParent */ 4080 4133 AutoReadLock treeLock(pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 4081 4134 … … 4103 4156 bool Medium::i_isReadOnly() 4104 4157 { 4158 /* it is possible that some previous/concurrent uninit has already cleared 4159 * the pVirtualBox reference, and in this case we don't need to continue */ 4160 ComObjPtr<VirtualBox> pVirtualBox(m->pVirtualBox); 4161 if (!pVirtualBox) 4162 return false; 4163 4164 /* we access children */ 4165 AutoReadLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 4166 4105 4167 AutoCaller autoCaller(this); 4106 4168 AssertComRCReturn(autoCaller.rc(), false); 4107 4108 /* we access children */4109 AutoReadLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);4110 4169 4111 4170 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); … … 4234 4293 const Utf8Str &strHardDiskFolder) 4235 4294 { 4295 /* we access m->pParent */ 4296 AutoReadLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 4297 4236 4298 AutoCaller autoCaller(this); 4237 4299 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 4238 4239 /* we access mParent */4240 AutoReadLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);4241 4300 4242 4301 i_saveSettingsOne(data, strHardDiskFolder); … … 4283 4342 MediumLockList &mediumLockList) 4284 4343 { 4285 Assert(!m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread()); 4344 /** @todo r=klaus this needs to be reworked, as the code below uses 4345 * i_getParent without holding the tree lock, and changing this is 4346 * a significant amount of effort. */ 4347 Assert(m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread()); 4286 4348 Assert(!isWriteLockOnCurrentThread()); 4287 4349 … … 4651 4713 bool aWait) 4652 4714 { 4715 /** @todo r=klaus The code below needs to be double checked with regard 4716 * to lock order violations, it probably causes lock order issues related 4717 * to the AutoCaller usage. */ 4653 4718 AssertReturn(aProgress != NULL || aWait == true, E_FAIL); 4654 4719 … … 4933 4998 bool &fMergeForward) 4934 4999 { 5000 /** @todo r=klaus The code below needs to be double checked with regard 5001 * to lock order violations, it probably causes lock order issues related 5002 * to the AutoCaller usage. Likewise the code using this method seems 5003 * problematic. */ 4935 5004 AssertReturn(pOther != NULL, E_FAIL); 4936 5005 AssertReturn(pOther != this, E_FAIL); … … 5058 5127 MediumLockList * &aMediumLockList) 5059 5128 { 5129 /** @todo r=klaus The code below needs to be double checked with regard 5130 * to lock order violations, it probably causes lock order issues related 5131 * to the AutoCaller usage. Likewise the code using this method seems 5132 * problematic. */ 5060 5133 AssertReturn(pTarget != NULL, E_FAIL); 5061 5134 AssertReturn(pTarget != this, E_FAIL); … … 5563 5636 HRESULT Medium::i_fixParentUuidOfChildren(MediumLockList *pChildrenToReparent) 5564 5637 { 5638 /** @todo r=klaus The code below needs to be double checked with regard 5639 * to lock order violations, it probably causes lock order issues related 5640 * to the AutoCaller usage. Likewise the code using this method seems 5641 * problematic. */ 5565 5642 Assert(!isWriteLockOnCurrentThread()); 5566 5643 Assert(!m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread()); … … 5742 5819 const ComObjPtr<Progress> &aProgress) 5743 5820 { 5821 /** @todo r=klaus The code below needs to be double checked with regard 5822 * to lock order violations, it probably causes lock order issues related 5823 * to the AutoCaller usage. */ 5744 5824 AssertPtrReturn(aFilename, E_INVALIDARG); 5745 5825 AssertReturn(!aFormat.isNull(), E_INVALIDARG); … … 5838 5918 uint32_t idxSrcImageSame, uint32_t idxDstImageSame) 5839 5919 { 5920 /** @todo r=klaus The code below needs to be double checked with regard 5921 * to lock order violations, it probably causes lock order issues related 5922 * to the AutoCaller usage. */ 5840 5923 CheckComArgNotNull(aTarget); 5841 5924 CheckComArgOutPointerValid(aProgress); … … 6033 6116 * @note Caller MUST NOT hold the media tree or medium lock. 6034 6117 * 6035 * @note Locks m Parent for reading. Locks this object for writing.6118 * @note Locks m->pParent for reading. Locks this object for writing. 6036 6119 * 6037 6120 * @param fSetImageId Whether to reset the UUID contained in the image file to the UUID in the medium instance data (see SetIDs()) … … 6342 6425 /* must drop the caller before taking the tree lock */ 6343 6426 autoCaller.release(); 6344 /* we set m Parent & children() */6427 /* we set m->pParent & children() */ 6345 6428 treeLock.acquire(); 6346 6429 autoCaller.add(); … … 6367 6450 /* must drop the caller before taking the tree lock */ 6368 6451 autoCaller.release(); 6369 /* we access m Parent */6452 /* we access m->pParent */ 6370 6453 treeLock.acquire(); 6371 6454 autoCaller.add(); … … 6577 6660 * VirtualBox::i_unregisterMedium() properly save the registry */ 6578 6661 6579 /* we modify m Parent and access children */6662 /* we modify m->pParent and access children */ 6580 6663 Assert(m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread()); 6581 6664 … … 7438 7521 HRESULT Medium::i_taskCreateBaseHandler(Medium::CreateBaseTask &task) 7439 7522 { 7523 /** @todo r=klaus The code below needs to be double checked with regard 7524 * to lock order violations, it probably causes lock order issues related 7525 * to the AutoCaller usage. */ 7440 7526 HRESULT rc = S_OK; 7441 7527 … … 7581 7667 HRESULT Medium::i_taskCreateDiffHandler(Medium::CreateDiffTask &task) 7582 7668 { 7669 /** @todo r=klaus The code below needs to be double checked with regard 7670 * to lock order violations, it probably causes lock order issues related 7671 * to the AutoCaller usage. */ 7583 7672 HRESULT rcTmp = S_OK; 7584 7673 … … 7801 7890 HRESULT Medium::i_taskMergeHandler(Medium::MergeTask &task) 7802 7891 { 7892 /** @todo r=klaus The code below needs to be double checked with regard 7893 * to lock order violations, it probably causes lock order issues related 7894 * to the AutoCaller usage. */ 7803 7895 HRESULT rcTmp = S_OK; 7804 7896 … … 8111 8203 HRESULT Medium::i_taskCloneHandler(Medium::CloneTask &task) 8112 8204 { 8205 /** @todo r=klaus The code below needs to be double checked with regard 8206 * to lock order violations, it probably causes lock order issues related 8207 * to the AutoCaller usage. */ 8113 8208 HRESULT rcTmp = S_OK; 8114 8209 … … 8320 8415 if (SUCCEEDED(mrc) && fCreatingTarget) 8321 8416 { 8322 /* we set m Parent & children() */8417 /* we set m->pParent & children() */ 8323 8418 AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 8324 8419 … … 9049 9144 HRESULT Medium::i_taskImportHandler(Medium::ImportTask &task) 9050 9145 { 9146 /** @todo r=klaus The code below needs to be double checked with regard 9147 * to lock order violations, it probably causes lock order issues related 9148 * to the AutoCaller usage. */ 9051 9149 HRESULT rcTmp = S_OK; 9052 9150 … … 9218 9316 if (SUCCEEDED(mrc) && fCreatingTarget) 9219 9317 { 9220 /* we set m Parent & children() */9318 /* we set m->pParent & children() */ 9221 9319 AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 9222 9320
Note:
See TracChangeset
for help on using the changeset viewer.