Changeset 51498 in vbox for trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
- Timestamp:
- Jun 2, 2014 6:53:08 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 94109
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
r50899 r51498 6 6 7 7 /* 8 * Copyright (C) 2006-201 3Oracle Corporation8 * Copyright (C) 2006-2014 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 329 329 m->strName = aName; 330 330 alock.release(); /* Important! (child->parent locks are forbidden) */ 331 rc = m->pMachine-> onSnapshotChange(this);331 rc = m->pMachine->i_onSnapshotChange(this); 332 332 } 333 333 … … 351 351 m->strDescription = aDescription; 352 352 alock.release(); /* Important! (child->parent locks are forbidden) */ 353 rc = m->pMachine-> onSnapshotChange(this);353 rc = m->pMachine->i_onSnapshotChange(this); 354 354 } 355 355 … … 746 746 // state file (only if this snapshot is online) 747 747 if (i_getStateFilePath().isNotEmpty()) 748 m->pMachine-> copyPathRelativeToMachine(i_getStateFilePath(), data.strStateFile);748 m->pMachine->i_copyPathRelativeToMachine(i_getStateFilePath(), data.strStateFile); 749 749 else 750 750 data.strStateFile.setNull(); 751 751 752 HRESULT rc = m->pMachine-> saveHardware(data.hardware, &data.debugging, &data.autostart);752 HRESULT rc = m->pMachine->i_saveHardware(data.hardware, &data.debugging, &data.autostart); 753 753 if (FAILED(rc)) return rc; 754 754 755 rc = m->pMachine-> saveStorageControllers(data.storage);755 rc = m->pMachine->i_saveStorageControllers(data.storage); 756 756 if (FAILED(rc)) return rc; 757 757 … … 858 858 859 859 // now call detachAllMedia on the snapshot machine 860 rc = m->pMachine-> detachAllMedia(writeLock,861 this /* pSnapshot */,862 cleanupMode,863 llMedia);860 rc = m->pMachine->i_detachAllMedia(writeLock, 861 this /* pSnapshot */, 862 cleanupMode, 863 llMedia); 864 864 if (FAILED(rc)) 865 865 return rc; … … 1168 1168 /* load hardware and harddisk settings */ 1169 1169 1170 HRESULT rc = loadHardware(hardware, pDbg, pAutostart);1170 HRESULT rc = i_loadHardware(hardware, pDbg, pAutostart); 1171 1171 if (SUCCEEDED(rc)) 1172 rc = loadStorageControllers(storage,1173 NULL, /* puuidRegistry */1174 &mSnapshotId);1172 rc = i_loadStorageControllers(storage, 1173 NULL, /* puuidRegistry */ 1174 &mSnapshotId); 1175 1175 1176 1176 if (SUCCEEDED(rc)) 1177 1177 /* commit all changes made during the initialization */ 1178 commit(); /// @todo r=dj why do we need a commit in init?!? this is very expensive1178 i_commit(); /// @todo r=dj why do we need a commit in init?!? this is very expensive 1179 1179 /// @todo r=klaus for some reason the settings loading logic backs up 1180 1180 // the settings, and therefore a commit is needed. Should probably be changed. … … 1234 1234 * @warning Caller must hold no locks when calling this. 1235 1235 */ 1236 HRESULT SnapshotMachine:: onSnapshotChange(Snapshot *aSnapshot)1236 HRESULT SnapshotMachine::i_onSnapshotChange(Snapshot *aSnapshot) 1237 1237 { 1238 1238 AutoMultiWriteLock2 mlock(this, aSnapshot COMMA_LOCKVAL_SRC_POS); … … 1244 1244 * modification of the current state flag, cause this snapshot data isn't 1245 1245 * related to the current state. */ 1246 mMachine-> setModified(Machine::IsModified_Snapshots, false /* fAllowStateModification */);1247 HRESULT rc = mMachine-> saveSettings(&fNeedsGlobalSaveSettings,1248 SaveS_Force); // we know we need saving, no need to check1246 mMachine->i_setModified(Machine::IsModified_Snapshots, false /* fAllowStateModification */); 1247 HRESULT rc = mMachine->i_saveSettings(&fNeedsGlobalSaveSettings, 1248 SaveS_Force); // we know we need saving, no need to check 1249 1249 mlock.release(); 1250 1250 … … 1312 1312 void handler() 1313 1313 { 1314 pMachine-> restoreSnapshotHandler(*this);1314 pMachine->i_restoreSnapshotHandler(*this); 1315 1315 } 1316 1316 }; … … 1330 1330 void handler() 1331 1331 { 1332 pMachine-> deleteSnapshotHandler(*this);1332 pMachine->i_deleteSnapshotHandler(*this); 1333 1333 } 1334 1334 … … 1434 1434 /* save all current settings to ensure current changes are committed and 1435 1435 * hard disks are fixed up */ 1436 HRESULT rc = saveSettings(NULL);1436 HRESULT rc = i_saveSettings(NULL); 1437 1437 // no need to check for whether VirtualBox.xml needs changing since 1438 1438 // we can't have a machine XML rename pending at this point … … 1454 1454 { 1455 1455 // creating a new online snapshot: we need a fresh saved state file 1456 composeSavedStateFilename(strStateFilePath);1456 i_composeSavedStateFilename(strStateFilePath); 1457 1457 } 1458 1458 } … … 1502 1502 // backup the media data so we can recover if things goes wrong along the day; 1503 1503 // the matching commit() is in fixupMedia() during endSnapshot() 1504 setModified(IsModified_Storage);1504 i_setModified(IsModified_Storage); 1505 1505 mMediaData.backup(); 1506 1506 1507 1507 /* Console::fntTakeSnapshotWorker and friends expects this. */ 1508 1508 if (mConsoleTaskData.mLastState == MachineState_Running) 1509 setMachineState(MachineState_LiveSnapshotting);1509 i_setMachineState(MachineState_LiveSnapshotting); 1510 1510 else 1511 setMachineState(MachineState_Saving); /** @todo Confusing! Saving is used for both online and offline snapshots. */1511 i_setMachineState(MachineState_Saving); /** @todo Confusing! Saving is used for both online and offline snapshots. */ 1512 1512 1513 1513 alock.release(); 1514 1514 /* create new differencing hard disks and attach them to this machine */ 1515 rc = createImplicitDiffs(aConsoleProgress,1516 1, // operation weight; must be the same as in Console::TakeSnapshot()1517 !!fTakingSnapshotOnline);1515 rc = i_createImplicitDiffs(aConsoleProgress, 1516 1, // operation weight; must be the same as in Console::TakeSnapshot() 1517 !!fTakingSnapshotOnline); 1518 1518 if (FAILED(rc)) 1519 1519 throw rc; … … 1531 1531 : mData->mMachineState == MachineState_Saving) 1532 1532 ) 1533 setMachineState(mConsoleTaskData.mLastState);1533 i_setMachineState(mConsoleTaskData.mLastState); 1534 1534 1535 1535 pSnapshot->uninit(); … … 1592 1592 && mConsoleTaskData.mLastState != MachineState_Running 1593 1593 ) 1594 setMachineState(mConsoleTaskData.mLastState);1594 i_setMachineState(mConsoleTaskData.mLastState); 1595 1595 1596 1596 ComObjPtr<Snapshot> pOldFirstSnap = mData->mFirstSnapshot; … … 1617 1617 flSaveSettings |= SaveS_ResetCurStateModified; 1618 1618 1619 rc = saveSettings(NULL, flSaveSettings);1619 rc = i_saveSettings(NULL, flSaveSettings); 1620 1620 } 1621 1621 … … 1623 1623 { 1624 1624 /* associate old hard disks with the snapshot and do locking/unlocking*/ 1625 commitMedia(fOnline);1625 i_commitMedia(fOnline); 1626 1626 1627 1627 /* inform callbacks */ … … 1636 1636 machineLock.release(); 1637 1637 1638 rollbackMedia();1638 i_rollbackMedia(); 1639 1639 1640 1640 mData->mFirstSnapshot = pOldFirstSnap; // might have been changed above … … 1766 1766 1767 1767 /* set the proper machine state (note: after creating a Task instance) */ 1768 setMachineState(MachineState_RestoringSnapshot);1768 i_setMachineState(MachineState_RestoringSnapshot); 1769 1769 1770 1770 /* return the progress to the caller */ … … 1791 1791 * @param aTask Task data. 1792 1792 */ 1793 void SessionMachine:: restoreSnapshotHandler(RestoreSnapshotTask &aTask)1793 void SessionMachine::i_restoreSnapshotHandler(RestoreSnapshotTask &aTask) 1794 1794 { 1795 1795 LogFlowThisFuncEnter(); … … 1823 1823 * the direct session. */ 1824 1824 if (mData->flModifications) 1825 rollback(false /* aNotify */);1825 i_rollback(false /* aNotify */); 1826 1826 1827 1827 /* Delete the saved state file if the machine was Saved prior to this … … 1835 1835 Utf8Str strStateFile(mSSData->strStateFilePath); 1836 1836 mSSData->strStateFilePath.setNull(); 1837 releaseSavedStateFile(strStateFile, NULL /* pSnapshotToIgnore */ );1837 i_releaseSavedStateFile(strStateFile, NULL /* pSnapshotToIgnore */ ); 1838 1838 1839 1839 aTask.modifyBackedUpState(MachineState_PoweredOff); 1840 1840 1841 rc = saveStateSettings(SaveSTS_StateFilePath);1841 rc = i_saveStateSettings(SaveSTS_StateFilePath); 1842 1842 if (FAILED(rc)) 1843 1843 throw rc; … … 1856 1856 1857 1857 /* copy all hardware data from the snapshot */ 1858 copyFrom(pSnapshotMachine);1858 i_copyFrom(pSnapshotMachine); 1859 1859 1860 1860 LogFlowThisFunc(("Restoring hard disks from the snapshot...\n")); 1861 1861 1862 1862 // restore the attachments from the snapshot 1863 setModified(IsModified_Storage);1863 i_setModified(IsModified_Storage); 1864 1864 mMediaData.backup(); 1865 1865 mMediaData->mAttachments.clear(); … … 1878 1878 alock.release(); 1879 1879 1880 rc = createImplicitDiffs(aTask.pProgress,1881 1,1882 false /* aOnline */);1880 rc = i_createImplicitDiffs(aTask.pProgress, 1881 1, 1882 false /* aOnline */); 1883 1883 if (FAILED(rc)) 1884 1884 throw rc; … … 1934 1934 * state accordingly no matter of the delete snapshot result */ 1935 1935 if (mSSData->strStateFilePath.isNotEmpty()) 1936 setMachineState(MachineState_Saved);1936 i_setMachineState(MachineState_Saved); 1937 1937 else 1938 setMachineState(MachineState_PoweredOff);1939 1940 updateMachineStateOnClient();1938 i_setMachineState(MachineState_PoweredOff); 1939 1940 i_updateMachineStateOnClient(); 1941 1941 stateRestored = true; 1942 1942 … … 1986 1986 // save machine settings, reset the modified flag and commit; 1987 1987 bool fNeedsGlobalSaveSettings = false; 1988 rc = saveSettings(&fNeedsGlobalSaveSettings,1989 SaveS_ResetCurStateModified);1988 rc = i_saveSettings(&fNeedsGlobalSaveSettings, 1989 SaveS_ResetCurStateModified); 1990 1990 if (FAILED(rc)) 1991 1991 throw rc; … … 2025 2025 2026 2026 /* undo all changes on failure */ 2027 rollback(false /* aNotify */);2027 i_rollback(false /* aNotify */); 2028 2028 2029 2029 if (!stateRestored) 2030 2030 { 2031 2031 /* restore the machine state */ 2032 setMachineState(aTask.machineStateBackup);2033 updateMachineStateOnClient();2032 i_setMachineState(aTask.machineStateBackup); 2033 i_updateMachineStateOnClient(); 2034 2034 } 2035 2035 } … … 2108 2108 2109 2109 ComObjPtr<Snapshot> pSnapshot; 2110 HRESULT rc = findSnapshotById(startId, pSnapshot, true /* aSetError */);2110 HRESULT rc = i_findSnapshotById(startId, pSnapshot, true /* aSetError */); 2111 2111 if (FAILED(rc)) return rc; 2112 2112 … … 2135 2135 if (mData->flModifications) 2136 2136 { 2137 rc = saveSettings(NULL);2137 rc = i_saveSettings(NULL); 2138 2138 // no need to change for whether VirtualBox.xml needs saving since 2139 2139 // we can't have a machine XML rename pending at this point … … 2219 2219 // set the proper machine state here now (note: after creating a Task instance) 2220 2220 if (mData->mMachineState == MachineState_Running) 2221 setMachineState(MachineState_DeletingSnapshotOnline);2221 i_setMachineState(MachineState_DeletingSnapshotOnline); 2222 2222 else if (mData->mMachineState == MachineState_Paused) 2223 setMachineState(MachineState_DeletingSnapshotPaused);2223 i_setMachineState(MachineState_DeletingSnapshotPaused); 2224 2224 else 2225 setMachineState(MachineState_DeletingSnapshot);2225 i_setMachineState(MachineState_DeletingSnapshot); 2226 2226 2227 2227 /* return the progress to the caller */ … … 2332 2332 */ 2333 2333 2334 void SessionMachine:: deleteSnapshotHandler(DeleteSnapshotTask &aTask)2334 void SessionMachine::i_deleteSnapshotHandler(DeleteSnapshotTask &aTask) 2335 2335 { 2336 2336 LogFlowThisFuncEnter(); … … 2369 2369 ComObjPtr<SnapshotMachine> pSnapMachine = aTask.pSnapshot->i_getSnapshotMachine(); 2370 2370 // no need to lock the snapshot machine since it is const by definition 2371 Guid machineId = pSnapMachine-> getId();2371 Guid machineId = pSnapMachine->i_getId(); 2372 2372 2373 2373 // save the snapshot ID (for callbacks) … … 2429 2429 // prevent online merging in general. 2430 2430 pOnlineMediumAttachment = 2431 findAttachment(mMediaData->mAttachments,2432 pAttach->i_getControllerName().raw(),2433 pAttach->i_getPort(),2434 pAttach->i_getDevice());2431 i_findAttachment(mMediaData->mAttachments, 2432 pAttach->i_getControllerName().raw(), 2433 pAttach->i_getPort(), 2434 pAttach->i_getDevice()); 2435 2435 if (pOnlineMediumAttachment) 2436 2436 { … … 2448 2448 2449 2449 treeLock.release(); 2450 rc = prepareDeleteSnapshotMedium(pHD, machineId, snapshotId,2451 fOnlineMergePossible,2452 pVMMALockList, pSource, pTarget,2453 fMergeForward, pParentForTarget,2454 pChildrenToReparent,2455 fNeedsOnlineMerge,2456 pMediumLockList,2457 pHDLockToken);2450 rc = i_prepareDeleteSnapshotMedium(pHD, machineId, snapshotId, 2451 fOnlineMergePossible, 2452 pVMMALockList, pSource, pTarget, 2453 fMergeForward, pParentForTarget, 2454 pChildrenToReparent, 2455 fNeedsOnlineMerge, 2456 pMediumLockList, 2457 pHDLockToken); 2458 2458 treeLock.acquire(); 2459 2459 if (FAILED(rc)) … … 2660 2660 1); // weight 2661 2661 2662 releaseSavedStateFile(stateFilePath, aTask.pSnapshot /* pSnapshotToIgnore */);2662 i_releaseSavedStateFile(stateFilePath, aTask.pSnapshot /* pSnapshotToIgnore */); 2663 2663 2664 2664 // machine will need saving now 2665 2665 machineLock.release(); 2666 mParent->i_markRegistryModified( getId());2666 mParent->i_markRegistryModified(i_getId()); 2667 2667 } 2668 2668 } … … 2730 2730 mConsoleTaskData.mDeleteSnapshotInfo = (void *)&(*it); 2731 2731 // online medium merge, in the direction decided earlier 2732 rc = onlineMergeMedium(it->mpOnlineMediumAttachment,2733 it->mpSource,2734 it->mpTarget,2735 it->mfMergeForward,2736 it->mpParentForTarget,2737 it->mpChildrenToReparent,2738 it->mpMediumLockList,2739 aTask.pProgress,2740 &fNeedsSave);2732 rc = i_onlineMergeMedium(it->mpOnlineMediumAttachment, 2733 it->mpSource, 2734 it->mpTarget, 2735 it->mfMergeForward, 2736 it->mpParentForTarget, 2737 it->mpChildrenToReparent, 2738 it->mpMediumLockList, 2739 aTask.pProgress, 2740 &fNeedsSave); 2741 2741 mConsoleTaskData.mDeleteSnapshotInfo = NULL; 2742 2742 } … … 2799 2799 if (fReparentTarget) 2800 2800 { 2801 pAtt = findAttachment(pSnapMachine->mMediaData->mAttachments,2802 it->mpTarget);2801 pAtt = i_findAttachment(pSnapMachine->mMediaData->mAttachments, 2802 it->mpTarget); 2803 2803 it->mpTarget->i_removeBackReference(machineId, snapshotId); 2804 2804 } 2805 2805 else 2806 pAtt = findAttachment(pSnapMachine->mMediaData->mAttachments,2807 it->mpSource);2806 pAtt = i_findAttachment(pSnapMachine->mMediaData->mAttachments, 2807 it->mpSource); 2808 2808 pSnapMachine->mMediaData->mAttachments.remove(pAtt); 2809 2809 … … 2820 2820 childSnapshotId = pChildSnapshot->i_getId(); 2821 2821 } 2822 pAtt = findAttachment(pMachine->mMediaData->mAttachments, it->mpSource);2822 pAtt = i_findAttachment(pMachine->mMediaData->mAttachments, it->mpSource); 2823 2823 if (pAtt) 2824 2824 { … … 2843 2843 2844 2844 // One attachment is merged, must save the settings 2845 mParent->i_markRegistryModified( getId());2845 mParent->i_markRegistryModified(i_getId()); 2846 2846 2847 2847 // prevent calling cancelDeleteSnapshotMedium() for this attachment … … 2863 2863 2864 2864 machineLock.release(); 2865 mParent->i_markRegistryModified( getId());2865 mParent->i_markRegistryModified(i_getId()); 2866 2866 } 2867 2867 } … … 2884 2884 it != toDelete.end(); 2885 2885 ++it) 2886 { 2887 cancelDeleteSnapshotMedium(it->mpHD, it->mpSource, 2888 it->mpChildrenToReparent, 2889 it->mfNeedsOnlineMerge, 2890 it->mpMediumLockList, it->mpHDLockToken, 2891 it->mMachineId, it->mSnapshotId); 2892 } 2886 i_cancelDeleteSnapshotMedium(it->mpHD, it->mpSource, 2887 it->mpChildrenToReparent, 2888 it->mfNeedsOnlineMerge, 2889 it->mpMediumLockList, it->mpHDLockToken, 2890 it->mMachineId, it->mSnapshotId); 2893 2891 } 2894 2892 … … 2902 2900 // restore the machine state that was saved when the 2903 2901 // task was started 2904 setMachineState(aTask.machineStateBackup);2905 updateMachineStateOnClient();2902 i_setMachineState(aTask.machineStateBackup); 2903 i_updateMachineStateOnClient(); 2906 2904 2907 2905 mParent->i_saveModifiedRegistries(); … … 2954 2952 * and every medium object on the merge chain for writing. 2955 2953 */ 2956 HRESULT SessionMachine:: prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,2957 const Guid &aMachineId,2958 const Guid &aSnapshotId,2959 bool fOnlineMergePossible,2960 MediumLockList *aVMMALockList,2961 ComObjPtr<Medium> &aSource,2962 ComObjPtr<Medium> &aTarget,2963 bool &aMergeForward,2964 ComObjPtr<Medium> &aParentForTarget,2965 MediumLockList * &aChildrenToReparent,2966 bool &fNeedsOnlineMerge,2967 MediumLockList * &aMediumLockList,2968 ComPtr<IToken> &aHDLockToken)2954 HRESULT SessionMachine::i_prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD, 2955 const Guid &aMachineId, 2956 const Guid &aSnapshotId, 2957 bool fOnlineMergePossible, 2958 MediumLockList *aVMMALockList, 2959 ComObjPtr<Medium> &aSource, 2960 ComObjPtr<Medium> &aTarget, 2961 bool &aMergeForward, 2962 ComObjPtr<Medium> &aParentForTarget, 2963 MediumLockList * &aChildrenToReparent, 2964 bool &fNeedsOnlineMerge, 2965 MediumLockList * &aMediumLockList, 2966 ComPtr<IToken> &aHDLockToken) 2969 2967 { 2970 2968 Assert(!mParent->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread()); … … 3247 3245 * @note Locks the medium tree and the hard disks in the chain for writing. 3248 3246 */ 3249 void SessionMachine:: cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,3250 const ComObjPtr<Medium> &aSource,3251 MediumLockList *aChildrenToReparent,3252 bool fNeedsOnlineMerge,3253 MediumLockList *aMediumLockList,3254 const ComPtr<IToken> &aHDLockToken,3255 const Guid &aMachineId,3256 const Guid &aSnapshotId)3247 void SessionMachine::i_cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD, 3248 const ComObjPtr<Medium> &aSource, 3249 MediumLockList *aChildrenToReparent, 3250 bool fNeedsOnlineMerge, 3251 MediumLockList *aMediumLockList, 3252 const ComPtr<IToken> &aHDLockToken, 3253 const Guid &aMachineId, 3254 const Guid &aSnapshotId) 3257 3255 { 3258 3256 if (aMediumLockList == NULL) … … 3343 3341 * @param pfNeedsMachineSaveSettings Whether the VM settings need to be saved (out). 3344 3342 */ 3345 HRESULT SessionMachine:: onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,3346 const ComObjPtr<Medium> &aSource,3347 const ComObjPtr<Medium> &aTarget,3348 bool fMergeForward,3349 const ComObjPtr<Medium> &aParentForTarget,3350 MediumLockList *aChildrenToReparent,3351 MediumLockList *aMediumLockList,3352 ComObjPtr<Progress> &aProgress,3353 bool *pfNeedsMachineSaveSettings)3343 HRESULT SessionMachine::i_onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment, 3344 const ComObjPtr<Medium> &aSource, 3345 const ComObjPtr<Medium> &aTarget, 3346 bool fMergeForward, 3347 const ComObjPtr<Medium> &aParentForTarget, 3348 MediumLockList *aChildrenToReparent, 3349 MediumLockList *aMediumLockList, 3350 ComObjPtr<Progress> &aProgress, 3351 bool *pfNeedsMachineSaveSettings) 3354 3352 { 3355 3353 AssertReturn(aSource != NULL, E_FAIL);
Note:
See TracChangeset
for help on using the changeset viewer.