Changeset 33921 in vbox for trunk/src/VBox/Main/MachineImpl.cpp
- Timestamp:
- Nov 9, 2010 5:51:38 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r33904 r33921 3323 3323 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3324 3324 3325 // if this becomes true then we need to call saveSettings in the end3326 // @todo r=dj there is no error handling so far...3327 bool fNeedsMachineSaveSettings = false,3328 fNeedsGlobalSaveSettings = false;3329 3330 3325 // request the host lock first, since might be calling Host methods for getting host drives; 3331 3326 // next, protect the media tree all the while we're in here, as well as our member variables … … 3336 3331 HRESULT rc = checkStateDependency(MutableStateDep); 3337 3332 if (FAILED(rc)) return rc; 3333 3334 GuidList llRegistriesThatNeedSaving; 3338 3335 3339 3336 /// @todo NEWMEDIA implicit machine registration … … 3596 3593 strFullSnapshotFolder.append(RTPATH_SLASH_STR), 3597 3594 medium->getFirstRegistryMachineId(), // store this diff in the same registry as the parent 3598 & fNeedsGlobalSaveSettings);3595 &llRegistriesThatNeedSaving); 3599 3596 if (FAILED(rc)) return rc; 3600 3597 … … 3628 3625 NULL /* aProgress */, 3629 3626 true /* aWait */, 3630 & fNeedsGlobalSaveSettings);3627 &llRegistriesThatNeedSaving); 3631 3628 3632 3629 alock.enter(); … … 3671 3668 3672 3669 // and decide which medium registry to use now that the medium is attached: 3670 Guid uuid; 3673 3671 if (mData->pMachineConfigFile->canHaveOwnMediaRegistry()) 3674 3672 // machine XML is VirtualBox 4.0 or higher: 3675 medium->addRegistry(getId(), // machine UUID 3676 &fNeedsMachineSaveSettings); 3673 uuid = getId(); // machine UUID 3677 3674 else 3678 medium->addRegistry(mParent->getGlobalRegistryId(), // VirtualBox global registry UUID 3679 &fNeedsGlobalSaveSettings); 3675 uuid = mParent->getGlobalRegistryId(); // VirtualBox global registry UUID 3676 3677 if (medium->addRegistry(uuid)) 3678 // registry actually changed: 3679 mParent->addGuidToListUniquely(llRegistriesThatNeedSaving, uuid); 3680 3680 } 3681 3681 … … 3687 3687 mediumLock.release(); 3688 3688 treeLock.leave(); 3689 3690 if (fNeedsMachineSaveSettings) 3691 saveSettings(&fNeedsGlobalSaveSettings, SaveS_Force); 3692 3693 if (fNeedsGlobalSaveSettings) 3694 { 3695 // save the global settings; for that we should hold only the VirtualBox lock 3696 alock.release(); 3697 3698 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS); 3699 mParent->saveSettings(); 3700 } 3689 alock.release(); 3690 3691 mParent->saveRegistries(llRegistriesThatNeedSaving); 3701 3692 3702 3693 return rc; … … 3714 3705 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3715 3706 3716 bool fNeedsSaveSettings = false;3707 GuidList llRegistriesThatNeedSaving; 3717 3708 3718 3709 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); … … 3737 3728 aDevice, aControllerPort, aControllerName); 3738 3729 3739 rc = detachDevice(pAttach, alock, NULL /* pSnapshot */, &fNeedsSaveSettings); 3740 3741 if (fNeedsSaveSettings) 3742 { 3743 bool fNeedsGlobalSaveSettings = false; 3744 saveSettings(&fNeedsGlobalSaveSettings); 3745 3746 if (fNeedsGlobalSaveSettings) 3747 { 3748 // save the global settings; for that we should hold only the VirtualBox lock 3749 alock.release(); 3750 AutoWriteLock vboxlock(this COMMA_LOCKVAL_SRC_POS); 3751 mParent->saveSettings(); 3752 } 3753 } 3754 3755 return S_OK; 3730 rc = detachDevice(pAttach, alock, NULL /* pSnapshot */, &llRegistriesThatNeedSaving); 3731 3732 alock.release(); 3733 3734 if (SUCCEEDED(rc)) 3735 rc = mParent->saveRegistries(llRegistriesThatNeedSaving); 3736 3737 return rc; 3756 3738 } 3757 3739 … … 3867 3849 mMediaData.backup(); 3868 3850 3869 bool fNeedsMachineSaveSettings = false, 3870 fNeedsGlobalSaveSettings = false; 3851 GuidList llRegistriesThatNeedSaving; 3871 3852 3872 3853 { … … 3885 3866 3886 3867 // and decide which medium registry to use now that the medium is attached: 3868 Guid uuid; 3887 3869 if (mData->pMachineConfigFile->canHaveOwnMediaRegistry()) 3888 // machine XML is VirtualBox 4.0 or higher: machine UUID 3889 pMedium->addRegistry(getId(), 3890 &fNeedsMachineSaveSettings); 3870 // machine XML is VirtualBox 4.0 or higher: 3871 uuid = getId(); // machine UUID 3891 3872 else 3892 // VirtualBox global registry UUID 3893 pMedium->addRegistry(mParent->getGlobalRegistryId(), 3894 &fNeedsGlobalSaveSettings); 3873 uuid = mParent->getGlobalRegistryId(); // VirtualBox global registry UUID 3874 3875 if (pMedium->addRegistry(uuid)) 3876 // registry actually changed: 3877 mParent->addGuidToListUniquely(llRegistriesThatNeedSaving, uuid); 3895 3878 } 3896 3879 … … 3927 3910 multiLock.release(); 3928 3911 3929 if (fNeedsMachineSaveSettings) 3930 { 3931 AutoWriteLock machineLock(this COMMA_LOCKVAL_SRC_POS); 3932 saveSettings(&fNeedsGlobalSaveSettings, SaveS_Force); 3933 } 3934 3935 if (fNeedsGlobalSaveSettings) 3936 { 3937 // save the global settings; for that we should hold only the VirtualBox lock 3938 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS); 3939 mParent->saveSettings(); 3940 } 3912 mParent->saveRegistries(llRegistriesThatNeedSaving); 3941 3913 3942 3914 return rc; … … 4347 4319 std::list<Utf8Str> llFilesToDelete; 4348 4320 ComObjPtr<Progress> pProgress; 4349 bool fNeedsGlobalSaveSettings;4321 GuidList llRegistriesThatNeedSaving; 4350 4322 }; 4351 4323 … … 4373 4345 pTask->llFilesToDelete = mData->llFilesToDelete; // saved states pushed here by Unregister() 4374 4346 4375 pTask->fNeedsGlobalSaveSettings = false;4376 4347 for (size_t i = 0; i < sfaMedia.size(); ++i) 4377 4348 { … … 4384 4355 // close the medium now; if that succeeds, then that means the medium is no longer 4385 4356 // in use and we can add it to the list of files to delete 4386 rc = pMedium->close(&pTask-> fNeedsGlobalSaveSettings,4357 rc = pMedium->close(&pTask->llRegistriesThatNeedSaving, 4387 4358 mediumAutoCaller); 4388 4359 if (SUCCEEDED(rc)) … … 4549 4520 alock.release(); 4550 4521 4551 if (task.fNeedsGlobalSaveSettings) 4552 { 4553 AutoWriteLock vboxlock(mParent COMMA_LOCKVAL_SRC_POS); 4554 mParent->saveSettings(); 4555 } 4522 mParent->saveRegistries(task.llRegistriesThatNeedSaving); 4556 4523 4557 4524 return S_OK; … … 7465 7432 if (puuidRegistry) 7466 7433 // caller wants registry ID to be set on all attached media (OVF import case) 7467 medium->addRegistry(*puuidRegistry, 7468 NULL /* pfNeedsSaveSettings */); 7434 medium->addRegistry(*puuidRegistry); 7469 7435 } 7470 7436 … … 8458 8424 * attached). 8459 8425 * @param aOnline Whether the VM was online prior to this operation. 8460 * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true 8461 * by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed. 8426 * @param pllRegistriesThatNeedSaving Optional pointer to a list of UUIDs to receive the registry IDs that need saving 8462 8427 * 8463 8428 * @note The progress object is not marked as completed, neither on success nor … … 8469 8434 ULONG aWeight, 8470 8435 bool aOnline, 8471 bool *pfNeedsSaveSettings)8436 GuidList *pllRegistriesThatNeedSaving) 8472 8437 { 8473 8438 LogFlowThisFunc(("aOnline=%d\n", aOnline)); … … 8594 8559 strFullSnapshotFolder.append(RTPATH_SLASH_STR), 8595 8560 pMedium->getFirstRegistryMachineId(), // store the diff in the same registry as the parent 8596 p fNeedsSaveSettings);8561 pllRegistriesThatNeedSaving); 8597 8562 if (FAILED(rc)) throw rc; 8598 8563 … … 8618 8583 NULL /* aProgress */, 8619 8584 true /* aWait */, 8620 p fNeedsSaveSettings);8585 pllRegistriesThatNeedSaving); 8621 8586 alock.enter(); 8622 8587 if (FAILED(rc)) throw rc; … … 8665 8630 MultiResult mrc = rc; 8666 8631 8667 mrc = deleteImplicitDiffs(p fNeedsSaveSettings);8632 mrc = deleteImplicitDiffs(pllRegistriesThatNeedSaving); 8668 8633 } 8669 8634 … … 8683 8648 * @note Locks this object for writing. 8684 8649 */ 8685 HRESULT Machine::deleteImplicitDiffs( bool *pfNeedsSaveSettings)8650 HRESULT Machine::deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving) 8686 8651 { 8687 8652 AutoCaller autoCaller(this); … … 8761 8726 8762 8727 rc = hd->deleteStorage(NULL /*aProgress*/, true /*aWait*/, 8763 p fNeedsSaveSettings);8728 pllRegistriesThatNeedSaving); 8764 8729 AssertMsg(SUCCEEDED(rc), ("rc=%Rhrc it=%s hd=%s\n", rc, (*it)->getLogName(), hd->getLocationFull().c_str() )); 8765 8730 mrc = rc; … … 8769 8734 8770 8735 if (mData->mMachineState == MachineState_SettingUp) 8771 {8772 8736 setMachineState(oldState); 8773 }8774 8737 } 8775 8738 … … 8873 8836 AutoWriteLock &writeLock, 8874 8837 Snapshot *pSnapshot, 8875 bool *pfNeedsSaveSettings)8838 GuidList *pllRegistriesThatNeedSaving) 8876 8839 { 8877 8840 ComObjPtr<Medium> oldmedium = pAttach->getMedium(); … … 8898 8861 8899 8862 HRESULT rc = oldmedium->deleteStorage(NULL /*aProgress*/, true /*aWait*/, 8900 p fNeedsSaveSettings);8863 pllRegistriesThatNeedSaving); 8901 8864 8902 8865 writeLock.acquire();
Note:
See TracChangeset
for help on using the changeset viewer.