Changeset 24160 in vbox
- Timestamp:
- Oct 29, 2009 2:25:53 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 54099
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r24155 r24160 2557 2557 2558 2558 mMediaData.backup(); 2559 2560 /* if a cd/dvd was attached to the atachment then better update it */2561 do2562 {2563 ComObjPtr<Medium> medium;2564 AutoWriteLock attLock(pAttach);2565 pAttach->updateMedium(medium, false /* aImplicit */, mData->mUuid);2566 } while (0);2567 2559 2568 2560 /* we cannot use erase (it) below because backup() above will create … … 2719 2711 if (!medium.isNull()) 2720 2712 medium->attachTo(mData->mUuid); 2721 pAttach->updateMedium(medium, false /* aImplicit */ , mData->mUuid);2713 pAttach->updateMedium(medium, false /* aImplicit */); 2722 2714 } 2723 2715 … … 7015 7007 MediumAttachment *pAttach = *it; 7016 7008 7017 if (pAttach->type() == DeviceType_HardDisk) 7009 pAttach->commit(); 7010 7011 Medium* pMedium = pAttach->medium(); 7012 7013 /** @todo convert all this Machine-based voodoo to MediumAttachment 7014 * based commit logic. */ 7015 if (pAttach->isImplicit()) 7018 7016 { 7019 pAttach->commit(); 7020 7021 Medium* pMedium = pAttach->medium(); 7022 7023 /** @todo convert all this Machine-based voodoo to MediumAttachment 7024 * based commit logic. */ 7025 if (pAttach->isImplicit()) 7017 /* convert implicit attachment to normal */ 7018 pAttach->setImplicit(false); 7019 7020 if (aOnline && pMedium && pAttach->type() == DeviceType_HardDisk) 7026 7021 { 7027 /* convert implicit attachment to normal */ 7028 pAttach->setImplicit(false); 7029 7030 if (aOnline) 7022 rc = pMedium->LockWrite(NULL); 7023 AssertComRC(rc); 7024 7025 mData->mSession.mLockedMedia.push_back( 7026 Data::Session::LockedMedia::value_type( 7027 ComPtr<IMedium>(pMedium), true)); 7028 7029 /* also, relock the old hard disk which is a base for the 7030 * new diff for reading if the VM is online */ 7031 7032 ComObjPtr<Medium> parent = pMedium->parent(); 7033 /* make the relock atomic */ 7034 AutoWriteLock parentLock (parent); 7035 rc = parent->UnlockWrite(NULL); 7036 AssertComRC(rc); 7037 rc = parent->LockRead(NULL); 7038 AssertComRC(rc); 7039 7040 /* XXX actually we should replace the old entry in that 7041 * vector (write lock => read lock) but this would take 7042 * some effort. So lets just ignore the error code in 7043 * SessionMachine::unlockMedia(). */ 7044 mData->mSession.mLockedMedia.push_back( 7045 Data::Session::LockedMedia::value_type ( 7046 ComPtr<IMedium>(parent), false)); 7047 } 7048 7049 continue; 7050 } 7051 7052 if (pMedium) 7053 { 7054 /* was this medium attached before? */ 7055 for (MediaData::AttachmentList::iterator oldIt = oldAtts.begin(); 7056 oldIt != oldAtts.end(); 7057 ++oldIt) 7058 { 7059 MediumAttachment *pOldAttach = *it; 7060 if (pOldAttach->medium().equalsTo(pMedium)) 7031 7061 { 7032 rc = pMedium->LockWrite(NULL); 7033 AssertComRC(rc); 7034 7035 mData->mSession.mLockedMedia.push_back( 7036 Data::Session::LockedMedia::value_type( 7037 ComPtr<IMedium>(pMedium), true)); 7038 7039 /* also, relock the old hard disk which is a base for the 7040 * new diff for reading if the VM is online */ 7041 7042 ComObjPtr<Medium> parent = pMedium->parent(); 7043 /* make the relock atomic */ 7044 AutoWriteLock parentLock (parent); 7045 rc = parent->UnlockWrite(NULL); 7046 AssertComRC(rc); 7047 rc = parent->LockRead(NULL); 7048 AssertComRC(rc); 7049 7050 /* XXX actually we should replace the old entry in that 7051 * vector (write lock => read lock) but this would take 7052 * some effort. So lets just ignore the error code in 7053 * SessionMachine::unlockMedia(). */ 7054 mData->mSession.mLockedMedia.push_back( 7055 Data::Session::LockedMedia::value_type ( 7056 ComPtr<IMedium>(parent), false)); 7057 } 7058 7059 continue; 7060 } 7061 7062 if (pMedium) 7063 { 7064 /* was this hard disk attached before? */ 7065 for (MediaData::AttachmentList::iterator oldIt = oldAtts.begin(); 7066 oldIt != oldAtts.end(); 7067 ++oldIt) 7068 { 7069 MediumAttachment *pOldAttach = *it; 7070 if (pOldAttach->medium().equalsTo(pMedium)) 7071 { 7072 /* yes: remove from old to avoid de-association */ 7073 oldAtts.erase(oldIt); 7074 break; 7075 } 7062 /* yes: remove from old to avoid de-association */ 7063 oldAtts.erase(oldIt); 7064 break; 7076 7065 } 7077 7066 } … … 7087 7076 MediumAttachment *pAttach = *it; 7088 7077 7089 if (pAttach->type() == DeviceType_HardDisk) 7078 Medium* pMedium = pAttach->medium(); 7079 7080 if (pMedium) 7090 7081 { 7091 Medium* pMedium = pAttach->medium(); 7092 7093 if (pMedium) 7082 /* now de-associate from the current machine state */ 7083 rc = pMedium->detachFrom(mData->mUuid); 7084 AssertComRC(rc); 7085 7086 if (aOnline && pAttach->type() == DeviceType_HardDisk) 7094 7087 { 7095 /* now de-associate from the current machine state */ 7096 rc = pMedium->detachFrom(mData->mUuid); 7097 AssertComRC(rc); 7098 7099 if (aOnline) 7100 { 7101 /* unlock since not used anymore */ 7102 MediumState_T state; 7103 rc = pMedium->UnlockWrite(&state); 7104 /* the disk may be alredy relocked for reading above */ 7105 Assert (SUCCEEDED(rc) || state == MediumState_LockedRead); 7106 } 7088 /* unlock since not used anymore */ 7089 MediumState_T state; 7090 rc = pMedium->UnlockWrite(&state); 7091 /* the disk may be alredy relocked for reading above */ 7092 Assert (SUCCEEDED(rc) || state == MediumState_LockedRead); 7107 7093 } 7108 7094 } -
trunk/src/VBox/Main/include/MediumAttachmentImpl.h
r24155 r24160 96 96 97 97 /** Must be called from under this object's write lock. */ 98 void updateMedium(const ComObjPtr<Medium> &aMedium, 99 bool aImplicit, 100 const Guid &aMachineId = Guid::Empty) 98 void updateMedium(const ComObjPtr<Medium> &aMedium, bool aImplicit) 101 99 { 102 100 m.backup(); 103 if (m->medium && aMachineId)104 m->medium->detachFrom(aMachineId);105 101 m->medium = aMedium; 106 102 m->implicit = aImplicit;
Note:
See TracChangeset
for help on using the changeset viewer.