Changeset 76298 in vbox for trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
- Timestamp:
- Dec 19, 2018 6:17:50 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 127586
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
r76240 r76298 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 #include <set> 19 #include <map> 17 20 18 21 #include "Logging.h" … … 1637 1640 BOOL fSuspendedBySave = FALSE; 1638 1641 1642 std::set<ComObjPtr<Medium> > pMediumsForNotify; 1643 std::map<Guid, DeviceType_T> uIdsForNotify; 1644 1639 1645 try 1640 1646 { … … 1773 1779 if (FAILED(rc)) 1774 1780 throw rc; 1781 } 1782 1783 // store parent of newly created diffs before commit for notify 1784 { 1785 MediumAttachmentList &oldAtts = *mMediumAttachments.backedUpData(); 1786 for (MediumAttachmentList::const_iterator 1787 it = mMediumAttachments->begin(); 1788 it != mMediumAttachments->end(); 1789 ++it) 1790 { 1791 MediumAttachment *pAttach = *it; 1792 Medium *pMedium = pAttach->i_getMedium(); 1793 if (!pMedium) 1794 continue; 1795 1796 bool fFound = false; 1797 /* was this medium attached before? */ 1798 for (MediumAttachmentList::iterator 1799 oldIt = oldAtts.begin(); 1800 oldIt != oldAtts.end(); 1801 ++oldIt) 1802 { 1803 MediumAttachment *pOldAttach = *oldIt; 1804 if (pOldAttach->i_getMedium() == pMedium) 1805 { 1806 fFound = true; 1807 break; 1808 } 1809 } 1810 if (!fFound) 1811 { 1812 pMediumsForNotify.insert(pMedium->i_getParent()); 1813 uIdsForNotify[pMedium->i_getId()] = pMedium->i_getDeviceType(); 1814 } 1815 } 1775 1816 } 1776 1817 … … 1876 1917 if (SUCCEEDED(rc)) 1877 1918 mParent->i_onSnapshotTaken(mData->mUuid, task.m_uuidSnapshot); 1919 1920 if (SUCCEEDED(rc)) 1921 { 1922 for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin(); 1923 it != uIdsForNotify.end(); 1924 ++it) 1925 { 1926 mParent->i_onMediumRegistered(it->first, it->second, TRUE); 1927 } 1928 1929 for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin(); 1930 it != pMediumsForNotify.end(); 1931 ++it) 1932 { 1933 if (it->isNotNull()) 1934 mParent->i_onMediumConfigChanged(*it); 1935 } 1936 } 1878 1937 LogFlowThisFuncLeave(); 1879 1938 } … … 2120 2179 HRESULT rc = S_OK; 2121 2180 Guid snapshotId; 2181 std::set<ComObjPtr<Medium> > pMediumsForNotify; 2182 std::map<Guid, DeviceType_T> uIdsForNotify; 2122 2183 2123 2184 try … … 2214 2275 /* make the snapshot we restored from the current snapshot */ 2215 2276 mData->mCurrentSnapshot = task.m_pSnapshot; 2277 } 2278 2279 // store parent of newly created diffs for notify 2280 { 2281 MediumAttachmentList &oldAtts = *mMediumAttachments.backedUpData(); 2282 for (MediumAttachmentList::const_iterator 2283 it = mMediumAttachments->begin(); 2284 it != mMediumAttachments->end(); 2285 ++it) 2286 { 2287 MediumAttachment *pAttach = *it; 2288 Medium *pMedium = pAttach->i_getMedium(); 2289 if (!pMedium) 2290 continue; 2291 2292 bool fFound = false; 2293 /* was this medium attached before? */ 2294 for (MediumAttachmentList::iterator 2295 oldIt = oldAtts.begin(); 2296 oldIt != oldAtts.end(); 2297 ++oldIt) 2298 { 2299 MediumAttachment *pOldAttach = *oldIt; 2300 if (pOldAttach->i_getMedium() == pMedium) 2301 { 2302 fFound = true; 2303 break; 2304 } 2305 } 2306 if (!fFound) 2307 { 2308 pMediumsForNotify.insert(pMedium->i_getParent()); 2309 uIdsForNotify[pMedium->i_getId()] = pMedium->i_getDeviceType(); 2310 } 2311 } 2216 2312 } 2217 2313 … … 2314 2410 LogFlowThisFunc(("Deleting old current state in differencing image '%s'\n", pMedium->i_getName().c_str())); 2315 2411 2412 ComObjPtr<Medium> pParent = pMedium->i_getParent(); 2316 2413 HRESULT rc2 = pMedium->i_deleteStorage(NULL /* aProgress */, 2317 true /* aWait */); 2414 true /* aWait */, 2415 false /* aNotify */); 2318 2416 // ignore errors here because we cannot roll back after i_saveSettings() above 2319 2417 if (SUCCEEDED(rc2)) 2418 { 2419 pMediumsForNotify.insert(pParent); 2320 2420 pMedium->uninit(); 2421 } 2321 2422 } 2322 2423 } … … 2345 2446 2346 2447 if (SUCCEEDED(rc)) 2448 { 2347 2449 mParent->i_onSnapshotRestored(mData->mUuid, snapshotId); 2450 for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin(); 2451 it != uIdsForNotify.end(); 2452 ++it) 2453 { 2454 mParent->i_onMediumRegistered(it->first, it->second, TRUE); 2455 } 2456 for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin(); 2457 it != pMediumsForNotify.end(); 2458 ++it) 2459 { 2460 if (it->isNotNull()) 2461 mParent->i_onMediumConfigChanged(*it); 2462 } 2463 } 2348 2464 2349 2465 LogFlowThisFunc(("Done restoring snapshot (rc=%08X)\n", rc)); … … 2696 2812 MediumDeleteRecList toDelete; 2697 2813 Guid snapshotId; 2814 std::set<ComObjPtr<Medium> > pMediumsForNotify; 2815 std::map<Guid,DeviceType_T> uIdsForNotify; 2698 2816 2699 2817 try … … 3070 3188 /* No need to hold the lock any longer. */ 3071 3189 mLock.release(); 3190 ComObjPtr<Medium> pParent = pMedium->i_getParent(); 3191 Guid uMedium = pMedium->i_getId(); 3192 DeviceType_T uMediumType = pMedium->i_getDeviceType(); 3072 3193 rc = pMedium->i_deleteStorage(&task.m_pProgress, 3073 true /* aWait */); 3194 true /* aWait */, 3195 false /* aNotify */); 3074 3196 if (FAILED(rc)) 3075 3197 throw rc; 3198 3199 pMediumsForNotify.insert(pParent); 3200 uIdsForNotify[uMedium] = uMediumType; 3076 3201 3077 3202 // need to uninit the deleted medium … … 3081 3206 else 3082 3207 { 3208 { 3209 //store ids before merging for notify 3210 pMediumsForNotify.insert(it->mpTarget); 3211 if (it->mfMergeForward) 3212 pMediumsForNotify.insert(it->mpSource->i_getParent()); 3213 else 3214 { 3215 //children which will be reparented to target 3216 for (MediaList::const_iterator iit = it->mpSource->i_getChildren().begin(); 3217 iit != it->mpSource->i_getChildren().end(); 3218 ++iit) 3219 { 3220 pMediumsForNotify.insert(*iit); 3221 } 3222 } 3223 if (it->mfMergeForward) 3224 { 3225 for (ComObjPtr<Medium> pTmpMedium = it->mpTarget->i_getParent(); 3226 pTmpMedium && pTmpMedium != it->mpSource; 3227 pTmpMedium = pTmpMedium->i_getParent()) 3228 { 3229 uIdsForNotify[pTmpMedium->i_getId()] = pTmpMedium->i_getDeviceType(); 3230 } 3231 uIdsForNotify[it->mpSource->i_getId()] = it->mpSource->i_getDeviceType(); 3232 } 3233 else 3234 { 3235 for (ComObjPtr<Medium> pTmpMedium = it->mpSource->i_getParent(); 3236 pTmpMedium && pTmpMedium != it->mpTarget; 3237 pTmpMedium = pTmpMedium->i_getParent()) 3238 { 3239 uIdsForNotify[pTmpMedium->i_getId()] = pTmpMedium->i_getDeviceType(); 3240 } 3241 } 3242 } 3243 3083 3244 bool fNeedsSave = false; 3084 3245 if (it->mfNeedsOnlineMerge) … … 3111 3272 it->mpMediumLockList, 3112 3273 &task.m_pProgress, 3113 true /* aWait */); 3274 true /* aWait */, 3275 false /* aNotify */); 3114 3276 } 3115 3277 … … 3278 3440 3279 3441 if (SUCCEEDED(mrc)) 3442 { 3280 3443 mParent->i_onSnapshotDeleted(mData->mUuid, snapshotId); 3444 for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin(); 3445 it != uIdsForNotify.end(); 3446 ++it) 3447 { 3448 mParent->i_onMediumRegistered(it->first, it->second, FALSE); 3449 } 3450 for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin(); 3451 it != pMediumsForNotify.end(); 3452 ++it) 3453 { 3454 if (it->isNotNull()) 3455 mParent->i_onMediumConfigChanged(*it); 3456 } 3457 } 3281 3458 3282 3459 LogFlowThisFunc(("Done deleting snapshot (rc=%08X)\n", (HRESULT)mrc)); … … 3972 4149 return S_OK; 3973 4150 } 3974
Note:
See TracChangeset
for help on using the changeset viewer.