- Timestamp:
- Mar 12, 2012 4:04:28 PM (13 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/MachineImpl.h
r40418 r40432 841 841 HRESULT saveStateSettings(int aFlags); 842 842 843 void addMediumToRegistry(ComObjPtr<Medium> &pMedium, 844 GuidList &llRegistriesThatNeedSaving, 845 Guid *puuid); 843 void addMediumToRegistry(ComObjPtr<Medium> &pMedium); 846 844 847 845 HRESULT createImplicitDiffs(IProgress *aProgress, 848 846 ULONG aWeight, 849 bool aOnline, 850 GuidList *pllRegistriesThatNeedSaving); 851 HRESULT deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving); 847 bool aOnline); 848 HRESULT deleteImplicitDiffs(); 852 849 853 850 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll, … … 862 859 HRESULT detachDevice(MediumAttachment *pAttach, 863 860 AutoWriteLock &writeLock, 864 Snapshot *pSnapshot, 865 GuidList *pllRegistriesThatNeedSaving); 861 Snapshot *pSnapshot); 866 862 867 863 HRESULT detachAllMedia(AutoWriteLock &writeLock, … … 937 933 typedef std::list<ComObjPtr<StorageController> > StorageControllerList; 938 934 Backupable<StorageControllerList> mStorageControllers; 935 936 uint64_t uRegistryNeedsSaving; 939 937 940 938 friend class SessionMachine; -
trunk/src/VBox/Main/include/MediumImpl.h
r40257 r40432 7 7 8 8 /* 9 * Copyright (C) 2008-201 1Oracle Corporation9 * Copyright (C) 2008-2012 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 70 70 const Utf8Str &aFormat, 71 71 const Utf8Str &aLocation, 72 const Guid &uuidMachineRegistry, 73 GuidList *pllRegistriesThatNeedSaving); 72 const Guid &uuidMachineRegistry); 74 73 75 74 // initializer for opening existing media … … 183 182 bool isInRegistry(const Guid& id); 184 183 bool getFirstRegistryMachineId(Guid &uuid) const; 185 HRESULT addToRegistryIDList(GuidList &llRegistryIDs);186 184 187 185 HRESULT addBackReference(const Guid &aMachineId, … … 218 216 MediumLockList *pMediumLockList, 219 217 ComObjPtr<Progress> *aProgress, 220 bool aWait, 221 GuidList *pllRegistriesThatNeedSaving); 218 bool aWait); 222 219 Utf8Str getPreferredDiffFormat(); 223 220 224 HRESULT close( GuidList *pllRegistriesThatNeedSaving,AutoCaller &autoCaller);225 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait , GuidList *pllRegistriesThatNeedSaving);221 HRESULT close(AutoCaller &autoCaller); 222 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait); 226 223 HRESULT markForDeletion(); 227 224 HRESULT unmarkForDeletion(); … … 243 240 MediumLockList *aMediumLockList, 244 241 ComObjPtr<Progress> *aProgress, 245 bool aWait, 246 GuidList *pllRegistriesThatNeedSaving); 242 bool aWait); 247 243 void cancelMergeTo(const MediaList &aChildrenToReparent, 248 244 MediumLockList *aMediumLockList); … … 273 269 274 270 HRESULT canClose(); 275 HRESULT unregisterWithVirtualBox(GuidList *pllRegistriesThatNeedSaving); 271 HRESULT unregisterWithVirtualBox(); 272 void markRegistriesModified(); 276 273 277 274 HRESULT setStateError(); … … 333 330 334 331 HRESULT startThread(Medium::Task *pTask); 335 HRESULT runNow(Medium::Task *pTask , GuidList *pllRegistriesThatNeedSaving);332 HRESULT runNow(Medium::Task *pTask); 336 333 337 334 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task); -
trunk/src/VBox/Main/include/VirtualBoxBase.h
r40418 r40432 4 4 5 5 /* 6 * Copyright (C) 2006-201 0Oracle Corporation6 * Copyright (C) 2006-2012 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 53 53 class Host; 54 54 typedef std::list< ComObjPtr<Medium> > MediaList; 55 typedef std::list<Guid> GuidList;56 55 57 56 //////////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r40262 r40432 260 260 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget); 261 261 262 HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType , GuidList *pllRegistriesThatNeedSaving);263 HRESULT unregisterMedium(Medium *pMedium , GuidList *pllRegistriesThatNeedSaving);262 HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType); 263 HRESULT unregisterMedium(Medium *pMedium); 264 264 265 265 void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium); … … 276 276 HRESULT saveSettings(); 277 277 278 static void addGuidToListUniquely(GuidList &llRegistriesThatNeedSaving,const Guid &uuid);279 HRESULT saveRegistries(const GuidList &llRegistriesThatNeedSaving);278 void markRegistryModified(const Guid &uuid); 279 void saveModifiedRegistries(); 280 280 281 281 static HRESULT ensureFilePathExists(const Utf8Str &strFileName, bool fCreate); -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r40329 r40432 6 6 7 7 /* 8 * Copyright (C) 2008-201 1Oracle Corporation8 * Copyright (C) 2008-2012 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 1847 1847 strTrgFormat, 1848 1848 strTargetPath, 1849 Guid::Empty, // media registry: none yet 1850 NULL /* llRegistriesThatNeedSaving */); 1849 Guid::Empty /* media registry: none yet */); 1851 1850 if (FAILED(rc)) throw rc; 1852 1851 -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r40418 r40432 5 5 6 6 /* 7 * Copyright (C) 2006-201 1Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 241 241 : mCollectorGuest(NULL), 242 242 mPeer(NULL), 243 mParent(NULL) 243 mParent(NULL), 244 uRegistryNeedsSaving(0) 244 245 {} 245 246 … … 768 769 769 770 Assert(!isWriteLockOnCurrentThread()); 771 772 Assert(!uRegistryNeedsSaving); 773 if (uRegistryNeedsSaving) 774 { 775 AutoCaller autoCaller(this); 776 if (SUCCEEDED(autoCaller.rc())) 777 { 778 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 779 saveSettings(NULL, Machine::SaveS_Force); 780 } 781 } 770 782 771 783 /* Enclose the state transition Ready->InUninit->NotReady */ … … 3483 3495 HRESULT rc = checkStateDependency(MutableStateDep); 3484 3496 if (FAILED(rc)) return rc; 3485 3486 GuidList llRegistriesThatNeedSaving;3487 3497 3488 3498 /// @todo NEWMEDIA implicit machine registration … … 3792 3802 // put the parent in the machine registry then 3793 3803 mediumLock.release(); 3794 addMediumToRegistry(medium , llRegistriesThatNeedSaving, &uuidRegistryParent);3804 addMediumToRegistry(medium); 3795 3805 mediumLock.acquire(); 3806 medium->getFirstRegistryMachineId(uuidRegistryParent); 3796 3807 } 3797 3808 rc = diff->init(mParent, 3798 3809 medium->getPreferredDiffFormat(), 3799 3810 strFullSnapshotFolder.append(RTPATH_SLASH_STR), 3800 uuidRegistryParent, 3801 &llRegistriesThatNeedSaving); 3811 uuidRegistryParent); 3802 3812 if (FAILED(rc)) return rc; 3803 3813 … … 3838 3848 pMediumLockList, 3839 3849 NULL /* aProgress */, 3840 true /* aWait */, 3841 &llRegistriesThatNeedSaving); 3850 true /* aWait */); 3842 3851 3843 3852 alock.acquire(); … … 3886 3895 3887 3896 mediumLock.release(); 3888 addMediumToRegistry(medium, 3889 llRegistriesThatNeedSaving, 3890 NULL /* Guid *puuid */); 3897 addMediumToRegistry(medium); 3891 3898 mediumLock.acquire(); 3892 3899 } … … 3904 3911 rc = onStorageDeviceChange(attachment, FALSE /* aRemove */); 3905 3912 3906 mParent->save Registries(llRegistriesThatNeedSaving);3913 mParent->saveModifiedRegistries(); 3907 3914 3908 3915 return rc; … … 3919 3926 AutoCaller autoCaller(this); 3920 3927 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3921 3922 GuidList llRegistriesThatNeedSaving;3923 3928 3924 3929 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); … … 3973 3978 3974 3979 /* If we are here everything went well and we can delete the implicit now. */ 3975 rc = detachDevice(pAttach, alock, NULL /* pSnapshot */ , &llRegistriesThatNeedSaving);3980 rc = detachDevice(pAttach, alock, NULL /* pSnapshot */); 3976 3981 3977 3982 alock.release(); 3978 3983 3979 if (SUCCEEDED(rc)) 3980 rc = mParent->saveRegistries(llRegistriesThatNeedSaving); 3984 mParent->saveModifiedRegistries(); 3981 3985 3982 3986 return rc; … … 4291 4295 setModified(IsModified_Storage); 4292 4296 mMediaData.backup(); 4293 4294 GuidList llRegistriesThatNeedSaving;4295 4297 4296 4298 { … … 4309 4311 4310 4312 mediumLock.release(); 4311 addMediumToRegistry(pMedium , llRegistriesThatNeedSaving, NULL /* Guid *puuid */);4313 addMediumToRegistry(pMedium); 4312 4314 mediumLock.acquire(); 4313 4315 } … … 4345 4347 multiLock.release(); 4346 4348 4347 mParent->save Registries(llRegistriesThatNeedSaving);4349 mParent->saveModifiedRegistries(); 4348 4350 4349 4351 return rc; … … 4743 4745 4744 4746 mParent->unregisterMachine(this, id); 4745 // calls VirtualBox::saveSettings() 4747 // calls VirtualBox::saveSettings() and VirtualBox::saveModifiedRegistries() 4746 4748 4747 4749 return S_OK; … … 4754 4756 std::list<Utf8Str> llFilesToDelete; 4755 4757 ComObjPtr<Progress> pProgress; 4756 GuidList llRegistriesThatNeedSaving;4757 4758 }; 4758 4759 … … 5000 5001 alock.release(); 5001 5002 5002 rc = mParent->saveRegistries(task.llRegistriesThatNeedSaving); 5003 if (FAILED(rc)) throw rc; 5003 mParent->saveModifiedRegistries(); 5004 5004 } 5005 5005 catch (HRESULT aRC) { rc = aRC; } … … 9506 9506 * Ensures that the given medium is added to a media registry. If this machine 9507 9507 * was created with 4.0 or later, then the machine registry is used. Otherwise 9508 * the global VirtualBox media registry is used. If the medium was actually 9509 * added to a registry (because it wasn't in the registry yet), the UUID of 9510 * that registry is added to the given list so that the caller can save the 9511 * registry. 9508 * the global VirtualBox media registry is used. 9512 9509 * 9513 9510 * Caller must hold machine read lock and at least media tree read lock! … … 9515 9512 * 9516 9513 * @param pMedium 9517 * @param llRegistriesThatNeedSaving9518 * @param puuid Optional buffer that receives the registry UUID that was used.9519 9514 */ 9520 void Machine::addMediumToRegistry(ComObjPtr<Medium> &pMedium, 9521 GuidList &llRegistriesThatNeedSaving, 9522 Guid *puuid) 9515 void Machine::addMediumToRegistry(ComObjPtr<Medium> &pMedium) 9523 9516 { 9524 9517 ComObjPtr<Medium> pBase = pMedium->getBase(); … … 9535 9528 uuid = mParent->getGlobalRegistryId(); // VirtualBox global registry UUID 9536 9529 9537 bool fAdd = false;9538 9530 if (pMedium->addRegistry(uuid, false /* fRecurse */)) 9539 { 9540 // registry actually changed: 9541 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving, uuid); 9542 fAdd = true; 9543 } 9531 mParent->markRegistryModified(uuid); 9544 9532 9545 9533 /* For more complex hard disk structures it can happen that the base … … 9547 9535 if (pMedium != pBase) 9548 9536 { 9549 if ( pBase->addRegistry(uuid, true /* fRecurse */) 9550 && !fAdd) 9551 { 9552 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving, uuid); 9553 fAdd = true; 9554 } 9555 } 9556 9557 if (puuid) 9558 *puuid = uuid; 9537 if (pBase->addRegistry(uuid, true /* fRecurse */)) 9538 mParent->markRegistryModified(uuid); 9539 } 9559 9540 } 9560 9541 … … 9584 9565 * attached). 9585 9566 * @param aOnline Whether the VM was online prior to this operation. 9586 * @param pllRegistriesThatNeedSaving Optional pointer to a list of UUIDs to receive the registry IDs that need saving9587 9567 * 9588 9568 * @note The progress object is not marked as completed, neither on success nor … … 9593 9573 HRESULT Machine::createImplicitDiffs(IProgress *aProgress, 9594 9574 ULONG aWeight, 9595 bool aOnline, 9596 GuidList *pllRegistriesThatNeedSaving) 9575 bool aOnline) 9597 9576 { 9598 9577 LogFlowThisFunc(("aOnline=%d\n", aOnline)); … … 9729 9708 pMedium->getPreferredDiffFormat(), 9730 9709 strFullSnapshotFolder.append(RTPATH_SLASH_STR), 9731 uuidRegistryParent, 9732 pllRegistriesThatNeedSaving); 9710 uuidRegistryParent); 9733 9711 if (FAILED(rc)) throw rc; 9734 9712 … … 9755 9733 pMediumLockList, 9756 9734 NULL /* aProgress */, 9757 true /* aWait */, 9758 pllRegistriesThatNeedSaving); 9735 true /* aWait */); 9759 9736 alock.acquire(); 9760 9737 if (FAILED(rc)) throw rc; … … 9812 9789 9813 9790 alock.release(); 9814 mrc = deleteImplicitDiffs( pllRegistriesThatNeedSaving);9791 mrc = deleteImplicitDiffs(); 9815 9792 } 9816 9793 … … 9825 9802 * called from #fixupMedia() when the changes are rolled back. 9826 9803 * 9827 * @param pllRegistriesThatNeedSaving Optional pointer to a list of UUIDs to receive the registry IDs that need saving9828 *9829 9804 * @note Locks this object for writing. 9830 9805 */ 9831 HRESULT Machine::deleteImplicitDiffs( GuidList *pllRegistriesThatNeedSaving)9806 HRESULT Machine::deleteImplicitDiffs() 9832 9807 { 9833 9808 AutoCaller autoCaller(this); … … 9906 9881 ComObjPtr<Medium> hd = (*it)->getMedium(); 9907 9882 9908 rc = hd->deleteStorage(NULL /*aProgress*/, true /*aWait*/, 9909 pllRegistriesThatNeedSaving); 9883 rc = hd->deleteStorage(NULL /*aProgress*/, true /*aWait*/); 9910 9884 AssertMsg(SUCCEEDED(rc), ("rc=%Rhrc it=%s hd=%s\n", rc, (*it)->getLogName(), hd->getLocationFull().c_str() )); 9911 9885 mrc = rc; … … 10010 9984 * @param writeLock Machine write lock which the caller must have locked once. This may be released temporarily in here. 10011 9985 * @param pSnapshot If NULL, then the detachment is for the current machine. Otherwise this is for a SnapshotMachine, and this must be its snapshot. 10012 * @param pllRegistriesThatNeedSaving Optional pointer to a list of UUIDs to receive the registry IDs that need saving10013 9986 * @return 10014 9987 */ 10015 9988 HRESULT Machine::detachDevice(MediumAttachment *pAttach, 10016 9989 AutoWriteLock &writeLock, 10017 Snapshot *pSnapshot, 10018 GuidList *pllRegistriesThatNeedSaving) 9990 Snapshot *pSnapshot) 10019 9991 { 10020 9992 ComObjPtr<Medium> oldmedium = pAttach->getMedium(); … … 10041 10013 10042 10014 HRESULT rc = oldmedium->deleteStorage(NULL /*aProgress*/, 10043 true /*aWait*/, 10044 pllRegistriesThatNeedSaving); 10015 true /*aWait*/); 10045 10016 10046 10017 writeLock.acquire(); … … 10152 10123 10153 10124 // real machine: then we need to use the proper method 10154 rc = detachDevice(pAttach, 10155 writeLock, 10156 pSnapshot, 10157 NULL /* pfNeedsSaveSettings */); 10125 rc = detachDevice(pAttach, writeLock, pSnapshot); 10158 10126 10159 10127 if (FAILED(rc)) … … 10348 10316 * backed up). 10349 10317 * 10350 * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true10351 * by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.10352 *10353 10318 * @note Locks this object for writing! 10354 *10355 * @todo r=dj this needs a pllRegistriesThatNeedSaving as well10356 10319 */ 10357 10320 void Machine::rollbackMedia() … … 10404 10367 /** @todo convert all this Machine-based voodoo to MediumAttachment 10405 10368 * based rollback logic. */ 10406 // @todo r=dj the below totally fails if this gets called from Machine::rollback(), 10407 // which gets called if Machine::registeredInit() fails... 10408 deleteImplicitDiffs(NULL /*pfNeedsSaveSettings*/); 10369 deleteImplicitDiffs(); 10409 10370 10410 10371 return; -
trunk/src/VBox/Main/src-server/MachineImplCloneVM.cpp
r40257 r40432 661 661 pParent->getPreferredDiffFormat(), 662 662 Utf8StrFmt("%s%c", strSnapshotFolder.c_str(), RTPATH_DELIMITER), 663 Guid::Empty, /* empty media registry */ 664 NULL); /* pllRegistriesThatNeedSaving */ 663 Guid::Empty /* empty media registry */); 665 664 if (FAILED(rc)) throw rc; 666 665 … … 678 677 pMediumLockList, 679 678 NULL /* aProgress */, 680 true /* aWait */, 681 NULL); // pllRegistriesThatNeedSaving 679 true /* aWait */); 682 680 delete pMediumLockList; 683 681 if (FAILED(rc)) throw rc; … … 1025 1023 typedef std::pair<Utf8Str, ComObjPtr<Medium> > TStrMediumPair; 1026 1024 TStrMediumMap map; 1027 GuidList llRegistriesThatNeedSaving;1028 1025 size_t cDisks = 0; 1029 1026 for (size_t i = 0; i < d->llMedias.size(); ++i) … … 1155 1152 Utf8Str(bstrSrcFormat), 1156 1153 strFile, 1157 Guid::Empty, /* empty media registry */ 1158 NULL /* llRegistriesThatNeedSaving */); 1154 Guid::Empty /* empty media registry */); 1159 1155 if (FAILED(rc)) throw rc; 1160 1156 … … 1202 1198 AutoWriteLock tlock(p->mParent->getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 1203 1199 rc = p->mParent->registerMedium(pTarget, &pTarget, 1204 DeviceType_HardDisk, 1205 NULL /* pllRegistriesThatNeedSaving */); 1200 DeviceType_HardDisk); 1206 1201 if (FAILED(rc)) throw rc; 1207 1202 } … … 1276 1271 AutoReadLock mlock2(pParent COMMA_LOCKVAL_SRC_POS); 1277 1272 if (pParent->getFirstRegistryMachineId(uuid)) 1278 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving,uuid);1273 p->mParent->markRegistryModified(uuid); 1279 1274 } 1280 1275 mlock.acquire(); … … 1347 1342 1348 1343 /* Any additional machines need saving? */ 1349 if (!llRegistriesThatNeedSaving.empty()) 1350 { 1351 rc = p->mParent->saveRegistries(llRegistriesThatNeedSaving); 1352 if (FAILED(rc)) throw rc; 1353 } 1344 p->mParent->saveModifiedRegistries(); 1354 1345 } 1355 1346 catch (HRESULT rc2) … … 1380 1371 const ComObjPtr<Medium> &pMedium = newMedia.at(i - 1); 1381 1372 mrc = pMedium->deleteStorage(NULL /* aProgress */, 1382 true /* aWait */, 1383 NULL /* llRegistriesThatNeedSaving */); 1373 true /* aWait */); 1384 1374 pMedium->Close(); 1385 1375 } -
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r40259 r40432 40 40 41 41 #include <algorithm> 42 #include <list> 43 44 typedef std::list<Guid> GuidList; 42 45 43 46 //////////////////////////////////////////////////////////////////////////////// … … 198 201 Task(Medium *aMedium, Progress *aProgress) 199 202 : mVDOperationIfaces(NULL), 200 m_pllRegistriesThatNeedSaving(NULL),201 203 mMedium(aMedium), 202 204 mMediumCaller(aMedium), … … 245 247 PVDINTERFACE mVDOperationIfaces; 246 248 247 // Whether the caller needs to call VirtualBox::saveRegistries() after248 // the task function returns. Only used in synchronous (wait) mode;249 // otherwise the task will save the settings itself.250 GuidList *m_pllRegistriesThatNeedSaving;251 252 249 const ComObjPtr<Medium> mMedium; 253 250 AutoCaller mMediumCaller; 254 251 255 friend HRESULT Medium::runNow(Medium::Task* , GuidList *);252 friend HRESULT Medium::runNow(Medium::Task*); 256 253 257 254 protected: … … 928 925 * @param aLocation Storage unit location. 929 926 * @param uuidMachineRegistry The registry to which this medium should be added (global registry UUID or machine UUID or empty if none). 930 * @param pllRegistriesThatNeedSaving Optional list to receive the UUIDs of the media registries that need saving.931 927 */ 932 928 HRESULT Medium::init(VirtualBox *aVirtualBox, 933 929 const Utf8Str &aFormat, 934 930 const Utf8Str &aLocation, 935 const Guid &uuidMachineRegistry, 936 GuidList *pllRegistriesThatNeedSaving) 931 const Guid &uuidMachineRegistry) 937 932 { 938 933 AssertReturn(aVirtualBox != NULL, E_FAIL); … … 979 974 AutoWriteLock treeLock(m->pVirtualBox->getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 980 975 ComObjPtr<Medium> pMedium; 981 rc = m->pVirtualBox->registerMedium(this, &pMedium, DeviceType_HardDisk, 982 pllRegistriesThatNeedSaving); 976 rc = m->pVirtualBox->registerMedium(this, &pMedium, DeviceType_HardDisk); 983 977 Assert(this == pMedium); 984 978 } … … 1256 1250 if (FAILED(rc)) break; 1257 1251 1258 rc = m->pVirtualBox->registerMedium(pHD, &pHD, DeviceType_HardDisk, 1259 NULL /* pllRegistriesThatNeedSaving */ ); 1252 rc = m->pVirtualBox->registerMedium(pHD, &pHD, DeviceType_HardDisk); 1260 1253 if (FAILED(rc)) break; 1261 1254 } … … 1749 1742 1750 1743 // save the settings 1751 GuidList llRegistriesThatNeedSaving; 1752 addToRegistryIDList(llRegistriesThatNeedSaving); 1744 markRegistriesModified(); 1753 1745 mlock.release(); 1754 1746 treeLock.release(); 1755 HRESULT rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);1756 1757 return rc;1747 m->pVirtualBox->saveModifiedRegistries(); 1748 1749 return S_OK; 1758 1750 } 1759 1751 … … 1889 1881 m->strLocationFull.c_str()); 1890 1882 1891 HRESULT rc = S_OK;1892 1893 1883 if (m->autoReset != !!aAutoReset) 1894 1884 { … … 1896 1886 1897 1887 // save the settings 1898 GuidList llRegistriesThatNeedSaving; 1899 addToRegistryIDList(llRegistriesThatNeedSaving); 1888 markRegistriesModified(); 1900 1889 mlock.release(); 1901 rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);1902 } 1903 1904 return rc;1890 m->pVirtualBox->saveModifiedRegistries(); 1891 } 1892 1893 return S_OK; 1905 1894 } 1906 1895 … … 2208 2197 ComObjPtr<VirtualBox> pVirtualBox(m->pVirtualBox); 2209 2198 2210 GuidList llRegistriesThatNeedSaving; 2211 MultiResult mrc = close(&llRegistriesThatNeedSaving, autoCaller); 2212 /* Must save the registries, since an entry was most likely removed. */ 2213 mrc = pVirtualBox->saveRegistries(llRegistriesThatNeedSaving); 2199 MultiResult mrc = close(autoCaller); 2200 2201 pVirtualBox->saveModifiedRegistries(); 2214 2202 2215 2203 return mrc; … … 2263 2251 2264 2252 // save the settings 2265 GuidList llRegistriesThatNeedSaving; 2266 addToRegistryIDList(llRegistriesThatNeedSaving); 2253 markRegistriesModified(); 2267 2254 mlock.release(); 2268 HRESULT rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);2269 2270 return rc;2255 m->pVirtualBox->saveModifiedRegistries(); 2256 2257 return S_OK; 2271 2258 } 2272 2259 … … 2341 2328 2342 2329 // save the settings 2343 GuidList llRegistriesThatNeedSaving; 2344 addToRegistryIDList(llRegistriesThatNeedSaving); 2330 markRegistriesModified(); 2345 2331 mlock.release(); 2346 HRESULT rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);2347 2348 return rc;2332 m->pVirtualBox->saveModifiedRegistries(); 2333 2334 return S_OK; 2349 2335 } 2350 2336 … … 2427 2413 ComObjPtr<Progress> pProgress; 2428 2414 2429 GuidList llRegistriesThatNeedSaving;2430 2415 MultiResult mrc = deleteStorage(&pProgress, 2431 false /* aWait */, 2432 &llRegistriesThatNeedSaving); 2416 false /* aWait */); 2433 2417 /* Must save the registries in any case, since an entry was removed. */ 2434 m rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);2418 m->pVirtualBox->saveModifiedRegistries(); 2435 2419 2436 2420 if (SUCCEEDED(mrc)) … … 2499 2483 /* since this medium has been just created it isn't associated yet */ 2500 2484 diff->m->llRegistryIDs.push_back(parentMachineRegistry); 2485 diff->markRegistriesModified(); 2501 2486 } 2502 2487 … … 2506 2491 2507 2492 rc = createDiffStorage(diff, (MediumVariant_T)aVariant, pMediumLockList, 2508 &pProgress, false /* aWait */, 2509 NULL /* pfNeedsGlobalSaveSettings*/); 2493 &pProgress, false /* aWait */); 2510 2494 if (FAILED(rc)) 2511 2495 delete pMediumLockList; … … 2541 2525 2542 2526 rc = mergeTo(pTarget, fMergeForward, pParentForTarget, childrenToReparent, 2543 pMediumLockList, &pProgress, false /* aWait */, 2544 NULL /* pfNeedsGlobalSaveSettings */); 2527 pMediumLockList, &pProgress, false /* aWait */); 2545 2528 if (FAILED(rc)) 2546 2529 cancelMergeTo(childrenToReparent, pMediumLockList); … … 3236 3219 3237 3220 /** 3238 * Adds all the IDs of the registries in which this medium is registered to the given list 3239 * of UUIDs, but only if they are not on the list yet. 3240 * @param llRegistryIDs 3241 */ 3242 HRESULT Medium::addToRegistryIDList(GuidList &llRegistryIDs) 3221 * Marks all the registries in which this medium is registered as modified. 3222 */ 3223 void Medium::markRegistriesModified() 3243 3224 { 3244 3225 AutoCaller autoCaller(this); 3245 if (FAILED(autoCaller.rc())) return false;3226 if (FAILED(autoCaller.rc())) return; 3246 3227 3247 3228 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); … … 3251 3232 ++it) 3252 3233 { 3253 VirtualBox::addGuidToListUniquely(llRegistryIDs, *it); 3254 } 3255 3256 return S_OK; 3234 m->pVirtualBox->markRegistryModified(*it); 3235 } 3257 3236 } 3258 3237 … … 3816 3795 * @param aWait @c true if this method should block instead of 3817 3796 * creating an asynchronous thread. 3818 * @param pllRegistriesThatNeedSaving Optional pointer to a list of UUIDs that will receive the registry IDs that need saving.3819 * This only works in "wait" mode; otherwise saveRegistries is called automatically by the thread that3820 * was created, and this parameter is ignored.3821 3797 * 3822 3798 * @note Locks this object and @a aTarget for writing. … … 3826 3802 MediumLockList *aMediumLockList, 3827 3803 ComObjPtr<Progress> *aProgress, 3828 bool aWait, 3829 GuidList *pllRegistriesThatNeedSaving) 3804 bool aWait) 3830 3805 { 3831 3806 AssertReturn(!aTarget.isNull(), E_FAIL); … … 3918 3893 { 3919 3894 if (aWait) 3920 rc = runNow(pTask , pllRegistriesThatNeedSaving);3895 rc = runNow(pTask); 3921 3896 else 3922 3897 rc = startThread(pTask); … … 3960 3935 * the object is no longer usable ("not ready" state). 3961 3936 * 3962 * @param pllRegistriesThatNeedSaving Optional pointer to a list of UUIDs that will receive the registry IDs that need saving.3963 3937 * @param autoCaller AutoCaller instance which must have been created on the caller's stack for this medium. This gets released here 3964 3938 * upon which the Medium instance gets uninitialized. 3965 3939 * @return 3966 3940 */ 3967 HRESULT Medium::close(GuidList *pllRegistriesThatNeedSaving, 3968 AutoCaller &autoCaller) 3941 HRESULT Medium::close(AutoCaller &autoCaller) 3969 3942 { 3970 3943 // we're accessing parent/child and backrefs, so lock the tree first, then ourselves … … 4003 3976 // uninitialization (to keep the media registry consistent on 4004 3977 // failure to do so) 4005 rc = unregisterWithVirtualBox( pllRegistriesThatNeedSaving);3978 rc = unregisterWithVirtualBox(); 4006 3979 if (FAILED(rc)) return rc; 4007 3980 } … … 4037 4010 * @param aWait @c true if this method should block instead of creating 4038 4011 * an asynchronous thread. 4039 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true4040 * by this function if the caller should invoke VirtualBox::saveRegistries() because the global settings have changed.4041 * This only works in "wait" mode; otherwise saveRegistries gets called automatically by the thread that was created,4042 * and this parameter is ignored.4043 4012 * 4044 4013 * @note Locks mVirtualBox and this object for writing. Locks medium tree for … … 4046 4015 */ 4047 4016 HRESULT Medium::deleteStorage(ComObjPtr<Progress> *aProgress, 4048 bool aWait, 4049 GuidList *pllRegistriesThatNeedSaving) 4017 bool aWait) 4050 4018 { 4051 4019 AssertReturn(aProgress != NULL || aWait == true, E_FAIL); … … 4153 4121 * which would have been broken if unregisterWithVirtualBox() failed 4154 4122 * after we successfully deleted the storage) */ 4155 rc = unregisterWithVirtualBox( pllRegistriesThatNeedSaving);4123 rc = unregisterWithVirtualBox(); 4156 4124 if (FAILED(rc)) 4157 4125 throw rc; … … 4189 4157 { 4190 4158 if (aWait) 4191 rc = runNow(pTask , NULL /* pfNeedsGlobalSaveSettings*/);4159 rc = runNow(pTask); 4192 4160 else 4193 4161 rc = startThread(pTask); … … 4672 4640 * @param aWait @c true if this method should block instead of creating 4673 4641 * an asynchronous thread. 4674 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true4675 * by this function if the caller should invoke VirtualBox::saveRegistries() because the global settings have changed.4676 * This only works in "wait" mode; otherwise saveRegistries gets called automatically by the thread that was created,4677 * and this parameter is ignored.4678 4642 * 4679 4643 * @note Locks the tree lock for writing. Locks the media from the chain … … 4686 4650 MediumLockList *aMediumLockList, 4687 4651 ComObjPtr <Progress> *aProgress, 4688 bool aWait, 4689 GuidList *pllRegistriesThatNeedSaving) 4652 bool aWait) 4690 4653 { 4691 4654 AssertReturn(pTarget != NULL, E_FAIL); … … 4749 4712 { 4750 4713 if (aWait) 4751 rc = runNow(pTask , pllRegistriesThatNeedSaving);4714 rc = runNow(pTask); 4752 4715 else 4753 4716 rc = startThread(pTask); … … 5803 5766 * Unregisters this medium with mVirtualBox. Called by close() under the medium tree lock. 5804 5767 * 5805 * @param pllRegistriesThatNeedSaving Optional pointer to a list of UUIDs that will receive the registry IDs that need saving.5806 *5807 5768 * @note Caller must have locked the media tree lock for writing! 5808 5769 */ 5809 HRESULT Medium::unregisterWithVirtualBox( GuidList *pllRegistriesThatNeedSaving)5770 HRESULT Medium::unregisterWithVirtualBox() 5810 5771 { 5811 5772 /* Note that we need to de-associate ourselves from the parent to let … … 5820 5781 deparent(); 5821 5782 5822 HRESULT rc = m->pVirtualBox->unregisterMedium(this , pllRegistriesThatNeedSaving);5783 HRESULT rc = m->pVirtualBox->unregisterMedium(this); 5823 5784 if (FAILED(rc)) 5824 5785 { … … 5830 5791 } 5831 5792 } 5793 m->pVirtualBox->saveModifiedRegistries(); 5832 5794 5833 5795 return rc; … … 6453 6415 * complete the progress object in this case. 6454 6416 */ 6455 HRESULT Medium::runNow(Medium::Task *pTask, 6456 GuidList *pllRegistriesThatNeedSaving) 6417 HRESULT Medium::runNow(Medium::Task *pTask) 6457 6418 { 6458 6419 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION … … 6463 6424 Assert(!AutoLockHoldsLocksInClass(getLockingClass())); 6464 6425 #endif 6465 6466 pTask->m_pllRegistriesThatNeedSaving = pllRegistriesThatNeedSaving;6467 6426 6468 6427 /* NIL_RTTHREAD indicates synchronous call. */ … … 6567 6526 AutoWriteLock treeLock(m->pVirtualBox->getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 6568 6527 ComObjPtr<Medium> pMedium; 6569 rc = m->pVirtualBox->registerMedium(this, &pMedium, DeviceType_HardDisk, 6570 NULL /* pllRegistriesThatNeedSaving */); 6528 rc = m->pVirtualBox->registerMedium(this, &pMedium, DeviceType_HardDisk); 6571 6529 Assert(this == pMedium); 6572 6530 } … … 6582 6540 m->logicalSize = logicalSize; 6583 6541 m->variant = variant; 6542 6543 markRegistriesModified(); 6544 if (task.isAsync()) 6545 { 6546 // in asynchronous mode, save settings now 6547 thisLock.release(); 6548 m->pVirtualBox->saveModifiedRegistries(); 6549 } 6584 6550 } 6585 6551 else … … 6601 6567 * This task always gets started from Medium::createDiffStorage() and can run 6602 6568 * synchronously or asynchronously depending on the "wait" parameter passed to 6603 * that function. If we run synchronously, the caller expects the bool6604 * *pfNeedsGlobalSaveSettingsto be set before returning; otherwise (in asynchronous6569 * that function. If we run synchronously, the caller expects the medium 6570 * registry modification to be set before returning; otherwise (in asynchronous 6605 6571 * mode), we save the settings ourselves. 6606 6572 * … … 6617 6583 MediumVariant_T variant = MediumVariant_Standard; 6618 6584 bool fGenerateUuid = false; 6619 6620 GuidList llRegistriesThatNeedSaving; // gets copied to task pointer later in synchronous mode6621 6585 6622 6586 try … … 6747 6711 * better than breaking media registry consistency) */ 6748 6712 ComObjPtr<Medium> pMedium; 6749 mrc = m->pVirtualBox->registerMedium(pTarget, &pMedium, DeviceType_HardDisk, 6750 &llRegistriesThatNeedSaving); 6713 mrc = m->pVirtualBox->registerMedium(pTarget, &pMedium, DeviceType_HardDisk); 6751 6714 Assert(pTarget == pMedium); 6752 6715 … … 6782 6745 --m->numCreateDiffTasks; 6783 6746 6747 markRegistriesModified(); 6784 6748 if (task.isAsync()) 6785 6749 { 6750 // in asynchronous mode, save settings now 6786 6751 mediaLock.release(); 6787 mrc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving); 6788 } 6789 else 6790 // synchronous mode: report save settings result to caller 6791 if (task.m_pllRegistriesThatNeedSaving) 6792 *task.m_pllRegistriesThatNeedSaving = llRegistriesThatNeedSaving; 6752 m->pVirtualBox->saveModifiedRegistries(); 6753 } 6793 6754 6794 6755 /* Note that in sync mode, it's the caller's responsibility to … … 6803 6764 * This task always gets started from Medium::mergeTo() and can run 6804 6765 * synchronously or asynchronously depending on the "wait" parameter passed to 6805 * that function. If we run synchronously, the caller expects the bool6806 * *pfNeedsGlobalSaveSettingsto be set before returning; otherwise (in asynchronous6766 * that function. If we run synchronously, the caller expects the medium 6767 * registry modification to be set before returning; otherwise (in asynchronous 6807 6768 * mode), we save the settings ourselves. 6808 6769 * … … 6968 6929 /* first, unregister the target since it may become a base 6969 6930 * medium which needs re-registration */ 6970 rc2 = m->pVirtualBox->unregisterMedium(pTarget , NULL /*pfNeedsGlobalSaveSettings*/);6931 rc2 = m->pVirtualBox->unregisterMedium(pTarget); 6971 6932 AssertComRC(rc2); 6972 6933 … … 6984 6945 ComObjPtr<Medium> pMedium; 6985 6946 rc2 = m->pVirtualBox->registerMedium(pTarget, &pMedium, 6986 DeviceType_HardDisk, 6987 NULL /* pllRegistriesThatNeedSaving */ ); 6947 DeviceType_HardDisk); 6988 6948 AssertComRC(rc2); 6989 6949 } … … 7038 6998 } 7039 6999 7040 rc2 = pMedium->m->pVirtualBox->unregisterMedium(pMedium, 7041 NULL /*pfNeedsGlobalSaveSettings*/); 7000 rc2 = pMedium->m->pVirtualBox->unregisterMedium(pMedium); 7042 7001 AssertComRC(rc2); 7043 7002 … … 7072 7031 } 7073 7032 7033 markRegistriesModified(); 7074 7034 if (task.isAsync()) 7075 7035 { 7076 7036 // in asynchronous mode, save settings now 7077 GuidList llRegistriesThatNeedSaving;7078 addToRegistryIDList(llRegistriesThatNeedSaving);7079 /* collect multiple errors */7080 7037 eik.restore(); 7081 m rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);7038 m->pVirtualBox->saveModifiedRegistries(); 7082 7039 eik.fetch(); 7083 7040 } 7084 else7085 // synchronous mode: report save settings result to caller7086 if (task.m_pllRegistriesThatNeedSaving)7087 pTarget->addToRegistryIDList(*task.m_pllRegistriesThatNeedSaving);7088 7041 7089 7042 if (FAILED(mrc)) … … 7336 7289 ComObjPtr<Medium> pMedium; 7337 7290 mrc = pParent->m->pVirtualBox->registerMedium(pTarget, &pMedium, 7338 DeviceType_HardDisk, 7339 NULL /* pllRegistriesThatNeedSaving */); 7291 DeviceType_HardDisk); 7340 7292 Assert(pTarget == pMedium); 7341 7293 eik.fetch(); … … 7351 7303 ComObjPtr<Medium> pMedium; 7352 7304 mrc = m->pVirtualBox->registerMedium(pTarget, &pMedium, 7353 DeviceType_HardDisk, 7354 NULL /* pllRegistriesThatNeedSaving */); 7305 DeviceType_HardDisk); 7355 7306 Assert(pTarget == pMedium); 7356 7307 eik.fetch(); … … 7385 7336 { 7386 7337 // save the settings 7387 GuidList llRegistriesThatNeedSaving; 7388 addToRegistryIDList(llRegistriesThatNeedSaving); 7338 markRegistriesModified(); 7389 7339 /* collect multiple errors */ 7390 7340 eik.restore(); 7391 m rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);7341 m->pVirtualBox->saveModifiedRegistries(); 7392 7342 eik.fetch(); 7393 7343 } … … 8119 8069 ComObjPtr<Medium> pMedium; 8120 8070 mrc = pParent->m->pVirtualBox->registerMedium(this, &pMedium, 8121 DeviceType_HardDisk, 8122 NULL /* llRegistriesThatNeedSaving */); 8071 DeviceType_HardDisk); 8123 8072 Assert(this == pMedium); 8124 8073 eik.fetch(); … … 8133 8082 eik.restore(); 8134 8083 ComObjPtr<Medium> pMedium; 8135 mrc = m->pVirtualBox->registerMedium(this, &pMedium, DeviceType_HardDisk, 8136 NULL /* pllRegistriesThatNeedSaving */); 8084 mrc = m->pVirtualBox->registerMedium(this, &pMedium, DeviceType_HardDisk); 8137 8085 Assert(this == pMedium); 8138 8086 eik.fetch(); … … 8166 8114 { 8167 8115 // save the settings 8168 GuidList llRegistriesThatNeedSaving; 8169 addToRegistryIDList(llRegistriesThatNeedSaving); 8116 markRegistriesModified(); 8170 8117 /* collect multiple errors */ 8171 8118 eik.restore(); 8172 m rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);8119 m->pVirtualBox->saveModifiedRegistries(); 8173 8120 eik.fetch(); 8174 8121 } -
trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
r40418 r40432 1397 1397 AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); 1398 1398 1399 GuidList llRegistriesThatNeedSaving;1400 1401 1399 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1402 1400 … … 1485 1483 rc = createImplicitDiffs(aConsoleProgress, 1486 1484 1, // operation weight; must be the same as in Console::TakeSnapshot() 1487 !!fTakingSnapshotOnline, 1488 &llRegistriesThatNeedSaving); 1485 !!fTakingSnapshotOnline); 1489 1486 if (FAILED(rc)) 1490 1487 throw rc; … … 1493 1490 // that got modified for the diff images 1494 1491 alock.release(); 1495 mParent->save Registries(llRegistriesThatNeedSaving);1492 mParent->saveModifiedRegistries(); 1496 1493 } 1497 1494 catch (HRESULT hrc) … … 1623 1620 mConsoleTaskData.mLastState = MachineState_Null; 1624 1621 mConsoleTaskData.mSnapshot.setNull(); 1622 1623 machineLock.release(); 1624 1625 mParent->saveModifiedRegistries(); 1625 1626 1626 1627 return rc; … … 1774 1775 1775 1776 bool stateRestored = false; 1776 GuidList llRegistriesThatNeedSaving;1777 1777 1778 1778 try … … 1841 1841 rc = createImplicitDiffs(aTask.pProgress, 1842 1842 1, 1843 false /* aOnline */, 1844 &llRegistriesThatNeedSaving); 1843 false /* aOnline */); 1845 1844 if (FAILED(rc)) 1846 1845 throw rc; … … 1949 1948 // unconditionally add the parent registry. We do similar in SessionMachine::EndTakingSnapshot 1950 1949 // (mParent->saveSettings()) 1951 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving,mParent->getGlobalRegistryId());1950 mParent->markRegistryModified(mParent->getGlobalRegistryId()); 1952 1951 1953 1952 // let go of the locks while we're deleting image files below … … 1963 1962 1964 1963 HRESULT rc2 = pMedium->deleteStorage(NULL /* aProgress */, 1965 true /* aWait */, 1966 &llRegistriesThatNeedSaving); 1964 true /* aWait */); 1967 1965 // ignore errors here because we cannot roll back after saveSettings() above 1968 1966 if (SUCCEEDED(rc2)) … … 1991 1989 } 1992 1990 1993 mParent->save Registries(llRegistriesThatNeedSaving);1991 mParent->saveModifiedRegistries(); 1994 1992 1995 1993 /* set the result (this will try to fetch current error info on failure) */ … … 2292 2290 } 2293 2291 2292 HRESULT rc = S_OK; 2294 2293 MediumDeleteRecList toDelete; 2295 2296 HRESULT rc = S_OK;2297 2298 GuidList llRegistriesThatNeedSaving;2299 2300 2294 Guid snapshotId; 2301 2295 … … 2499 2493 2500 2494 // machine will need saving now 2501 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving,getId());2495 mParent->markRegistryModified(getId()); 2502 2496 } 2503 2497 } … … 2546 2540 mLock.release(); 2547 2541 rc = pMedium->deleteStorage(&aTask.pProgress, 2548 true /* aWait */, 2549 &llRegistriesThatNeedSaving); 2542 true /* aWait */); 2550 2543 if (FAILED(rc)) 2551 2544 throw rc; … … 2580 2573 it->mpMediumLockList, 2581 2574 &aTask.pProgress, 2582 true /* aWait */, 2583 &llRegistriesThatNeedSaving); 2575 true /* aWait */); 2584 2576 } 2585 2577 … … 2674 2666 2675 2667 // One attachment is merged, must save the settings 2676 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving,getId());2668 mParent->markRegistryModified(getId()); 2677 2669 2678 2670 // prevent calling cancelDeleteSnapshotMedium() for this attachment … … 2693 2685 aTask.pSnapshot->uninit(); 2694 2686 2695 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving,getId());2687 mParent->markRegistryModified(getId()); 2696 2688 } 2697 2689 } … … 2733 2725 updateMachineStateOnClient(); 2734 2726 2735 mParent->save Registries(llRegistriesThatNeedSaving);2727 mParent->saveModifiedRegistries(); 2736 2728 } 2737 2729 … … 3271 3263 // first, unregister the target since it may become a base 3272 3264 // hard disk which needs re-registration 3273 rc = mParent->unregisterMedium(pTarget , NULL /*&fNeedsGlobalSaveSettings*/);3265 rc = mParent->unregisterMedium(pTarget); 3274 3266 AssertComRC(rc); 3275 3267 … … 3282 3274 3283 3275 // then, register again 3284 rc = mParent->registerMedium(pTarget, &pTarget, DeviceType_HardDisk, 3285 NULL /* pllRegistriesThatNeedSaving */); 3276 rc = mParent->registerMedium(pTarget, &pTarget, DeviceType_HardDisk); 3286 3277 AssertComRC(rc); 3287 3278 } … … 3356 3347 else 3357 3348 { 3358 rc = mParent->unregisterMedium(pMedium , NULL /*pfNeedsGlobalSaveSettings*/);3349 rc = mParent->unregisterMedium(pMedium); 3359 3350 AssertComRC(rc); 3360 3351 -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r40262 r40432 185 185 : pMainConfigFile(NULL), 186 186 uuidMediaRegistry("48024e5c-fdd9-470f-93af-ec29f7ea518c"), 187 uRegistryNeedsSaving(0), 187 188 lockMachines(LOCKCLASS_LISTOFMACHINES), 188 189 allMachines(lockMachines), … … 223 224 // constant pseudo-machine ID for global media registry 224 225 const Guid uuidMediaRegistry; 226 227 // counter if global media registry needs saving, updated using atomic 228 // operations, without requiring any locks 229 uint64_t uRegistryNeedsSaving; 225 230 226 231 // const objects not requiring locking … … 628 633 if (FAILED(rc)) return rc; 629 634 630 rc = registerMedium(pHardDisk, &pHardDisk, DeviceType_HardDisk, 631 NULL /* pllRegistriesThatNeedSaving */); 635 rc = registerMedium(pHardDisk, &pHardDisk, DeviceType_HardDisk); 632 636 if (FAILED(rc)) return rc; 633 637 } … … 649 653 if (FAILED(rc)) return rc; 650 654 651 rc = registerMedium(pImage, &pImage, DeviceType_DVD, 652 NULL /* pllRegistriesThatNeedSaving */); 655 rc = registerMedium(pImage, &pImage, DeviceType_DVD); 653 656 if (FAILED(rc)) return rc; 654 657 } … … 670 673 if (FAILED(rc)) return rc; 671 674 672 rc = registerMedium(pImage, &pImage, DeviceType_Floppy, 673 NULL /* pllRegistriesThatNeedSaving */); 675 rc = registerMedium(pImage, &pImage, DeviceType_Floppy); 674 676 if (FAILED(rc)) return rc; 675 677 } … … 682 684 void VirtualBox::uninit() 683 685 { 686 Assert(!m->uRegistryNeedsSaving); 687 if (m->uRegistryNeedsSaving) 688 saveSettings(); 689 684 690 /* Enclose the state transition Ready->InUninit->NotReady */ 685 691 AutoUninitSpan autoUninitSpan(this); … … 1652 1658 format, 1653 1659 aLocation, 1654 Guid::Empty, // media registry: none yet 1655 NULL /* pllRegistriesThatNeedSaving */); 1660 Guid::Empty /* media registry: none yet */); 1656 1661 1657 1662 if (SUCCEEDED(rc)) … … 1722 1727 if (SUCCEEDED(rc)) 1723 1728 { 1724 rc = registerMedium(pMedium, &pMedium, deviceType, 1725 NULL /* pllRegistriesThatNeedSaving */); 1729 rc = registerMedium(pMedium, &pMedium, deviceType); 1726 1730 1727 1731 treeLock.release(); … … 3543 3547 * created. 3544 3548 * @param argType Either DeviceType_HardDisk, DeviceType_DVD or DeviceType_Floppy. 3545 * @param pllRegistriesThatNeedSaving Optional pointer to a list of UUIDs of media registries that need saving.3546 3549 * @return 3547 3550 */ 3548 3551 HRESULT VirtualBox::registerMedium(const ComObjPtr<Medium> &pMedium, 3549 3552 ComObjPtr<Medium> *ppMedium, 3550 DeviceType_T argType, 3551 GuidList *pllRegistriesThatNeedSaving) 3553 DeviceType_T argType) 3552 3554 { 3553 3555 AssertReturn(pMedium != NULL, E_INVALIDARG); … … 3622 3624 m->mapHardDisks[id] = pMedium; 3623 3625 3624 if (pllRegistriesThatNeedSaving)3625 pMedium->addToRegistryIDList(*pllRegistriesThatNeedSaving);3626 3627 3626 *ppMedium = pMedium; 3628 3627 } … … 3644 3643 * 3645 3644 * @param pMedium Hard disk object to remove. 3646 * @param pfNeedsGlobalSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true3647 * by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.3648 3645 * 3649 3646 * @note Caller must hold the media tree lock for writing; in addition, this locks @a pMedium for reading 3650 3647 */ 3651 HRESULT VirtualBox::unregisterMedium(Medium *pMedium, 3652 GuidList *pllRegistriesThatNeedSaving) 3648 HRESULT VirtualBox::unregisterMedium(Medium *pMedium) 3653 3649 { 3654 3650 AssertReturn(pMedium != NULL, E_INVALIDARG); … … 3701 3697 } 3702 3698 3703 if (pllRegistriesThatNeedSaving)3704 pMedium->addToRegistryIDList(*pllRegistriesThatNeedSaving);3705 3706 3699 return S_OK; 3707 3700 } … … 3777 3770 Log(("Closing medium %RTuuid\n", pMedium->getId().raw())); 3778 3771 AutoCaller mac(pMedium); 3779 pMedium->close( NULL /* pfNeedsGlobalSaveSettings*/,mac);3772 pMedium->close(mac); 3780 3773 } 3781 3774 … … 3813 3806 * become inaccessible. 3814 3807 */ 3815 GuidList llRegistriesThatNeedSaving;3816 3808 { 3817 3809 AutoReadLock tlock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); … … 3837 3829 pMedium->addRegistry(*puuidBetter, true /* fRecurse */); 3838 3830 // 3) and make sure the registry is saved below 3839 VirtualBox::addGuidToListUniquely(llRegistriesThatNeedSaving,*puuidBetter);3831 markRegistryModified(*puuidBetter); 3840 3832 } 3841 3833 } … … 3843 3835 } 3844 3836 3845 save Registries(llRegistriesThatNeedSaving);3837 saveModifiedRegistries(); 3846 3838 3847 3839 /* fire an event */ … … 3852 3844 3853 3845 /** 3854 * Adds uuid to llRegistriesThatNeedSaving unless it's already on the list. 3855 * 3856 * @todo maybe there's something in libstdc++ for this 3857 * 3858 * @param llRegistriesThatNeedSaving 3846 * Marks the registry for @a uuid as modified, so that it's saved in a later 3847 * call to saveModifiedRegistries(). 3848 * 3859 3849 * @param uuid 3860 3850 */ 3861 /* static */ 3862 void VirtualBox::addGuidToListUniquely(GuidList &llRegistriesThatNeedSaving, 3863 const Guid &uuid) 3864 { 3865 for (GuidList::const_iterator it = llRegistriesThatNeedSaving.begin(); 3866 it != llRegistriesThatNeedSaving.end(); 3867 ++it) 3868 { 3869 if (*it == uuid) 3870 // uuid is already in list: 3871 return; 3872 } 3873 3874 llRegistriesThatNeedSaving.push_back(uuid); 3875 } 3876 3877 /** 3878 * Saves all settings files according to the given list of UUIDs, which are 3879 * either machine IDs (in which case Machine::saveSettings is invoked) or 3880 * the global registry UUID (in which case VirtualBox::saveSettings is invoked). 3851 void VirtualBox::markRegistryModified(const Guid &uuid) 3852 { 3853 if (uuid == getGlobalRegistryId()) 3854 ASMAtomicIncU64(&m->uRegistryNeedsSaving); 3855 else 3856 { 3857 ComObjPtr<Machine> pMachine; 3858 HRESULT rc = findMachine(uuid, 3859 false /* fPermitInaccessible */, 3860 false /* aSetError */, 3861 &pMachine); 3862 if (SUCCEEDED(rc)) 3863 { 3864 AutoCaller machineCaller(pMachine); 3865 if (SUCCEEDED(machineCaller.rc())) 3866 ASMAtomicIncU64(&pMachine->uRegistryNeedsSaving); 3867 } 3868 } 3869 } 3870 3871 /** 3872 * Saves all settings files according to the modified flags in the Machine 3873 * objects and in the VirtualBox object. 3881 3874 * 3882 3875 * This locks machines and the VirtualBox object as necessary, so better not 3883 3876 * hold any locks before calling this. 3884 3877 * 3885 * @param llRegistriesThatNeedSaving3886 3878 * @return 3887 3879 */ 3888 HRESULT VirtualBox::saveRegistries(const GuidList &llRegistriesThatNeedSaving) 3889 { 3880 void VirtualBox::saveModifiedRegistries() 3881 { 3882 HRESULT rc = S_OK; 3890 3883 bool fNeedsGlobalSettings = false; 3891 HRESULT rc = S_OK;3892 3893 for ( GuidList::const_iterator it = llRegistriesThatNeedSaving.begin();3894 it != llRegistriesThatNeedSaving.end();3884 uint64_t uOld; 3885 3886 for (MachinesOList::iterator it = m->allMachines.begin(); 3887 it != m->allMachines.end(); 3895 3888 ++it) 3896 3889 { 3897 const Guid &uuid = *it; 3898 3899 if (uuid == getGlobalRegistryId()) 3900 fNeedsGlobalSettings = true; 3901 else 3902 { 3903 // should be machine ID then: 3904 ComObjPtr<Machine> pMachine; 3905 rc = findMachine(uuid, 3906 false /* fPermitInaccessible */, 3907 false /* aSetError */, 3908 &pMachine); 3909 if (SUCCEEDED(rc)) 3910 { 3911 AutoCaller autoCaller(pMachine); 3912 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3913 AutoWriteLock mlock(pMachine COMMA_LOCKVAL_SRC_POS); 3914 rc = pMachine->saveSettings(&fNeedsGlobalSettings, 3915 Machine::SaveS_Force); // caller said save, so stop arguing 3916 } 3917 3918 if (FAILED(rc)) 3919 return rc; 3920 } 3921 } 3922 3923 if (fNeedsGlobalSettings) 3924 { 3925 AutoWriteLock vlock(this COMMA_LOCKVAL_SRC_POS); 3890 const ComObjPtr<Machine> &pMachine = *it; 3891 3892 for (;;) 3893 { 3894 uOld = ASMAtomicReadU64(&pMachine->uRegistryNeedsSaving); 3895 if (!uOld) 3896 break; 3897 if (ASMAtomicCmpXchgU64(&pMachine->uRegistryNeedsSaving, 0, uOld)) 3898 break; 3899 ASMNopPause(); 3900 } 3901 if (uOld) 3902 { 3903 AutoCaller autoCaller(pMachine); 3904 if (FAILED(autoCaller.rc())) continue; 3905 AutoWriteLock mlock(pMachine COMMA_LOCKVAL_SRC_POS); 3906 rc = pMachine->saveSettings(&fNeedsGlobalSettings, 3907 Machine::SaveS_Force); // caller said save, so stop arguing 3908 } 3909 } 3910 3911 for (;;) 3912 { 3913 uOld = ASMAtomicReadU64(&m->uRegistryNeedsSaving); 3914 if (!uOld) 3915 break; 3916 if (ASMAtomicCmpXchgU64(&m->uRegistryNeedsSaving, 0, uOld)) 3917 break; 3918 ASMNopPause(); 3919 } 3920 if (uOld || fNeedsGlobalSettings) 3921 { 3922 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3926 3923 rc = saveSettings(); 3927 3924 } 3928 3929 return S_OK;3930 3925 } 3931 3926
Note:
See TracChangeset
for help on using the changeset viewer.