Changeset 33140 in vbox for trunk/src/VBox/Main/MachineImpl.cpp
- Timestamp:
- Oct 14, 2010 4:20:15 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r33108 r33140 3327 3327 // if this becomes true then we need to call saveSettings in the end 3328 3328 // @todo r=dj there is no error handling so far... 3329 bool fNeedsGlobalSaveSettings = false; 3329 bool fNeedsMachineSaveSettings = false, 3330 fNeedsGlobalSaveSettings = false; 3330 3331 3331 3332 // request the host lock first, since might be calling Host methods for getting host drives; … … 3671 3672 if (mData->pMachineConfigFile->canHaveOwnMediaRegistry()) 3672 3673 // machine XML is VirtualBox 4.0 or higher: 3673 medium->addRegistry(getId()); // machine UUID 3674 medium->addRegistry(getId(), // machine UUID 3675 &fNeedsMachineSaveSettings); 3674 3676 else 3675 medium->addRegistry(mParent->getGlobalRegistryId()); // VirtualBox global registry UUID 3677 medium->addRegistry(mParent->getGlobalRegistryId(), // VirtualBox global registry UUID 3678 &fNeedsGlobalSaveSettings); 3676 3679 } 3677 3680 … … 3680 3683 mMediaData.backup(); 3681 3684 mMediaData->mAttachments.push_back(attachment); 3685 3686 if (fNeedsMachineSaveSettings) 3687 saveSettings(&fNeedsGlobalSaveSettings, SaveS_Force); 3682 3688 3683 3689 if (fNeedsGlobalSaveSettings) … … 3798 3804 LONG aControllerPort, 3799 3805 LONG aDevice, 3800 I N_BSTR aId,3806 IMedium *aMedium, 3801 3807 BOOL aForce) 3802 3808 { … … 3810 3816 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3811 3817 3812 // we're calling host methods for getting DVD and floppy drives so lock host first 3813 AutoMultiWriteLock2 alock(mParent->host(), this COMMA_LOCKVAL_SRC_POS); 3818 // request the host lock first, since might be calling Host methods for getting host drives; 3819 // next, protect the media tree all the while we're in here, as well as our member variables 3820 AutoMultiWriteLock3 multiLock(mParent->host()->lockHandle(), 3821 this->lockHandle(), 3822 &mParent->getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 3814 3823 3815 3824 ComObjPtr<MediumAttachment> pAttach = findAttachment(mMediaData->mAttachments, … … 3827 3836 oldmedium = pAttach->getMedium(); 3828 3837 3829 Guid uuid(aId); 3830 ComObjPtr<Medium> medium; 3831 DeviceType_T mediumType = pAttach->getType(); 3832 switch (mediumType) 3833 { 3834 case DeviceType_DVD: 3835 case DeviceType_Floppy: 3836 rc = mParent->findRemoveableMedium(mediumType, uuid, true /* fRefresh */, medium); 3837 if (FAILED(rc)) return rc; 3838 break; 3839 3840 default: 3841 return setError(VBOX_E_INVALID_OBJECT_STATE, 3842 tr("Cannot change medium attached to device slot %d on port %d of controller '%ls'"), 3843 aDevice, aControllerPort, aControllerName); 3844 } 3845 3846 if (SUCCEEDED(rc)) 3847 { 3848 setModified(IsModified_Storage); 3849 mMediaData.backup(); 3850 3851 /* The backup operation makes the pAttach reference point to the 3852 * old settings. Re-get the correct reference. */ 3838 ComObjPtr<Medium> pMedium = static_cast<Medium*>(aMedium); 3839 if (aMedium && pMedium.isNull()) 3840 return setError(E_INVALIDARG, "The given medium pointer is invalid"); 3841 3842 AutoCaller mediumCaller(pMedium); 3843 if (FAILED(mediumCaller.rc())) return mediumCaller.rc(); 3844 3845 AutoWriteLock mediumLock(pMedium COMMA_LOCKVAL_SRC_POS); 3846 if (pMedium) 3847 { 3848 DeviceType_T mediumType = pAttach->getType(); 3849 switch (mediumType) 3850 { 3851 case DeviceType_DVD: 3852 case DeviceType_Floppy: 3853 break; 3854 3855 default: 3856 return setError(VBOX_E_INVALID_OBJECT_STATE, 3857 tr("The device at port %d, device %d of controller '%ls' of this virtual machine is not removeable"), 3858 aControllerPort, 3859 aDevice, 3860 aControllerName); 3861 } 3862 } 3863 3864 setModified(IsModified_Storage); 3865 mMediaData.backup(); 3866 3867 bool fNeedsMachineSaveSettings = false, 3868 fNeedsGlobalSaveSettings = false; 3869 3870 { 3871 // The backup operation makes the pAttach reference point to the 3872 // old settings. Re-get the correct reference. 3853 3873 pAttach = findAttachment(mMediaData->mAttachments, 3854 3874 aControllerName, … … 3856 3876 aDevice); 3857 3877 AutoWriteLock attLock(pAttach COMMA_LOCKVAL_SRC_POS); 3858 /* For non-hard disk media, detach straight away. */ 3859 if (mediumType != DeviceType_HardDisk && !oldmedium.isNull()) 3878 if (!oldmedium.isNull()) 3860 3879 oldmedium->removeBackReference(mData->mUuid); 3861 if (!medium.isNull()) 3862 { 3863 medium->addBackReference(mData->mUuid); 3880 if (!pMedium.isNull()) 3881 { 3882 pMedium->addBackReference(mData->mUuid); 3883 3864 3884 // and decide which medium registry to use now that the medium is attached: 3865 3885 if (mData->pMachineConfigFile->canHaveOwnMediaRegistry()) 3866 // machine XML is VirtualBox 4.0 or higher: 3867 medium->addRegistry(getId()); // machine UUID 3886 // machine XML is VirtualBox 4.0 or higher: machine UUID 3887 pMedium->addRegistry(getId(), 3888 &fNeedsMachineSaveSettings); 3868 3889 else 3869 medium->addRegistry(mParent->getGlobalRegistryId()); // VirtualBox global registry UUID 3870 } 3871 3872 pAttach->updateMedium(medium); 3873 3874 setModified(IsModified_Storage); 3875 } 3876 3877 alock.leave(); 3890 // VirtualBox global registry UUID 3891 pMedium->addRegistry(mParent->getGlobalRegistryId(), 3892 &fNeedsGlobalSaveSettings); 3893 } 3894 3895 pAttach->updateMedium(pMedium); 3896 } 3897 3898 setModified(IsModified_Storage); 3899 3900 mediumLock.release(); 3901 multiLock.release(); 3878 3902 rc = onMediumChange(pAttach, aForce); 3879 alock.enter(); 3903 multiLock.acquire(); 3904 mediumLock.acquire(); 3880 3905 3881 3906 /* On error roll back this change only. */ 3882 3907 if (FAILED(rc)) 3883 3908 { 3884 if (! medium.isNull())3885 medium->removeBackReference(mData->mUuid);3909 if (!pMedium.isNull()) 3910 pMedium->removeBackReference(mData->mUuid); 3886 3911 pAttach = findAttachment(mMediaData->mAttachments, 3887 3912 aControllerName, … … 3892 3917 return rc; 3893 3918 AutoWriteLock attLock(pAttach COMMA_LOCKVAL_SRC_POS); 3894 /* For non-hard disk media, re-attach straight away. */ 3895 if (mediumType != DeviceType_HardDisk && !oldmedium.isNull()) 3919 if (!oldmedium.isNull()) 3896 3920 oldmedium->addBackReference(mData->mUuid); 3897 3921 pAttach->updateMedium(oldmedium); 3922 } 3923 3924 mediumLock.release(); 3925 multiLock.release(); 3926 3927 if (fNeedsMachineSaveSettings) 3928 { 3929 AutoWriteLock machineLock(this COMMA_LOCKVAL_SRC_POS); 3930 saveSettings(&fNeedsGlobalSaveSettings, SaveS_Force); 3931 } 3932 3933 if (fNeedsGlobalSaveSettings) 3934 { 3935 // save the global settings; for that we should hold only the VirtualBox lock 3936 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS); 3937 mParent->saveSettings(); 3898 3938 } 3899 3939 … … 7465 7505 if (puuidRegistry) 7466 7506 // caller wants registry ID to be set on all attached media (OVF import case) 7467 medium->addRegistry(*puuidRegistry); 7507 medium->addRegistry(*puuidRegistry, 7508 NULL /* pfNeedsSaveSettings */); 7468 7509 } 7469 7510
Note:
See TracChangeset
for help on using the changeset viewer.