Changeset 76215 in vbox for trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
- Timestamp:
- Dec 13, 2018 6:58:16 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 127481
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
r75373 r76215 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 1794 bool fFound = false; 1795 /* was this medium attached before? */ 1796 for (MediumAttachmentList::iterator 1797 oldIt = oldAtts.begin(); 1798 oldIt != oldAtts.end(); 1799 ++oldIt) 1800 { 1801 MediumAttachment *pOldAttach = *oldIt; 1802 if (pOldAttach->i_getMedium() == pMedium) 1803 { 1804 fFound = true; 1805 break; 1806 } 1807 } 1808 if (!fFound) 1809 { 1810 pMediumsForNotify.insert(pMedium->i_getParent()); 1811 uIdsForNotify[pMedium->i_getId()] = pMedium->i_getDeviceType(); 1812 } 1813 } 1775 1814 } 1776 1815 … … 1877 1916 mParent->i_onSnapshotTaken(mData->mUuid, task.m_uuidSnapshot); 1878 1917 LogFlowThisFuncLeave(); 1918 1919 if (SUCCEEDED(rc)) 1920 { 1921 for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin(); 1922 it != uIdsForNotify.end(); 1923 ++it) 1924 { 1925 mParent->i_onMediumRegistered(it->first, it->second, TRUE); 1926 } 1927 1928 for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin(); 1929 it != pMediumsForNotify.end(); 1930 ++it) 1931 { 1932 if (it->isNotNull()) 1933 mParent->i_onMediumConfigChanged(*it); 1934 } 1935 } 1879 1936 } 1880 1937 … … 2120 2177 HRESULT rc = S_OK; 2121 2178 Guid snapshotId; 2179 std::set<ComObjPtr<Medium> > pMediumsForNotify; 2180 std::map<Guid, DeviceType_T> uIdsForNotify; 2122 2181 2123 2182 try … … 2214 2273 /* make the snapshot we restored from the current snapshot */ 2215 2274 mData->mCurrentSnapshot = task.m_pSnapshot; 2275 } 2276 2277 // store parent of newly created diffs for notify 2278 { 2279 MediumAttachmentList &oldAtts = *mMediumAttachments.backedUpData(); 2280 for (MediumAttachmentList::const_iterator 2281 it = mMediumAttachments->begin(); 2282 it != mMediumAttachments->end(); 2283 ++it) 2284 { 2285 MediumAttachment *pAttach = *it; 2286 Medium *pMedium = pAttach->i_getMedium(); 2287 2288 bool fFound = false; 2289 /* was this medium attached before? */ 2290 for (MediumAttachmentList::iterator 2291 oldIt = oldAtts.begin(); 2292 oldIt != oldAtts.end(); 2293 ++oldIt) 2294 { 2295 MediumAttachment *pOldAttach = *oldIt; 2296 if (pOldAttach->i_getMedium() == pMedium) 2297 { 2298 fFound = true; 2299 break; 2300 } 2301 } 2302 if (!fFound) 2303 { 2304 pMediumsForNotify.insert(pMedium->i_getParent()); 2305 uIdsForNotify[pMedium->i_getId()] = pMedium->i_getDeviceType(); 2306 } 2307 } 2216 2308 } 2217 2309 … … 2314 2406 LogFlowThisFunc(("Deleting old current state in differencing image '%s'\n", pMedium->i_getName().c_str())); 2315 2407 2408 ComObjPtr<Medium> pParent = pMedium->i_getParent(); 2316 2409 HRESULT rc2 = pMedium->i_deleteStorage(NULL /* aProgress */, 2317 true /* aWait */); 2410 true /* aWait */, 2411 false /* aNotify */); 2318 2412 // ignore errors here because we cannot roll back after i_saveSettings() above 2319 2413 if (SUCCEEDED(rc2)) 2414 { 2415 pMediumsForNotify.insert(pParent); 2320 2416 pMedium->uninit(); 2417 } 2321 2418 } 2322 2419 } … … 2345 2442 2346 2443 if (SUCCEEDED(rc)) 2444 { 2347 2445 mParent->i_onSnapshotRestored(mData->mUuid, snapshotId); 2446 for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin(); 2447 it != uIdsForNotify.end(); 2448 ++it) 2449 { 2450 mParent->i_onMediumRegistered(it->first, it->second, TRUE); 2451 } 2452 for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin(); 2453 it != pMediumsForNotify.end(); 2454 ++it) 2455 { 2456 if (it->isNotNull()) 2457 mParent->i_onMediumConfigChanged(*it); 2458 } 2459 } 2348 2460 2349 2461 LogFlowThisFunc(("Done restoring snapshot (rc=%08X)\n", rc)); … … 2696 2808 MediumDeleteRecList toDelete; 2697 2809 Guid snapshotId; 2810 std::set<ComObjPtr<Medium> > pMediumsForNotify; 2811 std::map<Guid,DeviceType_T> uIdsForNotify; 2698 2812 2699 2813 try … … 3070 3184 /* No need to hold the lock any longer. */ 3071 3185 mLock.release(); 3186 ComObjPtr<Medium> pParent = pMedium->i_getParent(); 3187 Guid uMedium = pMedium->i_getId(); 3188 DeviceType_T uMediumType = pMedium->i_getDeviceType(); 3072 3189 rc = pMedium->i_deleteStorage(&task.m_pProgress, 3073 true /* aWait */); 3190 true /* aWait */, 3191 false /* aNotify */); 3074 3192 if (FAILED(rc)) 3075 3193 throw rc; 3194 3195 pMediumsForNotify.insert(pParent); 3196 uIdsForNotify[uMedium] = uMediumType; 3076 3197 3077 3198 // need to uninit the deleted medium … … 3081 3202 else 3082 3203 { 3204 { 3205 //store ids before merging for notify 3206 pMediumsForNotify.insert(it->mpTarget); 3207 if (it->mfMergeForward) 3208 pMediumsForNotify.insert(it->mpSource->i_getParent()); 3209 else 3210 { 3211 //children which will be reparented to target 3212 for (MediaList::const_iterator iit = it->mpSource->i_getChildren().begin(); 3213 iit != it->mpSource->i_getChildren().end(); 3214 ++iit) 3215 { 3216 pMediumsForNotify.insert(*iit); 3217 } 3218 } 3219 if (it->mfMergeForward) 3220 { 3221 for (ComObjPtr<Medium> pTmpMedium = it->mpTarget->i_getParent(); 3222 pTmpMedium != it->mpSource; 3223 pTmpMedium = pTmpMedium->i_getParent()) 3224 { 3225 uIdsForNotify[pTmpMedium->i_getId()] = pTmpMedium->i_getDeviceType(); 3226 } 3227 uIdsForNotify[it->mpSource->i_getId()] = it->mpSource->i_getDeviceType(); 3228 } 3229 else 3230 { 3231 for (ComObjPtr<Medium> pTmpMedium = it->mpSource->i_getParent(); 3232 pTmpMedium != it->mpTarget; 3233 pTmpMedium = pTmpMedium->i_getParent()) 3234 { 3235 uIdsForNotify[pTmpMedium->i_getId()] = pTmpMedium->i_getDeviceType(); 3236 } 3237 } 3238 } 3239 3083 3240 bool fNeedsSave = false; 3084 3241 if (it->mfNeedsOnlineMerge) … … 3111 3268 it->mpMediumLockList, 3112 3269 &task.m_pProgress, 3113 true /* aWait */); 3270 true /* aWait */, 3271 false /* aNotify */); 3114 3272 } 3115 3273 … … 3278 3436 3279 3437 if (SUCCEEDED(mrc)) 3438 { 3280 3439 mParent->i_onSnapshotDeleted(mData->mUuid, snapshotId); 3440 for (std::map<Guid, DeviceType_T>::const_iterator it = uIdsForNotify.begin(); 3441 it != uIdsForNotify.end(); 3442 ++it) 3443 { 3444 mParent->i_onMediumRegistered(it->first, it->second, FALSE); 3445 } 3446 for (std::set<ComObjPtr<Medium> >::const_iterator it = pMediumsForNotify.begin(); 3447 it != pMediumsForNotify.end(); 3448 ++it) 3449 { 3450 if (it->isNotNull()) 3451 mParent->i_onMediumConfigChanged(*it); 3452 } 3453 } 3281 3454 3282 3455 LogFlowThisFunc(("Done deleting snapshot (rc=%08X)\n", (HRESULT)mrc));
Note:
See TracChangeset
for help on using the changeset viewer.